aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-09-04 00:07:50 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-09-24 21:57:54 +0900
commitea68bb914a3c806a1c5188993b96791a76ab0849 (patch)
tree085fe4bbf44e546143ba2ee950298bf269785d7a /test
parente73cc3eead75b27eabf93a7163bed511f2bb3b17 (diff)
downloadruby-ea68bb914a3c806a1c5188993b96791a76ab0849.tar.gz
Changed numbered parameter prefix
Diffstat (limited to 'test')
-rw-r--r--test/irb/test_color.rb2
-rw-r--r--test/ripper/test_lexer.rb8
-rw-r--r--test/ripper/test_parser_events.rb10
-rw-r--r--test/ripper/test_scanner_events.rb7
-rw-r--r--test/ruby/test_syntax.rb43
5 files changed, 32 insertions, 38 deletions
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index e1057d3144..3ecbee8cd6 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -67,8 +67,6 @@ module TestIRB
"4.5.6" => "#{MAGENTA}#{BOLD}4.5#{CLEAR}#{RED}#{REVERSE}.6#{CLEAR}",
"\e[0m\n" => "#{RED}#{REVERSE}^[#{CLEAR}[#{BLUE}#{BOLD}0#{CLEAR}#{RED}#{REVERSE}m#{CLEAR}\n",
"<<EOS\nhere\nEOS" => "#{RED}<<EOS#{CLEAR}\n#{RED}here#{CLEAR}\n#{RED}EOS#{CLEAR}",
- ":@1" => "#{YELLOW}:#{CLEAR}#{RED}#{REVERSE}@1#{CLEAR}",
- "@@1" => "#{RED}#{REVERSE}@@1#{CLEAR}",
})
end
diff --git a/test/ripper/test_lexer.rb b/test/ripper/test_lexer.rb
index 060d5f2db9..1794773d89 100644
--- a/test/ripper/test_lexer.rb
+++ b/test/ripper/test_lexer.rb
@@ -102,15 +102,15 @@ class TestRipper::Lexer < Test::Unit::TestCase
def test_state_after_ivar
assert_equal [[1,0],:on_ivar,"@a",state(:EXPR_END)], Ripper.lex("@a").last
assert_equal [[1,1],:on_ivar,"@a",state(:EXPR_ENDFN)], Ripper.lex(":@a").last
- assert_equal [[1,0],:on_ivar,"@1",state(:EXPR_END)], Ripper.lex("@1").last
- assert_equal [[1,1],:on_ivar,"@1",state(:EXPR_ENDFN)], Ripper.lex(":@1").last
+ assert_equal [[1,1],:on_int,"1",state(:EXPR_END)], Ripper.lex("@1").last
+ assert_equal [[1,2],:on_int,"1",state(:EXPR_END)], Ripper.lex(":@1").last
end
def test_state_after_cvar
assert_equal [[1,0],:on_cvar,"@@a",state(:EXPR_END)], Ripper.lex("@@a").last
assert_equal [[1,1],:on_cvar,"@@a",state(:EXPR_ENDFN)], Ripper.lex(":@@a").last
- assert_equal [[1,0],:on_cvar,"@@1",state(:EXPR_END)], Ripper.lex("@@1").last
- assert_equal [[1,1],:on_cvar,"@@1",state(:EXPR_ENDFN)], Ripper.lex(":@@1").last
+ assert_equal [[1,2],:on_int,"1",state(:EXPR_END)], Ripper.lex("@@1").last
+ assert_equal [[1,3],:on_int,"1",state(:EXPR_END)], Ripper.lex(":@@1").last
end
def test_token_aftr_error_heredoc
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 1bae1e31ad..662ab3d7fe 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -58,7 +58,10 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
assert_equal '[assign(var_field(a),ref(a))]', parse('a=a')
assert_equal '[ref(nil)]', parse('nil')
assert_equal '[ref(true)]', parse('true')
- assert_include parse('proc{@1}'), '[ref(@1)]'
+ assert_equal '[vcall(_0)]', parse('_0')
+ assert_equal '[vcall(_1)]', parse('_1')
+ assert_include parse('proc{_0}'), '[ref(_0)]'
+ assert_include parse('proc{_1}'), '[ref(_1)]'
end
def test_vcall
@@ -1505,11 +1508,8 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
assert_equal("unterminated regexp meets end of file", compile_error('/'))
end
- def test_invalid_numbered_parameter_name
- assert_equal("leading zero is not allowed as a numbered parameter", compile_error('proc{@0}'))
- end
-
def test_invalid_instance_variable_name
+ assert_equal("`@1' is not allowed as an instance variable name", compile_error('proc{@1}'))
assert_equal("`@' without identifiers is not allowed as an instance variable name", compile_error('@%'))
assert_equal("`@' without identifiers is not allowed as an instance variable name", compile_error('@'))
end
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index 75ae29491d..641310b384 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -360,13 +360,6 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
scan('ivar', 'm(lvar, @ivar, @@cvar, $gvar)')
end
- def test_tnumparam
- assert_equal [],
- scan('tnumparam', '')
- assert_equal ['@1'],
- scan('tnumparam', 'proc {@1}')
- end
-
def test_kw
assert_equal [],
scan('kw', '')
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index 6209bb3a23..31175ebae9 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -1439,26 +1439,29 @@ eom
end
def test_numbered_parameter
- assert_valid_syntax('proc {@1}')
- assert_equal(3, eval('[1,2].then {@1+@2}'))
- assert_equal("12", eval('[1,2].then {"#@1#@2"}'))
- assert_equal(3, eval('->{@1+@2}.call(1,2)'))
- assert_equal(4, eval('->(a=->{@1}){a}.call.call(4)'))
- assert_equal(5, eval('-> a: ->{@1} {a}.call.call(5)'))
- assert_syntax_error('proc {|| @1}', /ordinary parameter is defined/)
- assert_syntax_error('proc {|;a| @1}', /ordinary parameter is defined/)
- assert_syntax_error("proc {|\n| @1}", /ordinary parameter is defined/)
- assert_syntax_error('proc {|x| @1}', /ordinary parameter is defined/)
- assert_syntax_error('->(){@1}', /ordinary parameter is defined/)
- assert_syntax_error('->(x){@1}', /ordinary parameter is defined/)
- assert_syntax_error('->x{@1}', /ordinary parameter is defined/)
- assert_syntax_error('->x:@2{}', /ordinary parameter is defined/)
- assert_syntax_error('->x=@1{}', /ordinary parameter is defined/)
- assert_syntax_error('proc {@1 = nil}', /Can't assign to numbered parameter @1/)
- assert_syntax_error('proc {@01}', /leading zero/)
- assert_syntax_error('proc {@1_}', /unexpected/)
- assert_syntax_error('proc {@9999999999999999}', /too large/)
- assert_syntax_error('@1', /outside block/)
+ assert_valid_syntax('proc {_1}')
+ assert_equal(3, eval('[1,2].then {_1+_2}'))
+ assert_equal("12", eval('[1,2].then {"#{_1}#{_2}"}'))
+ assert_equal([1, 2], eval('[1,2].then {_0}'))
+ assert_equal(3, eval('->{_1+_2}.call(1,2)'))
+ assert_equal(4, eval('->(a=->{_1}){a}.call.call(4)'))
+ assert_equal(5, eval('-> a: ->{_1} {a}.call.call(5)'))
+ assert_syntax_error('proc {|| _0}', /ordinary parameter is defined/)
+ assert_syntax_error('proc {|| _1}', /ordinary parameter is defined/)
+ assert_syntax_error('proc {|;a| _1}', /ordinary parameter is defined/)
+ assert_syntax_error("proc {|\n| _1}", /ordinary parameter is defined/)
+ assert_syntax_error('proc {|x| _1}', /ordinary parameter is defined/)
+ assert_syntax_error('proc {_0+_1}', /implicit parameter is used/)
+ assert_syntax_error('proc {_1+_0}', /numbered parameter is used/)
+ assert_syntax_error('->(){_0}', /ordinary parameter is defined/)
+ assert_syntax_error('->(){_1}', /ordinary parameter is defined/)
+ assert_syntax_error('->(x){_1}', /ordinary parameter is defined/)
+ assert_syntax_error('->x{_1}', /ordinary parameter is defined/)
+ assert_syntax_error('->x:_2{}', /ordinary parameter is defined/)
+ assert_syntax_error('->x=_1{}', /ordinary parameter is defined/)
+ assert_syntax_error('-> {_0+_1}', /implicit parameter is used/)
+ assert_syntax_error('-> {_1+_0}', /numbered parameter is used/)
+ assert_warn(/`_1' is used as numbered parameter/) {eval('proc {_1 = nil}')}
assert_warn(/`_2' is used as numbered parameter/) {eval('_2=1')}
end