Skip to content

Commit

Permalink
use to_s instead of string from MatchData, fix #1011, update #989
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Nov 1, 2014
1 parent a87974c commit 6d46ea2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/veewee/provider/core/helper/scancode.rb
Expand Up @@ -78,7 +78,7 @@ def self.string_to_keycode(thestring)
#take thestring
#check if it starts with a special key + pop special string
keycodes += value + result.captures.join(",") + ' '
thestring = thestring.slice(result.string.length, thestring.length-result.string.length)
thestring = thestring.slice(result.to_s.length, thestring.length-result.to_s.length)
nospecial = false;
break;
end
Expand Down
58 changes: 58 additions & 0 deletions test/veewee/provider/core/helper/scancode_test.rb
@@ -0,0 +1,58 @@
require 'test/unit'
require 'veewee/provider/core/helper/scancode'

class TestVeeweeScancode < Test::Unit::TestCase
def setup
@helper = Veewee::Provider::Core::Helper::Scancode
end

def test_simple_strings
assert_equal(
"1e 9e ",
@helper.string_to_keycode("a")
)
end

def test_specials
assert_equal(
"01 81 ",
@helper.string_to_keycode("<Esc>")
)
end

def test_specials_lowercase
assert_equal(
"01 81 ",
@helper.string_to_keycode("<esc>")
)
end

def test_spaces
assert_equal(
"39 b9 ",
@helper.string_to_keycode(" ")
)
end

def test_regexps
assert_equal(
"wait11 ",
@helper.string_to_keycode("<Wait11>")
)
end

def test_regexps
assert_equal(
"wait ",
@helper.string_to_keycode("<Wait>")
)
end

def test_combinations
assert_equal(
"wait10 01 81 1e 9e 39 b9 30 b0 ",
@helper.string_to_keycode("<Wait10><Esc>a b")
)
end

end

0 comments on commit 6d46ea2

Please sign in to comment.