diff options
| author | Earlopain <14981592+Earlopain@users.noreply.github.com> | 2025-08-14 17:05:54 +0200 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2025-08-14 15:42:33 +0000 |
| commit | a04555c8ab109355d00275d28d867fce06805c55 (patch) | |
| tree | 22690666c2cf4202322faa1c39b43a0373d69562 /test/prism/ruby | |
| parent | a677220aba0c99f93f234a009bceeae063a96889 (diff) | |
[ruby/prism] Be more defensive in the parser translator lexer
Generally I have been good about safely accessing the tokens but failed
to properly guard against no tokens in places
where it could theoretically happen through invalid syntax.
I added a test case for one occurance, other changes are theoretical only.
https://github.com/ruby/prism/commit/4a3866af19
Diffstat (limited to 'test/prism/ruby')
| -rw-r--r-- | test/prism/ruby/parser_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb index 156e8f9e9f..2a4ea981bd 100644 --- a/test/prism/ruby/parser_test.rb +++ b/test/prism/ruby/parser_test.rb @@ -163,6 +163,22 @@ module Prism end end + def test_invalid_syntax + code = <<~RUBY + foo do + case bar + when + end + end + RUBY + buffer = Parser::Source::Buffer.new("(string)") + buffer.source = code + + parser = Prism::Translation::Parser33.new + parser.diagnostics.all_errors_are_fatal = true + assert_raise(Parser::SyntaxError) { parser.tokenize(buffer) } + end + def test_it_block_parameter_syntax it_fixture_path = Pathname(__dir__).join("../../../test/prism/fixtures/it.txt") |
