Skip to content

Commit e9e9a48

Browse files
committed
Be a bit stricter when comparing parser translator tokens
When there were more actual tokens than expected tokens, the test would still pass. Now it's possible to receive an assertion like this: ``` expected: [] actual: [:tNL, [nil, #<Parser::Source::Range comment_single.txt 8...9>]] <[]> expected but was <[:tNL, [nil, #<Parser::Source::Range comment_single.txt 8...9>]]> ```
1 parent a0571d9 commit e9e9a48

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

test/prism/ruby/parser_test.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,14 @@ def assert_equal_asts_message(expected_ast, actual_ast)
207207

208208
def assert_equal_tokens(expected_tokens, actual_tokens)
209209
if expected_tokens != actual_tokens
210-
expected_index = 0
211-
actual_index = 0
210+
index = 0
211+
max_index = [expected_tokens, actual_tokens].map(&:size).max
212212

213-
while expected_index < expected_tokens.length
214-
expected_token = expected_tokens[expected_index]
215-
actual_token = actual_tokens.fetch(actual_index, [])
213+
while index <= max_index
214+
expected_token = expected_tokens.fetch(index, [])
215+
actual_token = actual_tokens.fetch(index, [])
216216

217-
expected_index += 1
218-
actual_index += 1
217+
index += 1
219218

220219
# There are a lot of tokens that have very specific meaning according
221220
# to the context of the parser. We don't expose that information in

0 commit comments

Comments
 (0)