diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-09 07:22:51 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-09 07:22:51 +0000 |
commit | 69492b4dcf5eb3e8c38f94bdbb4ea42ed32a2a96 (patch) | |
tree | 5adcf8db41628be6af573a555a7000f1d96efce8 /test | |
parent | 5ee60048088ec5e6dbe1aa558cefa24a488b495c (diff) |
merge revision(s) 40606,40607,40635: [Backport #8375]
test_scanner_events.rb: assert_location
* test/ripper/test_scanner_events.rb (TestRipper#assert_location):
rename so skipped in backtraces.
* parse.y (parser_yylex): fail if $, @, @@ are not followed by a valid
name character. [ruby-core:54846] [Bug #8375].
* parse.y (parser_peek_variable_name): treat invalid global, class,
and instance variable names as mere strings rather than errors.
[ruby-core:54885] [Bug #8375]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@42462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ripper/test_parser_events.rb | 22 | ||||
-rw-r--r-- | test/ripper/test_scanner_events.rb | 48 | ||||
-rw-r--r-- | test/ruby/test_parse.rb | 21 |
3 files changed, 60 insertions, 31 deletions
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb index af41d3e6a4..1e3e6a3625 100644 --- a/test/ripper/test_parser_events.rb +++ b/test/ripper/test_parser_events.rb @@ -24,6 +24,10 @@ class TestRipper::ParserEvents < Test::Unit::TestCase dp.parse.to_s end + def compile_error(str) + parse(str, :compile_error) {|e, msg| return msg} + end + def test_program thru_program = false assert_equal '[void()]', parse('', :on_program) {thru_program = true} @@ -1135,8 +1139,20 @@ class TestRipper::ParserEvents < Test::Unit::TestCase end def test_unterminated_regexp - compile_error = false - parse('/', :compile_error) {|e, msg| compile_error = msg} - assert_equal("unterminated regexp meets end of file", compile_error) + assert_equal("unterminated regexp meets end of file", compile_error('/')) + end + + def test_invalid_instance_variable_name + assert_equal("`@1' is not allowed as an instance variable name", compile_error('@1')) + assert_equal("`@%' is not allowed as an instance variable name", compile_error('@%')) + end + + def test_invalid_class_variable_name + assert_equal("`@@1' is not allowed as a class variable name", compile_error('@@1')) + assert_equal("`@@%' is not allowed as a class variable name", compile_error('@@%')) + end + + def test_invalid_global_variable_name + assert_equal("`$%' is not allowed as a global variable name", compile_error('$%')) end end if ripper_test diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb index c92ec494ed..0f61ac7880 100644 --- a/test/ripper/test_scanner_events.rb +++ b/test/ripper/test_scanner_events.rb @@ -90,28 +90,28 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase end def test_location - validate_location "" - validate_location " " - validate_location "@" - validate_location "\n" - validate_location "\r\n" - validate_location "\n\n\n\n\n\r\n\n\n" - validate_location "\n;\n;\n;\n;\n" - validate_location "nil" - validate_location "@ivar" - validate_location "1;2;3" - validate_location "1\n2\n3" - validate_location "1\n2\n3\n" - validate_location "def m(a) nil end" - validate_location "if true then false else nil end" - validate_location "BEGIN{print nil}" - validate_location "%w(a b\nc\r\nd \ne )" - validate_location %Q["a\nb\r\nc"] - validate_location "print(<<EOS)\nheredoc\nEOS\n" - validate_location "print(<<-\"EOS\")\nheredoc\n EOS\n" - end - - def validate_location(src) + assert_location "" + assert_location " " + assert_location ":" + assert_location "\n" + assert_location "\r\n" + assert_location "\n\n\n\n\n\r\n\n\n" + assert_location "\n;\n;\n;\n;\n" + assert_location "nil" + assert_location "@ivar" + assert_location "1;2;3" + assert_location "1\n2\n3" + assert_location "1\n2\n3\n" + assert_location "def m(a) nil end" + assert_location "if true then false else nil end" + assert_location "BEGIN{print nil}" + assert_location "%w(a b\nc\r\nd \ne )" + assert_location %Q["a\nb\r\nc"] + assert_location "print(<<""EOS)\nheredoc\nEOS\n" + assert_location "print(<<-\"EOS\")\nheredoc\n EOS\n" + end + + def assert_location(src) buf = '' Ripper.lex(src).each do |pos, type, tok| line, col = *pos @@ -823,8 +823,8 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase def test_CHAR assert_equal [], scan('CHAR', "") - assert_equal ["@"], - scan('CHAR', "@") + assert_equal ["?a"], + scan('CHAR', "?a") assert_equal [], scan('CHAR', "@ivar") end diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 14990be12c..6de57c1a22 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -358,6 +358,17 @@ class TestParse < Test::Unit::TestCase assert_equal("foo 1 bar", "foo #$1 bar") end + def test_dstr_disallowd_variable + bug8375 = '[ruby-core:54885] [Bug #8375]' + %w[@ @1 @@. @@ @@1 @@. $ $%].each do |src| + src = '#'+src+' ' + str = assert_nothing_raised(SyntaxError, "#{bug8375} #{src.dump}") do + break eval('"'+src+'"') + end + assert_equal(src, str, bug8375) + end + end + def test_dsym assert_nothing_raised { eval(':""') } end @@ -524,13 +535,14 @@ class TestParse < Test::Unit::TestCase ) end - assert_raise(SyntaxError) do - eval %q( + assert_nothing_raised(SyntaxError) do + x = eval %q( <<FOO #$ FOO ) end + assert_equal "\#$\n", x assert_raise(SyntaxError) do eval %Q( @@ -550,14 +562,15 @@ FOO ) end - assert_raise(SyntaxError) do - eval %q( + assert_nothing_raised(SyntaxError) do + x = eval %q( <<FOO #$ foo FOO ) end + assert_equal "\#$\nfoo\n", x assert_nothing_raised do eval "x = <<""FOO\r\n1\r\nFOO" |