From 9e01fcd0cb79a05daa50d99c888cc7eeb9c79426 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 26 Nov 2019 22:54:35 +0900 Subject: [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 --- test/ripper/test_sexp.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/ripper/test_sexp.rb') 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 -- cgit v1.2.3