ruby/test/prism/snippets_test.rb
Earlopain 17bcd71e42 [ruby/prism] Clean up test excludes
Mostly not having to list version-specific excludes when testing against ripper/parse.y

Also don't test new syntax additions against the parser gems. The version support
for them may (or may not) be expanded but we shouldn't bother while the ruby version
hasn't even released yet.
(ruby_parser translation is not versioned, so let as is for now)

I also removed excludes that have since been implemented by parse.y

https://github.com/ruby/prism/commit/e5a0221c37
2025-12-02 16:20:43 +00:00

44 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require_relative "test_helper"
module Prism
class SnippetsTest < TestCase
except = [
"encoding_binary.txt",
"newline_terminated.txt",
"seattlerb/begin_rescue_else_ensure_no_bodies.txt",
"seattlerb/case_in.txt",
"seattlerb/parse_line_defn_no_parens.txt",
"seattlerb/pct_nl.txt",
"seattlerb/str_heredoc_interp.txt",
"spanning_heredoc_newlines.txt",
"unparser/corpus/semantic/dstr.txt",
"whitequark/dedenting_heredoc.txt",
"whitequark/multiple_pattern_matches.txt"
]
Fixture.each_with_all_versions(except: except) do |fixture, version|
define_method(fixture.test_name(version)) { assert_snippets(fixture, version) }
end
private
# We test every snippet (separated by \n\n) in isolation to ensure the
# parser does not try to read bytes further than the end of each snippet.
def assert_snippets(fixture, version)
fixture.read.split(/(?<=\S)\n\n(?=\S)/).each do |snippet|
snippet = snippet.rstrip
result = Prism.parse(snippet, filepath: fixture.path, version: version)
assert result.success?
if !ENV["PRISM_BUILD_MINIMAL"]
dumped = Prism.dump(snippet, filepath: fixture.path, version: version)
assert_equal_nodes(result.value, Prism.load(snippet, dumped, version: version).value)
end
end
end
end
end