diff options
-rw-r--r-- | test/ruby/test_syntax.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index ec2892d091..776711c8de 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -986,6 +986,27 @@ eom assert_valid_syntax("a #\n #\n&.foo") assert_valid_syntax("a\n\n.foo") assert_valid_syntax("a \n \n &.foo") + + src = <<~RUBY + def m + # c + + x + end + RUBY + tokens = [ + [:on_kw, "def", ], # EXPR_FNAME], + [:on_sp, " ", ], # EXPR_FNAME], + [:on_ident, "m", ], # EXPR_ENDFN], + [:on_nl, "\n", ], # EXPR_BEG], + [:on_comment, " # c\n", ], # EXPR_EMPTYLN], + [:on_sp, " ", ], # EXPR_BEG], + [:on_ident, "x", ], # EXPR_CMDARG], + [:on_nl, "\n", ], # EXPR_BEG], + [:on_kw, "end", ], # EXPR_END], + [:on_nl, "\n", ], # EXPR_BEG], + ] + assert_tokens tokens, src end def test_no_warning_logop_literal @@ -1404,6 +1425,17 @@ eom assert_equal(expected, @result, message) end + def assert_tokens(expected, src, message = nil) + begin + require 'ripper' + actual = Ripper.lex(src).map { |_position, type, value, _state| [type, value] } + assert_equal(expected, actual, message) + rescue Exception => err + puts err + exit! 1 + end + end + def make_tmpsrc(f, src) f.open f.truncate(0) |