summaryrefslogtreecommitdiff
path: root/test/ripper/test_parser_events.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-14 04:58:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-14 04:58:47 +0000
commite21f1875b770caed1dd04adaa1a0043d45cb59d7 (patch)
tree34297474dae1db2e7d643452a92ebbf7f677f398 /test/ripper/test_parser_events.rb
parent049c9fecd82cf36f256296859117e9e9f5324827 (diff)
parse.y: fix ripper warnings
* parse.y (parser_nextc): send a warning to ripper, not to STDERR always. * parse.y (rb_warn1, rb_warning1): move argument conversions to callers. PRIsVALUE is not valid in String#%. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ripper/test_parser_events.rb')
-rw-r--r--test/ripper/test_parser_events.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 46204bcec6..5ed17b6924 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -24,6 +24,14 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
parse(str, :compile_error) {|e, msg| return msg}
end
+ def warning(str)
+ parse(str, :warning) {|e, *args| return args}
+ end
+
+ def warn(str)
+ parse(str, :warn) {|e, *args| return args}
+ end
+
def test_program
thru_program = false
assert_equal '[void()]', parse('', :on_program) {thru_program = true}
@@ -1261,4 +1269,17 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
assert_equal("`$%' is not allowed as a global variable name", compile_error('$%'))
assert_equal("`$' without identifiers is not allowed as a global variable name", compile_error('$'))
end
+
+ def test_warning_shadowing
+ fmt, *args = warning("x = 1; tap {|;x|}")
+ assert_match(/shadowing outer local variable/, fmt)
+ assert_equal("x", args[0])
+ assert_match(/x/, fmt % args)
+ end
+
+ def test_warn_cr_in_middle
+ fmt = nil
+ assert_warn("") {fmt, *args = warn("\r;")}
+ assert_match(/encountered/, fmt)
+ end
end if ripper_test