diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ripper/test_parser_events.rb | 6 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 15 |
2 files changed, 21 insertions, 0 deletions
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb index af41d3e6a4..3b4785804d 100644 --- a/test/ripper/test_parser_events.rb +++ b/test/ripper/test_parser_events.rb @@ -146,6 +146,12 @@ class TestRipper::ParserEvents < Test::Unit::TestCase assert_equal true, thru_assoc_new end + def test_assoc_splat + thru_assoc_splat = false + parse('m(**h)', :on_assoc_splat) {thru_assoc_splat = true} + assert_equal true, thru_assoc_splat + end + def test_aref_field assert_equal '[assign(aref_field(vcall(a),[1]),2)]', parse('a[1]=2') end diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index fd5b14d6c3..55655e2e11 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -90,6 +90,21 @@ class TestSyntax < Test::Unit::TestCase assert_equal({foo: 1, bar: 2}, o.kw(foo: 1, bar: 2), bug5989) end + def test_keyword_splat + assert_valid_syntax("foo(**h)", __FILE__) + o = Object.new + def o.kw(k1: 1, k2: 2) [k1, k2] end + h = {k1: 11, k2: 12} + assert_equal([11, 12], o.kw(**h)) + assert_equal([11, 22], o.kw(k2: 22, **h)) + assert_equal([11, 12], o.kw(**h, **{k2: 22})) + assert_equal([11, 22], o.kw(**{k2: 22}, **h)) + h = {k3: 31} + assert_raise(ArgumentError) {o.kw(**h)} + h = {"k1"=>11, k2: 12} + assert_raise(TypeError) {o.kw(**h)} + end + def test_warn_grouped_expression assert_warn("test:2: warning: (...) interpreted as grouped expression\n") do assert_valid_syntax("foo \\\n(\n true)", "test") {$VERBOSE = true} |