From 507ccbe28787ae3c226093355b3c9b83df85325d Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 7 Jun 2016 08:57:36 +0000 Subject: test_syntax.rb: formal argument name tests * test/ruby/test_syntax.rb: add invalid formal argument name tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_syntax.rb | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 4f2a95c8c3..ce013583be 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -93,6 +93,20 @@ class TestSyntax < Test::Unit::TestCase assert_valid_syntax("tap (proc do end)", __FILE__, bug9726) end + def test_normal_argument + assert_valid_syntax('def foo(x) end') + assert_syntax_error('def foo(X) end', /constant/) + assert_syntax_error('def foo(@x) end', /instance variable/) + assert_syntax_error('def foo(@@x) end', /class variable/) + end + + def test_optional_argument + assert_valid_syntax('def foo(x=nil) end') + assert_syntax_error('def foo(X=nil) end', /constant/) + assert_syntax_error('def foo(@x=nil) end', /instance variable/) + assert_syntax_error('def foo(@@x=nil) end', /class variable/) + end + def test_keyword_rest bug5989 = '[ruby-core:42455]' assert_valid_syntax("def kwrest_test(**a) a; end", __FILE__, bug5989) @@ -210,6 +224,11 @@ class TestSyntax < Test::Unit::TestCase assert_syntax_error('def o.foo(arg1?:, arg2:) end', /arg1\?/, bug11663) assert_syntax_error('proc {|arg1?:|}', /arg1\?/, bug11663) assert_syntax_error('proc {|arg1?:, arg2:|}', /arg1\?/, bug11663) + + bug10545 = '[ruby-dev:48742] [Bug #10545]' + assert_syntax_error('def o.foo(FOO: a) end', /constant/, bug10545) + assert_syntax_error('def o.foo(@foo: a) end', /instance variable/) + assert_syntax_error('def o.foo(@@foo: a) end', /class variable/) end def test_optional_self_reference @@ -746,12 +765,6 @@ eom assert_syntax_error(code, /def n "\u{2208}"; end/, bug10114) end - def test_bad_kwarg - bug10545 = '[ruby-dev:48742] [Bug #10545]' - src = 'def foo(A: a) end' - assert_syntax_error(src, /formal argument/, bug10545) - end - def test_null_range_cmdarg bug10957 = '[ruby-core:68477] [Bug #10957]' assert_ruby_status(['-c', '-e', 'p ()..0'], "", bug10957) -- cgit v1.2.3