summaryrefslogtreecommitdiff
path: root/test/ruby/test_syntax.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-28 21:12:05 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-28 21:12:05 +0000
commit3380974143d3fdf1721d9e28d6b2d42036f03bd2 (patch)
tree86a60ee982dbdc8f2c68900a43327765b648822e /test/ruby/test_syntax.rb
parent82fa2995b5ca47d3383cce82ba5c75da4f09da5a (diff)
* parse.y (assoc, parser_yylex): add syntax to splat keyword hash.
[ruby-core:44591][Feature #6353] * compile.c (compile_array_): generate keyword splat insns. * vm.c (m_core_hash_merge_kwd): merge keyword hash into intermediate hash. leftward argument is prior currently. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35489 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_syntax.rb')
-rw-r--r--test/ruby/test_syntax.rb15
1 files changed, 15 insertions, 0 deletions
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}