diff options
| author | Earlopain <14981592+Earlopain@users.noreply.github.com> | 2025-01-13 21:22:07 +0100 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2025-01-14 15:36:28 +0000 |
| commit | 23fc0fc22d0f066938387f3397fb8ee9358744e5 (patch) | |
| tree | 0661e27e90396caa7538cbbe7c50056dcf6c73e4 | |
| parent | d0c493df7d1bb4b32ede82422b0d08f72de025b9 (diff) | |
[ruby/prism] 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>]]>
```
https://github.com/ruby/prism/commit/e9e9a48e43
| -rw-r--r-- | test/prism/ruby/parser_test.rb | 13 |
1 files 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 @@ module Prism 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 |
