Sha256: c23193a8632e63f9b8a81219e88da55eb8309d01cc21a1afcaa6add76c0c726c

Contents?: true

Size: 1.89 KB

Versions: 21

Compression:

Stored size: 1.89 KB

Contents

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'rautomation'
require 'rspec'

describe "KeystrokeConverter", :if => SpecHelper.adapter == :ms_uia do

  it "converts plain ASCII" do
    codes = RAutomation::Adapter::MsUia::KeystrokeConverter.convert("abc")
    converted_keys = convert_keys "abc"
    codes.should == converted_keys
  end

  it "uses caps lock for entering downcase keys" do
    codes = RAutomation::Adapter::MsUia::KeystrokeConverter.convert("aBc")
    converted_keys = convert_keys "abc"
    converted_keys = converted_keys.insert(1, RAutomation::Adapter::MsUia::Constants::VK_LSHIFT)
    codes.should == converted_keys
  end

  it "converts special keys" do
    codes = RAutomation::Adapter::MsUia::KeystrokeConverter.convert("{tab}a{backspace}b{enter}c {left}d{right}ee{down}f{up}g{unsupported}{home}{end}{delete}")
    expected_codes = [
        RAutomation::Adapter::MsUia::Constants::VK_TAB,
        convert_keys("a"),
        RAutomation::Adapter::MsUia::Constants::VK_BACK,
        convert_keys("b"),
        RAutomation::Adapter::MsUia::Constants::VK_RETURN,
        convert_keys("c"),
        RAutomation::Adapter::MsUia::Constants::VK_SPACE,
        RAutomation::Adapter::MsUia::Constants::VK_LEFT,
        convert_keys("d"),
        RAutomation::Adapter::MsUia::Constants::VK_RIGHT,
        convert_keys("ee"),
        RAutomation::Adapter::MsUia::Constants::VK_DOWN,
        convert_keys("f"),
        RAutomation::Adapter::MsUia::Constants::VK_UP,
        convert_keys("g"),
        convert_keys("unsupported"),
        RAutomation::Adapter::MsUia::Constants::VK_HOME,
        RAutomation::Adapter::MsUia::Constants::VK_END,
        RAutomation::Adapter::MsUia::Constants::VK_DELETE
    ].flatten
    codes.should == expected_codes
  end

  def convert_keys keys
    keys.split("").map { |k| k.upcase.unpack("c")[0] }
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rautomation-0.7.0 spec/adapter/ms_uia/keystroke_converter_spec.rb