From 46527e1bf4a66a42ac4729e23f12bdfec8ae953e Mon Sep 17 00:00:00 2001 From: Josh Cheek Date: Fri, 14 Jun 2019 21:13:27 -0500 Subject: Test for blank lines between leadinig dot method chains --- test/ruby/test_syntax.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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) -- cgit v1.2.3