[前][次][番号順一覧][スレッド一覧]

ruby-changes:43238

From: nobu <ko1@a...>
Date: Tue, 7 Jun 2016 17:57:41 +0900 (JST)
Subject: [ruby-changes:43238] nobu:r55312 (trunk): test_syntax.rb: formal argument name tests

nobu	2016-06-07 17:57:36 +0900 (Tue, 07 Jun 2016)

  New Revision: 55312

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55312

  Log:
    test_syntax.rb: formal argument name tests
    
    * test/ruby/test_syntax.rb: add invalid formal argument name
      tests.

  Modified files:
    trunk/test/ruby/test_syntax.rb
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 55311)
+++ test/ruby/test_syntax.rb	(revision 55312)
@@ -93,6 +93,20 @@ class TestSyntax < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L93
     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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L224
     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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L765
     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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]