diff options
Diffstat (limited to 'test/ripper')
| -rw-r--r-- | test/ripper/assert_parse_files.rb | 1 | ||||
| -rw-r--r-- | test/ripper/test_lexer.rb | 93 | ||||
| -rw-r--r-- | test/ripper/test_parser_events.rb | 7 |
3 files changed, 101 insertions, 0 deletions
diff --git a/test/ripper/assert_parse_files.rb b/test/ripper/assert_parse_files.rb index 0d583a99e3..4f08589e41 100644 --- a/test/ripper/assert_parse_files.rb +++ b/test/ripper/assert_parse_files.rb @@ -40,6 +40,7 @@ class TestRipper::Generic < Test::Unit::TestCase end } end + assert(true) if scripts.empty? end; end end diff --git a/test/ripper/test_lexer.rb b/test/ripper/test_lexer.rb index a371e8c42d..4bc6fd7ced 100644 --- a/test/ripper/test_lexer.rb +++ b/test/ripper/test_lexer.rb @@ -344,6 +344,47 @@ world" ] assert_lexer(expected, code) + + code = <<~'HEREDOC' + <<H1 + #{<<H2}a + H2 + b + HEREDOC + + expected = [ + [[1, 0], :on_heredoc_beg, "<<H1", state(:EXPR_BEG)], + [[1, 4], :on_nl, "\n", state(:EXPR_BEG)], + [[2, 0], :on_embexpr_beg, "\#{", state(:EXPR_BEG)], + [[2, 2], :on_heredoc_beg, "<<H2", state(:EXPR_BEG)], + [[2, 6], :on_embexpr_end, "}", state(:EXPR_END)], + [[2, 7], :on_tstring_content, "a\n", state(:EXPR_BEG)], + [[3, 0], :on_heredoc_end, "H2\n", state(:EXPR_BEG)], + [[4, 0], :on_tstring_content, "b\n", state(:EXPR_BEG)] + ] + + assert_lexer(expected, code) + + code = <<~'HEREDOC' + <<H1 + #{<<H2}a + H2 + b + c + HEREDOC + + expected = [ + [[1, 0], :on_heredoc_beg, "<<H1", state(:EXPR_BEG)], + [[1, 4], :on_nl, "\n", state(:EXPR_BEG)], + [[2, 0], :on_embexpr_beg, "\#{", state(:EXPR_BEG)], + [[2, 2], :on_heredoc_beg, "<<H2", state(:EXPR_BEG)], + [[2, 6], :on_embexpr_end, "}", state(:EXPR_END)], + [[2, 7], :on_tstring_content, "a\n", state(:EXPR_BEG)], + [[3, 0], :on_heredoc_end, "H2\n", state(:EXPR_BEG)], + [[4, 0], :on_tstring_content, "b\nc\n", state(:EXPR_BEG)] + ] + + assert_lexer(expected, code) end def test_invalid_escape_ctrl_mbchar @@ -545,6 +586,58 @@ world" assert_lexer(expected, code) end + def test_fluent_and + code = "foo\n" "and" + expected = [ + [[1, 0], :on_ident, "foo", state(:EXPR_CMDARG)], + [[1, 3], :on_ignored_nl, "\n", state(:EXPR_CMDARG)], + [[2, 0], :on_kw, "and", state(:EXPR_BEG)], + ] + assert_lexer(expected, code) + + code = "foo\n" "and?" + expected = [ + [[1, 0], :on_ident, "foo", state(:EXPR_CMDARG)], + [[1, 3], :on_nl, "\n", state(:EXPR_BEG)], + [[2, 0], :on_ident, "and?", state(:EXPR_CMDARG)], + ] + assert_lexer(expected, code) + + code = "foo\n" "and!" + expected = [ + [[1, 0], :on_ident, "foo", state(:EXPR_CMDARG)], + [[1, 3], :on_nl, "\n", state(:EXPR_BEG)], + [[2, 0], :on_ident, "and!", state(:EXPR_CMDARG)], + ] + assert_lexer(expected, code) + end + + def test_fluent_or + code = "foo\n" "or" + expected = [ + [[1, 0], :on_ident, "foo", state(:EXPR_CMDARG)], + [[1, 3], :on_ignored_nl, "\n", state(:EXPR_CMDARG)], + [[2, 0], :on_kw, "or", state(:EXPR_BEG)], + ] + assert_lexer(expected, code) + + code = "foo\n" "or?" + expected = [ + [[1, 0], :on_ident, "foo", state(:EXPR_CMDARG)], + [[1, 3], :on_nl, "\n", state(:EXPR_BEG)], + [[2, 0], :on_ident, "or?", state(:EXPR_CMDARG)], + ] + assert_lexer(expected, code) + + code = "foo\n" "or!" + expected = [ + [[1, 0], :on_ident, "foo", state(:EXPR_CMDARG)], + [[1, 3], :on_nl, "\n", state(:EXPR_BEG)], + [[2, 0], :on_ident, "or!", state(:EXPR_CMDARG)], + ] + assert_lexer(expected, code) + end + def assert_lexer(expected, code) assert_equal(code, Ripper.tokenize(code).join("")) assert_equal(expected, result = Ripper.lex(code), diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb index aa7434c083..3e72c7a331 100644 --- a/test/ripper/test_parser_events.rb +++ b/test/ripper/test_parser_events.rb @@ -482,6 +482,13 @@ class TestRipper::ParserEvents < Test::Unit::TestCase thru_call = false assert_nothing_raised { + tree = parse("a b do end.()", :on_call) {thru_call = true} + } + assert_equal true, thru_call + assert_equal "[call(command(a,[vcall(b)],&do_block(,bodystmt([void()]))),.,call,[])]", tree + + thru_call = false + assert_nothing_raised { tree = parse("self::foo", :on_call) {thru_call = true} } assert_equal true, thru_call |
