From e9e9a48e43e2e4665bcf573184cddcce04388359 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Mon, 13 Jan 2025 21:22:07 +0100 Subject: [PATCH] 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, #]] <[]> expected but was <[:tNL, [nil, #]]> ``` --- test/prism/ruby/parser_test.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb index 935e6ed8af..8d791da369 100644 --- a/test/prism/ruby/parser_test.rb +++ b/test/prism/ruby/parser_test.rb @@ -207,15 +207,14 @@ def assert_equal_asts_message(expected_ast, actual_ast) def assert_equal_tokens(expected_tokens, actual_tokens) if expected_tokens != actual_tokens - expected_index = 0 - actual_index = 0 + index = 0 + max_index = [expected_tokens, actual_tokens].map(&:size).max - while expected_index < expected_tokens.length - expected_token = expected_tokens[expected_index] - actual_token = actual_tokens.fetch(actual_index, []) + while index <= max_index + expected_token = expected_tokens.fetch(index, []) + actual_token = actual_tokens.fetch(index, []) - expected_index += 1 - actual_index += 1 + index += 1 # There are a lot of tokens that have very specific meaning according # to the context of the parser. We don't expose that information in