diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-11-26 22:54:35 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-11-26 22:54:35 +0900 |
commit | 9e01fcd0cb79a05daa50d99c888cc7eeb9c79426 (patch) | |
tree | ffa6df85db248a1abd843d2b2c8d56b6a0c0ce16 /test | |
parent | 22dfd14c179632d773b97e708255b6c183a740aa (diff) | |
download | ruby-9e01fcd0cb79a05daa50d99c888cc7eeb9c79426.tar.gz |
[ripper] Fixed unique key check in pattern matching
Check keys
* by an internal table, instead of unstable dispatched results
* and by parsed key values, instead of escaped forms in the source
Diffstat (limited to 'test')
-rw-r--r-- | test/ripper/test_sexp.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/ripper/test_sexp.rb b/test/ripper/test_sexp.rb index 9b3a99e522..89b45941a3 100644 --- a/test/ripper/test_sexp.rb +++ b/test/ripper/test_sexp.rb @@ -438,6 +438,9 @@ eot [__LINE__, %q{ case 0; in "A":; end }] => nil, + + [__LINE__, %q{ case 0; in "a\x0":a1, "a\0":a2; end }] => + nil, # duplicated key name } pattern_matching_data.each do |(i, src), expected| define_method(:"test_pattern_matching_#{i}") do @@ -445,4 +448,26 @@ eot assert_equal expected, sexp && sexp[1][0], src end end + + def test_hshptn + parser = Class.new(Ripper::SexpBuilder) do + def on_label(token) + [:@label, token] + end + end + + result = parser.new("#{<<~"begin;"}#{<<~'end;'}").parse + begin; + case foo + in { a: 1 } + bar + else + baz + end + end; + + hshptn = result.dig(1, 2, 2, 1) + assert_equal(:hshptn, hshptn[0]) + assert_equal([:@label, "a:"], hshptn.dig(2, 0, 0)) + end end if ripper_test |