@@ -38,7 +38,7 @@ class RipperTest < TestCase
3838 end
3939
4040 # Skip these tests that we haven't implemented yet.
41- omitted = [
41+ omitted_sexp_raw = [
4242 "dos_endings.txt" ,
4343 "heredocs_with_fake_newlines.txt" ,
4444 "heredocs_with_ignored_newlines.txt" ,
@@ -59,8 +59,29 @@ class RipperTest < TestCase
5959 "whitequark/slash_newline_in_heredocs.txt"
6060 ]
6161
62- Fixture . each_for_current_ruby ( except : incorrect | omitted ) do |fixture |
63- define_method ( fixture . test_name ) { assert_ripper ( fixture . read ) }
62+ omitted_lexer_parse = [
63+ "comments.txt" ,
64+ "heredoc_percent_q_newline_delimiter.txt" ,
65+ "heredoc_with_escaped_newline_at_start.txt" ,
66+ "heredocs_with_fake_newlines.txt" ,
67+ "indented_file_end.txt" ,
68+ "seattlerb/TestRubyParserShared.txt" ,
69+ "seattlerb/class_comments.txt" ,
70+ "seattlerb/module_comments.txt" ,
71+ "seattlerb/parse_line_block_inline_comment_leading_newlines.txt" ,
72+ "seattlerb/parse_line_block_inline_multiline_comment.txt" ,
73+ "spanning_heredoc_newlines.txt" ,
74+ "strings.txt" ,
75+ "whitequark/dedenting_heredoc.txt" ,
76+ "whitequark/procarg0.txt" ,
77+ ]
78+
79+ Fixture . each_for_current_ruby ( except : incorrect | omitted_sexp_raw ) do |fixture |
80+ define_method ( "#{ fixture . test_name } _sexp_raw" ) { assert_ripper_sexp_raw ( fixture . read ) }
81+ end
82+
83+ Fixture . each_for_current_ruby ( except : incorrect | omitted_lexer_parse ) do |fixture |
84+ define_method ( "#{ fixture . test_name } _lexer_parse" ) { assert_ripper_lexer_parse ( fixture . read ) }
6485 end
6586
6687 # Check that the hardcoded values don't change without us noticing.
@@ -76,8 +97,27 @@ def test_internals
7697
7798 private
7899
79- def assert_ripper ( source )
100+ def assert_ripper_sexp_raw ( source )
80101 assert_equal Ripper . sexp_raw ( source ) , Prism ::Translation ::Ripper . sexp_raw ( source )
81102 end
103+
104+ def assert_ripper_lexer_parse ( source )
105+ prism = Translation ::Ripper ::Lexer . new ( source ) . parse
106+ ripper = Ripper ::Lexer . new ( source ) . parse
107+ ripper . reject! { |elem | elem . event == :on_sp } # Prism doesn't emit on_sp
108+ ripper . sort_by! ( &:pos ) # Prism emits tokens by their order in the code, not in parse order
109+
110+ [ prism . size , ripper . size ] . max . times do |i |
111+ expected = ripper [ i ] . to_a
112+ actual = prism [ i ] . to_a
113+ # Since tokens related to heredocs are not emitted in the same order,
114+ # the state also doesn't line up.
115+ if expected [ 1 ] == :on_heredoc_end && actual [ 1 ] == :on_heredoc_end
116+ expected [ 3 ] = actual [ 3 ] = nil
117+ end
118+
119+ assert_equal ( expected , actual )
120+ end
121+ end
82122 end
83123end
0 commit comments