Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 5 additions & 47 deletions test/prism/lex_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,6 @@

module Prism
class LexTest < TestCase
except = [
# https://bugs.ruby-lang.org/issues/21756
"spanning_heredoc.txt",
# Prism emits a single string in some cases when ripper splits them up
"whitequark/dedenting_heredoc.txt",
"heredocs_with_fake_newlines.txt",
# Prism emits BEG for `on_regexp_end`
"spanning_heredoc_newlines.txt",
]

if RUBY_VERSION < "3.3.0"
# This file has changed behavior in Ripper in Ruby 3.3, so we skip it if
# we're on an earlier version.
except << "seattlerb/pct_w_heredoc_interp_nested.txt"

# Ruby < 3.3.0 cannot parse heredocs where there are leading whitespace
# characters in the heredoc start.
# Example: <<~' EOF' or <<-' EOF'
# https://bugs.ruby-lang.org/issues/19539
except << "heredocs_leading_whitespace.txt"
except << "whitequark/ruby_bug_19539.txt"

# https://bugs.ruby-lang.org/issues/19025
except << "whitequark/numparam_ruby_bug_19025.txt"
# https://bugs.ruby-lang.org/issues/18878
except << "whitequark/ruby_bug_18878.txt"
# https://bugs.ruby-lang.org/issues/19281
except << "whitequark/ruby_bug_19281.txt"
end

# https://bugs.ruby-lang.org/issues/21168#note-5
except << "command_method_call_2.txt"

Fixture.each_for_current_ruby(except: except) do |fixture|
define_method(fixture.test_name) { assert_lex(fixture) }
end

def test_lex_file
assert_nothing_raised do
Prism.lex_file(__FILE__)
Expand Down Expand Up @@ -83,16 +46,11 @@ def test_parse_lex_file
end
end

private

def assert_lex(fixture)
source = fixture.read

result = Prism.lex_compat(source, version: "current")
assert_equal [], result.errors

Prism.lex_ripper(source).zip(result.value).each do |(ripper, prism)|
Comment on lines -91 to -94
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still test Prism.lex_compat & Prism.lex_ripper?
They don't seem tested by #3849 from a quick look, but maybe I missed something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lex_compat is what drives Translation::Ripper so that should be good. I'm not sure what the use-case for lex_ripper is, seems useful only for for testing against the real one in prism itself.

Both are also pretty extensively used in the various lex CI steps. I added a basic test for them back here.

assert_equal ripper, prism
if RUBY_VERSION >= "3.3"
def test_lex_compare
prism = Prism.lex_compat(File.read(__FILE__), version: "current").value
ripper = Prism.lex_ripper(File.read(__FILE__))
assert_equal(ripper, prism)
end
end
end
Expand Down