diff options
author | TSUYUSATO Kitsune <make.just.on@gmail.com> | 2023-11-14 16:20:41 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-11-14 14:34:48 +0000 |
commit | 499786de4658de5d9c1ebe68ec99fbbfdf63f8e1 (patch) | |
tree | a59bee44eb64da8c85677685823b4ad486fe4ede /test/prism/errors_test.rb | |
parent | 3439f1e62e60db0f154ffdb53a1217378b4c9038 (diff) | |
download | ruby-499786de4658de5d9c1ebe68ec99fbbfdf63f8e1.tar.gz |
[ruby/prism] Check value expressions on parsing arguments and assignments
They are corresponding to `arg_value` in `parse.y`.
https://github.com/ruby/prism/commit/a4a4834e0d
Diffstat (limited to 'test/prism/errors_test.rb')
-rw-r--r-- | test/prism/errors_test.rb | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/test/prism/errors_test.rb b/test/prism/errors_test.rb index 0eb0f5bb58..9a63b32e30 100644 --- a/test/prism/errors_test.rb +++ b/test/prism/errors_test.rb @@ -1511,6 +1511,39 @@ module Prism ], compare_ripper: false # Ripper does not check 'void value expression'. end + def test_void_value_expression_in_def + source = <<~RUBY + def (return).x + end + def x(a = return) + end + def x(a: return) + end + RUBY + message = 'Unexpected void value expression' + assert_errors expression(source), source, [ + [message, 5..11], + [message, 29..35], + [message, 50..56], + ], compare_ripper: false # Ripper does not check 'void value expression'. + end + + def test_void_value_expression_in_assignment + source = <<~RUBY + a = return + a = 1, return + a, b = return, 1 + a, b = 1, *return + RUBY + message = 'Unexpected void value expression' + assert_errors expression(source), source, [ + [message, 4..10], + [message, 18..24], + [message, 32..38], + [message, 53..59], + ], compare_ripper: false # Ripper does not check 'void value expression'. + end + def test_void_value_expression_in_modifier source = <<~RUBY 1 if (return) @@ -1527,6 +1560,46 @@ module Prism ], compare_ripper: false # Ripper does not check 'void value expression'. end + def test_void_value_expression_in_arguments + source = <<~RUBY + foo(return) + foo(1, return) + foo(*return) + foo(**return) + foo(&return) + foo(return => 1) + foo(:a => return) + foo(a: return) + RUBY + message = 'Unexpected void value expression' + assert_errors expression(source), source, [ + [message, 4..10], + [message, 19..25], + [message, 32..38], + [message, 46..52], + [message, 59..65], + [message, 71..77], + [message, 94..100], + [message, 109..115], + ], compare_ripper: false # Ripper does not check 'void value expression'. + end + + def test_void_value_expression_in_hash + source = <<~RUBY + { return => 1 } + { 1 => return } + { a: return } + { **return } + RUBY + message = 'Unexpected void value expression' + assert_errors expression(source), source, [ + [message, 2..8], + [message, 23..29], + [message, 37..43], + [message, 50..56], + ], compare_ripper: false # Ripper does not check 'void value expression'. + end + private def assert_errors(expected, source, errors, compare_ripper: RUBY_ENGINE == "ruby") |