summaryrefslogtreecommitdiff
path: root/test/ripper
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-08 04:07:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-08 04:07:22 +0000
commit85280f4b555a7f69692a5a469402c433a36b5eca (patch)
tree0c85d735184bacb8500dee121ee3fc2555f95534 /test/ripper
parent4dfd3739055388f0395eee81b3297966498f49d5 (diff)
parse.y: fail if invalid name
* parse.y (parser_yylex): fail if $, @, @@ are not followed by a valid name character. [ruby-core:54846] [Bug #8375]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ripper')
-rw-r--r--test/ripper/test_parser_events.rb22
-rw-r--r--test/ripper/test_scanner_events.rb6
2 files changed, 22 insertions, 6 deletions
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 4418061..c9b5690 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}
@@ -1167,8 +1171,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 66ae07c..a96edef 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -92,7 +92,7 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
def test_location
assert_location ""
assert_location " "
- assert_location "@"
+ assert_location ":"
assert_location "\n"
assert_location "\r\n"
assert_location "\n\n\n\n\n\r\n\n\n"
@@ -842,8 +842,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