@@ -188,39 +188,43 @@ def test_parse_file_comments
188
188
directory = File . dirname ( snapshot )
189
189
FileUtils . mkdir_p ( directory ) unless File . directory? ( directory )
190
190
191
- ripper_should_parse = ripper_should_match = ripper_enabled
192
-
193
- # This file has changed behavior in Ripper in Ruby 3.3, so we skip it if
194
- # we're on an earlier version.
195
- ripper_should_match = false if relative == "seattlerb/pct_w_heredoc_interp_nested.txt" && RUBY_VERSION < "3.3.0"
196
-
197
- # It seems like there are some oddities with nested heredocs and ripper.
198
- # Waiting for feedback on https://bugs.ruby-lang.org/issues/19838.
199
- ripper_should_match = false if relative == "seattlerb/heredoc_nested.txt"
200
- ripper_should_match = false if relative == "whitequark/dedenting_heredoc.txt"
201
-
202
- # Ripper seems to have a bug that the regex portions before and after the heredoc are combined
203
- # into a single token. See https://bugs.ruby-lang.org/issues/19838.
204
- #
205
- # Additionally, Ripper cannot parse the %w[] fixture in this file, so set ripper_should_parse to false.
206
- ripper_should_parse = false if relative == "spanning_heredoc.txt"
207
- ripper_should_match = false if relative == "spanning_heredoc_newlines.txt"
208
-
209
- # Ruby < 3.3.0 cannot parse heredocs where there are leading whitespace characters in the heredoc start.
210
- # Example: <<~' EOF' or <<-' EOF'
211
- # https://bugs.ruby-lang.org/issues/19539
212
- ripper_should_parse = false if relative == "heredocs_leading_whitespace.txt" && RUBY_VERSION < "3.3.0"
191
+ ripper_should_match = ripper_enabled
192
+ check_valid_syntax = true
193
+
194
+ case relative
195
+ when "seattlerb/pct_w_heredoc_interp_nested.txt"
196
+ # This file has changed behavior in Ripper in Ruby 3.3, so we skip it if
197
+ # we're on an earlier version.
198
+ ripper_should_match = false if RUBY_VERSION < "3.3.0"
199
+ when "seattlerb/heredoc_nested.txt" , "whitequark/dedenting_heredoc.txt"
200
+ # It seems like there are some oddities with nested heredocs and ripper.
201
+ # Waiting for feedback on https://bugs.ruby-lang.org/issues/19838.
202
+ ripper_should_match = false
203
+ when "spanning_heredoc.txt" , "spanning_heredoc_newlines.txt"
204
+ # Ripper seems to have a bug that the regex portions before and after
205
+ # the heredoc are combined into a single token. See
206
+ # https://bugs.ruby-lang.org/issues/19838.
207
+ ripper_should_match = false
208
+ when "heredocs_leading_whitespace.txt"
209
+ # Ruby < 3.3.0 cannot parse heredocs where there are leading whitespace
210
+ # characters in the heredoc start.
211
+ # Example: <<~' EOF' or <<-' EOF'
212
+ # https://bugs.ruby-lang.org/issues/19539
213
+ if RUBY_VERSION < "3.3.0"
214
+ ripper_should_match = false
215
+ check_valid_syntax = false
216
+ end
217
+ end
213
218
214
219
define_method "test_filepath_#{ relative } " do
215
- # First, read the source from the filepath. Use binmode to avoid converting CRLF on Windows,
216
- # and explicitly set the external encoding to UTF-8 to override the binmode default.
220
+ # First, read the source from the filepath. Use binmode to avoid
221
+ # converting CRLF on Windows, and explicitly set the external encoding
222
+ # to UTF-8 to override the binmode default.
217
223
source = File . read ( filepath , binmode : true , external_encoding : Encoding ::UTF_8 )
218
224
219
- if ripper_should_parse
220
- # Make sure that it can be correctly parsed by Ripper. If it can't,
221
- # then we have a fixture that is invalid Ruby.
222
- refute_nil ( Ripper . sexp_raw ( source ) , "Ripper failed to parse" )
223
- end
225
+ # Make sure that the given source is valid syntax, otherwise we have an
226
+ # invalid fixture.
227
+ assert_valid_syntax ( source ) if check_valid_syntax
224
228
225
229
# Next, assert that there were no errors during parsing.
226
230
result = Prism . parse ( source , filepath : relative )
@@ -263,7 +267,7 @@ def test_parse_file_comments
263
267
source . b . scan ( "\n " ) { expected_newlines << $~. offset ( 0 ) [ 0 ] + 1 }
264
268
assert_equal expected_newlines , Debug . newlines ( source )
265
269
266
- if ripper_should_parse && ripper_should_match
270
+ if ripper_should_match
267
271
# Finally, assert that we can lex the source and get the same tokens as
268
272
# Ripper.
269
273
lex_result = Prism . lex_compat ( source )
0 commit comments