2017-05-02 20:48:10 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
begin
|
2017-07-15 10:24:12 +03:00
|
|
|
require 'ripper'
|
2017-05-02 20:48:10 +03:00
|
|
|
require 'test/unit'
|
|
|
|
ripper_test = true
|
|
|
|
module TestRipper; end
|
|
|
|
rescue LoadError
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestRipper::Lexer < Test::Unit::TestCase
|
|
|
|
def test_nested_dedent_heredoc
|
|
|
|
bug = '[ruby-core:80977] [Bug #13536]'
|
|
|
|
str = <<~'E'
|
|
|
|
<<~"D"
|
|
|
|
#{
|
|
|
|
<<~"B"
|
|
|
|
this must be a valid ruby
|
|
|
|
B
|
|
|
|
}
|
|
|
|
D
|
|
|
|
E
|
|
|
|
assert_equal(str, Ripper.tokenize(str).join(""), bug)
|
2017-05-06 18:14:58 +03:00
|
|
|
|
|
|
|
str = <<~'E'
|
|
|
|
<<~"D"
|
|
|
|
#{
|
|
|
|
<<~"B"
|
|
|
|
this must be a valid ruby
|
|
|
|
B
|
|
|
|
}
|
|
|
|
D
|
|
|
|
E
|
|
|
|
assert_equal(str, Ripper.tokenize(str).join(""), bug)
|
2017-05-02 20:48:10 +03:00
|
|
|
end
|
2017-07-06 07:12:51 +03:00
|
|
|
|
|
|
|
def test_embedded_expr_in_heredoc
|
|
|
|
src = <<~'E'
|
|
|
|
<<~B
|
|
|
|
#{1}
|
|
|
|
B
|
|
|
|
E
|
|
|
|
expect = %I[
|
|
|
|
on_heredoc_beg
|
|
|
|
on_nl
|
|
|
|
on_ignored_sp
|
|
|
|
on_embexpr_beg
|
|
|
|
on_int
|
|
|
|
on_embexpr_end
|
|
|
|
on_tstring_content
|
|
|
|
on_heredoc_end
|
|
|
|
]
|
|
|
|
assert_equal expect, Ripper.lex(src).map {|e| e[1]}
|
|
|
|
end
|
2017-10-19 07:25:30 +03:00
|
|
|
|
|
|
|
def test_space_after_expr_in_heredoc
|
|
|
|
src = <<~'E'
|
|
|
|
<<~B
|
|
|
|
#{1} a
|
|
|
|
B
|
|
|
|
E
|
|
|
|
expect = %I[
|
|
|
|
on_heredoc_beg
|
|
|
|
on_nl
|
|
|
|
on_ignored_sp
|
|
|
|
on_embexpr_beg
|
|
|
|
on_int
|
|
|
|
on_embexpr_end
|
|
|
|
on_tstring_content
|
|
|
|
on_heredoc_end
|
|
|
|
]
|
|
|
|
assert_equal expect, Ripper.lex(src).map {|e| e[1]}
|
|
|
|
end
|
2017-10-19 08:10:38 +03:00
|
|
|
|
|
|
|
def test_expr_at_beginning_in_heredoc
|
|
|
|
src = <<~'E'
|
|
|
|
<<~B
|
|
|
|
a
|
|
|
|
#{1}
|
|
|
|
B
|
|
|
|
E
|
|
|
|
expect = %I[
|
|
|
|
on_heredoc_beg
|
|
|
|
on_nl
|
|
|
|
on_tstring_content
|
|
|
|
on_embexpr_beg
|
|
|
|
on_int
|
|
|
|
on_embexpr_end
|
|
|
|
on_tstring_content
|
|
|
|
on_heredoc_end
|
|
|
|
]
|
|
|
|
assert_equal expect, Ripper.lex(src).map {|e| e[1]}
|
|
|
|
end
|
2017-05-02 20:48:10 +03:00
|
|
|
end
|