diff options
37 files changed, 322 insertions, 9 deletions
diff --git a/test/prism/fixtures/whitequark/LICENSE b/test/prism/fixtures/whitequark/LICENSE index 971310e3d6..43f9788985 100644 --- a/test/prism/fixtures/whitequark/LICENSE +++ b/test/prism/fixtures/whitequark/LICENSE @@ -1,4 +1,5 @@ -Copyright (c) 2013-2016 whitequark <[email protected]> +Copyright (c) 2013-2024 parser project contributors +Copyright (c) 2013-2016 Catherine <[email protected]> Parts of the source are derived from ruby_parser: Copyright (c) Ryan Davis, seattle.rb diff --git a/test/prism/fixtures/whitequark/arg_combinations.txt b/test/prism/fixtures/whitequark/arg_combinations.txt new file mode 100644 index 0000000000..801b1e47f4 --- /dev/null +++ b/test/prism/fixtures/whitequark/arg_combinations.txt @@ -0,0 +1,29 @@ +def f &b; end + +def f *r, &b; end + +def f *r, p, &b; end + +def f ; end + +def f a, &b; end + +def f a, *r, &b; end + +def f a, *r, p, &b; end + +def f a, o=1, &b; end + +def f a, o=1, *r, &b; end + +def f a, o=1, *r, p, &b; end + +def f a, o=1, p, &b; end + +def f o=1, &b; end + +def f o=1, *r, &b; end + +def f o=1, *r, p, &b; end + +def f o=1, p, &b; end diff --git a/test/prism/fixtures/whitequark/block_arg_combinations.txt b/test/prism/fixtures/whitequark/block_arg_combinations.txt new file mode 100644 index 0000000000..ccb9cfea56 --- /dev/null +++ b/test/prism/fixtures/whitequark/block_arg_combinations.txt @@ -0,0 +1,57 @@ +f{ } + +f{ | | } + +f{ |&b| } + +f{ |*, &b| } + +f{ |*r, p, &b| } + +f{ |*s, &b| } + +f{ |*s| } + +f{ |*| } + +f{ |; +a +| } + +f{ |;a| } + +f{ |a, &b| } + +f{ |a, *, &b| } + +f{ |a, *r, p, &b| } + +f{ |a, *s, &b| } + +f{ |a, *s| } + +f{ |a, *| } + +f{ |a, c| } + +f{ |a, o=1, &b| } + +f{ |a, o=1, *r, p, &b| } + +f{ |a, o=1, o1=2, *r, &b| } + +f{ |a, o=1, p, &b| } + +f{ |a,| } + +f{ |a| } + +f{ |o=1, &b| } + +f{ |o=1, *r, &b| } + +f{ |o=1, *r, p, &b| } + +f{ |o=1, p, &b| } + +f{ || } diff --git a/test/prism/fixtures/whitequark/block_kwarg.txt b/test/prism/fixtures/whitequark/block_kwarg.txt new file mode 100644 index 0000000000..9f1283371f --- /dev/null +++ b/test/prism/fixtures/whitequark/block_kwarg.txt @@ -0,0 +1 @@ +f{ |foo:| } diff --git a/test/prism/fixtures/whitequark/block_kwarg_combinations.txt b/test/prism/fixtures/whitequark/block_kwarg_combinations.txt new file mode 100644 index 0000000000..3dbb961777 --- /dev/null +++ b/test/prism/fixtures/whitequark/block_kwarg_combinations.txt @@ -0,0 +1,5 @@ +f{ |**baz, &b| } + +f{ |foo: 1, &b| } + +f{ |foo: 1, bar: 2, **baz, &b| } diff --git a/test/prism/fixtures/whitequark/emit_arg_inside_procarg0_legacy.txt b/test/prism/fixtures/whitequark/emit_arg_inside_procarg0_legacy.txt new file mode 100644 index 0000000000..a985f15b6e --- /dev/null +++ b/test/prism/fixtures/whitequark/emit_arg_inside_procarg0_legacy.txt @@ -0,0 +1 @@ +f{ |a| } diff --git a/test/prism/fixtures/whitequark/find_pattern.txt b/test/prism/fixtures/whitequark/find_pattern.txt new file mode 100644 index 0000000000..fb8999ae28 --- /dev/null +++ b/test/prism/fixtures/whitequark/find_pattern.txt @@ -0,0 +1,7 @@ +case foo; in *, 42, * then true; end + +case foo; in Array[*, 1, *] then true; end + +case foo; in String(*, 1, *) then true; end + +case foo; in [*x, 1 => a, *y] then true; end diff --git a/test/prism/fixtures/whitequark/kwarg_combinations.txt b/test/prism/fixtures/whitequark/kwarg_combinations.txt new file mode 100644 index 0000000000..1bd792856e --- /dev/null +++ b/test/prism/fixtures/whitequark/kwarg_combinations.txt @@ -0,0 +1,7 @@ +def f (foo: 1, &b); end + +def f (foo: 1, bar: 2, **baz, &b); end + +def f **baz, &b; end + +def f *, **; end diff --git a/test/prism/fixtures/whitequark/kwarg_no_paren.txt b/test/prism/fixtures/whitequark/kwarg_no_paren.txt new file mode 100644 index 0000000000..cf29c273d0 --- /dev/null +++ b/test/prism/fixtures/whitequark/kwarg_no_paren.txt @@ -0,0 +1,5 @@ +def f foo: +; end + +def f foo: -1 +; end diff --git a/test/prism/fixtures/whitequark/lvar_injecting_match.txt b/test/prism/fixtures/whitequark/lvar_injecting_match.txt index ba814a1088..2d18c84b57 100644 --- a/test/prism/fixtures/whitequark/lvar_injecting_match.txt +++ b/test/prism/fixtures/whitequark/lvar_injecting_match.txt @@ -1 +1,3 @@ +/(?<a>a)/ =~ 'a'; /#{}(?<b>b)/ =~ 'b'; a; b + /(?<match>bar)/ =~ 'bar'; match diff --git a/test/prism/fixtures/whitequark/marg_combinations.txt b/test/prism/fixtures/whitequark/marg_combinations.txt new file mode 100644 index 0000000000..aff34dcb62 --- /dev/null +++ b/test/prism/fixtures/whitequark/marg_combinations.txt @@ -0,0 +1,19 @@ +def f (((a))); end + +def f ((*)); end + +def f ((*, p)); end + +def f ((*r)); end + +def f ((*r, p)); end + +def f ((a, *)); end + +def f ((a, *, p)); end + +def f ((a, *r)); end + +def f ((a, *r, p)); end + +def f ((a, a1)); end diff --git a/test/prism/fixtures/whitequark/multiple_args_with_trailing_comma.txt b/test/prism/fixtures/whitequark/multiple_args_with_trailing_comma.txt new file mode 100644 index 0000000000..b690738757 --- /dev/null +++ b/test/prism/fixtures/whitequark/multiple_args_with_trailing_comma.txt @@ -0,0 +1 @@ +f{ |a, b,| } diff --git a/test/prism/fixtures/whitequark/pattern_matching_const_pattern.txt b/test/prism/fixtures/whitequark/pattern_matching_const_pattern.txt new file mode 100644 index 0000000000..82821dbc83 --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_const_pattern.txt @@ -0,0 +1,11 @@ +case foo; in A() then true; end + +case foo; in A(1, 2) then true; end + +case foo; in A(x:) then true; end + +case foo; in A[1, 2] then true; end + +case foo; in A[] then true; end + +case foo; in A[x:] then true; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_constants.txt b/test/prism/fixtures/whitequark/pattern_matching_constants.txt new file mode 100644 index 0000000000..aba764ff35 --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_constants.txt @@ -0,0 +1,5 @@ +case foo; in ::A then true; end + +case foo; in A then true; end + +case foo; in A::B then true; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_explicit_array_match.txt b/test/prism/fixtures/whitequark/pattern_matching_explicit_array_match.txt new file mode 100644 index 0000000000..61e518d0fb --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_explicit_array_match.txt @@ -0,0 +1,19 @@ +case foo; in [*, x] then true; end + +case foo; in [*x, y] then true; end + +case foo; in [x, *, y] then true; end + +case foo; in [x, *y, z] then true; end + +case foo; in [x, y, *] then true; end + +case foo; in [x, y, *z] then true; end + +case foo; in [x, y,] then true; end + +case foo; in [x, y] then true; end + +case foo; in [x,] then nil; end + +case foo; in [x] then nil; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_expr_in_paren.txt b/test/prism/fixtures/whitequark/pattern_matching_expr_in_paren.txt new file mode 100644 index 0000000000..9b2e91b70d --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_expr_in_paren.txt @@ -0,0 +1 @@ +case foo; in (1) then true; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_hash.txt b/test/prism/fixtures/whitequark/pattern_matching_hash.txt new file mode 100644 index 0000000000..b26f2c59dc --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_hash.txt @@ -0,0 +1,48 @@ +case foo; + in a: {b:}, c: + p c + ; end + +case foo; + in {Foo: 42 + } + false + ; end + +case foo; + in {a: + 2} + false + ; end + +case foo; + in {a: + } + true + ; end + +case foo; + in {a: 1 + } + false + ; end + +case foo; in ** then true; end + +case foo; in **a then true; end + +case foo; in a: 1 then true; end + +case foo; in a: 1, _a:, ** then true; end + +case foo; in a: 1, b: 2 then true; end + +case foo; in a: then true; end + +case foo; in a:, b: then true; end + +case foo; in { a: 1 } then true; end + +case foo; in { a: 1, } then true; end + +case foo; in {} then true; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_if_unless_modifiers.txt b/test/prism/fixtures/whitequark/pattern_matching_if_unless_modifiers.txt new file mode 100644 index 0000000000..05ca317355 --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_if_unless_modifiers.txt @@ -0,0 +1,3 @@ +case foo; in x if true; nil; end + +case foo; in x unless true; nil; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_implicit_array_match.txt b/test/prism/fixtures/whitequark/pattern_matching_implicit_array_match.txt new file mode 100644 index 0000000000..360c5150a5 --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_implicit_array_match.txt @@ -0,0 +1,15 @@ +case foo; in * then nil; end + +case foo; in *x then nil; end + +case foo; in *x, y, z then nil; end + +case foo; in 1, "a", [], {} then nil; end + +case foo; in x, *y, z then nil; end + +case foo; in x, then nil; end + +case foo; in x, y then nil; end + +case foo; in x, y, then nil; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_keyword_variable.txt b/test/prism/fixtures/whitequark/pattern_matching_keyword_variable.txt new file mode 100644 index 0000000000..83c7a06b09 --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_keyword_variable.txt @@ -0,0 +1 @@ +case foo; in self then true; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_lambda.txt b/test/prism/fixtures/whitequark/pattern_matching_lambda.txt new file mode 100644 index 0000000000..eeccdc70e0 --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_lambda.txt @@ -0,0 +1 @@ +case foo; in ->{ 42 } then true; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_match_alt.txt b/test/prism/fixtures/whitequark/pattern_matching_match_alt.txt new file mode 100644 index 0000000000..6c6549916d --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_match_alt.txt @@ -0,0 +1 @@ +case foo; in 1 | 2 then true; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_match_as.txt b/test/prism/fixtures/whitequark/pattern_matching_match_as.txt new file mode 100644 index 0000000000..2a105f9f36 --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_match_as.txt @@ -0,0 +1 @@ +case foo; in 1 => a then true; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_nil_pattern.txt b/test/prism/fixtures/whitequark/pattern_matching_nil_pattern.txt new file mode 100644 index 0000000000..46dce94a2d --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_nil_pattern.txt @@ -0,0 +1 @@ +case foo; in **nil then true; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_no_body.txt b/test/prism/fixtures/whitequark/pattern_matching_no_body.txt new file mode 100644 index 0000000000..73b471d352 --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_no_body.txt @@ -0,0 +1 @@ +case foo; in 1; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_ranges.txt b/test/prism/fixtures/whitequark/pattern_matching_ranges.txt new file mode 100644 index 0000000000..7e603e77b0 --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_ranges.txt @@ -0,0 +1,11 @@ +case foo; in ...2 then true; end + +case foo; in ..2 then true; end + +case foo; in 1.. then true; end + +case foo; in 1... then true; end + +case foo; in 1...2 then true; end + +case foo; in 1..2 then true; end diff --git a/test/prism/fixtures/whitequark/pattern_matching_single_match.txt b/test/prism/fixtures/whitequark/pattern_matching_single_match.txt new file mode 100644 index 0000000000..c174376585 --- /dev/null +++ b/test/prism/fixtures/whitequark/pattern_matching_single_match.txt @@ -0,0 +1 @@ +case foo; in x then x; end diff --git a/test/prism/fixtures/whitequark/pin_expr.txt b/test/prism/fixtures/whitequark/pin_expr.txt new file mode 100644 index 0000000000..a072c7c194 --- /dev/null +++ b/test/prism/fixtures/whitequark/pin_expr.txt @@ -0,0 +1,14 @@ +case foo; in ^$TestPatternMatching; end + +case foo; in ^(0+0) then nil; end + +case foo; in ^(1 +); end + +case foo; in ^(42) then nil; end + +case foo; in ^@@TestPatternMatching; end + +case foo; in ^@a; end + +case foo; in { foo: ^(42) } then nil; end diff --git a/test/prism/fixtures/whitequark/procarg0_legacy.txt b/test/prism/fixtures/whitequark/procarg0_legacy.txt new file mode 100644 index 0000000000..a985f15b6e --- /dev/null +++ b/test/prism/fixtures/whitequark/procarg0_legacy.txt @@ -0,0 +1 @@ +f{ |a| } diff --git a/test/prism/fixtures/whitequark/ruby_bug_18878.txt b/test/prism/fixtures/whitequark/ruby_bug_18878.txt new file mode 100644 index 0000000000..583280c9e3 --- /dev/null +++ b/test/prism/fixtures/whitequark/ruby_bug_18878.txt @@ -0,0 +1 @@ +Foo::Bar { |a| 42 } diff --git a/test/prism/fixtures/whitequark/ruby_bug_19281.txt b/test/prism/fixtures/whitequark/ruby_bug_19281.txt new file mode 100644 index 0000000000..cd154f9756 --- /dev/null +++ b/test/prism/fixtures/whitequark/ruby_bug_19281.txt @@ -0,0 +1,7 @@ +a.b (1;2),(3),(4) + +a.b (;),(),() + +p (1;2),(3),(4) + +p (;),(),() diff --git a/test/prism/fixtures/whitequark/ruby_bug_19539.txt b/test/prism/fixtures/whitequark/ruby_bug_19539.txt new file mode 100644 index 0000000000..b2d052d94d --- /dev/null +++ b/test/prism/fixtures/whitequark/ruby_bug_19539.txt @@ -0,0 +1,9 @@ +<<' FOO' +[Bug #19539] + FOO + + +<<-' FOO' +[Bug #19539] + FOO + diff --git a/test/prism/fixtures_test.rb b/test/prism/fixtures_test.rb index 7225b4ac66..3b4a502b90 100644 --- a/test/prism/fixtures_test.rb +++ b/test/prism/fixtures_test.rb @@ -8,11 +8,22 @@ module Prism class FixturesTest < TestCase except = [] - # Ruby < 3.3.0 cannot parse heredocs where there are leading whitespace - # characters in the heredoc start. - # Example: <<~' EOF' or <<-' EOF' - # https://bugs.ruby-lang.org/issues/19539 - except << "heredocs_leading_whitespace.txt" if RUBY_VERSION < "3.3.0" + + if RUBY_VERSION < "3.3.0" + # Ruby < 3.3.0 cannot parse heredocs where there are leading whitespace + # characters in the heredoc start. + # Example: <<~' EOF' or <<-' EOF' + # https://bugs.ruby-lang.org/issues/19539 + except << "heredocs_leading_whitespace.txt" + except << "whitequark/ruby_bug_19539.txt" + + # https://bugs.ruby-lang.org/issues/19025 + except << "whitequark/numparam_ruby_bug_19025.txt" + # https://bugs.ruby-lang.org/issues/18878 + except << "whitequark/ruby_bug_18878.txt" + # https://bugs.ruby-lang.org/issues/19281 + except << "whitequark/ruby_bug_19281.txt" + end Fixture.each(except: except) do |fixture| define_method(fixture.test_name) { assert_valid_syntax(fixture.read) } diff --git a/test/prism/lex_test.rb b/test/prism/lex_test.rb index 7eac677ef7..0e03874a15 100644 --- a/test/prism/lex_test.rb +++ b/test/prism/lex_test.rb @@ -28,6 +28,14 @@ module Prism # Example: <<~' EOF' or <<-' EOF' # https://bugs.ruby-lang.org/issues/19539 except << "heredocs_leading_whitespace.txt" + except << "whitequark/ruby_bug_19539.txt" + + # https://bugs.ruby-lang.org/issues/19025 + except << "whitequark/numparam_ruby_bug_19025.txt" + # https://bugs.ruby-lang.org/issues/18878 + except << "whitequark/ruby_bug_18878.txt" + # https://bugs.ruby-lang.org/issues/19281 + except << "whitequark/ruby_bug_19281.txt" end Fixture.each(except: except) do |fixture| diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb index a197e24b1c..e972142672 100644 --- a/test/prism/ruby/parser_test.rb +++ b/test/prism/ruby/parser_test.rb @@ -154,13 +154,14 @@ module Prism "whitequark/dedenting_heredoc.txt", "whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt", "whitequark/forward_arg_with_open_args.txt", - "whitequark/interp_digit_var.txt", + "whitequark/kwarg_no_paren.txt", "whitequark/lbrace_arg_after_command_args.txt", "whitequark/multiple_pattern_matches.txt", "whitequark/newline_in_hash_argument.txt", "whitequark/parser_bug_640.txt", - "whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt", - "whitequark/ruby_bug_11990.txt", + "whitequark/pattern_matching_expr_in_paren.txt", + "whitequark/pattern_matching_hash.txt", + "whitequark/pin_expr.txt", "whitequark/ruby_bug_14690.txt", "whitequark/ruby_bug_9669.txt", "whitequark/slash_newline_in_heredocs.txt", diff --git a/test/prism/ruby/ripper_test.rb b/test/prism/ruby/ripper_test.rb index 8db47da3d3..7ed32ed216 100644 --- a/test/prism/ruby/ripper_test.rb +++ b/test/prism/ruby/ripper_test.rb @@ -45,6 +45,7 @@ module Prism "whitequark/dedenting_heredoc.txt", "whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt", "whitequark/parser_slash_slash_n_escaping_in_literals.txt", + "whitequark/ruby_bug_18878.txt", "whitequark/send_block_chain_cmd.txt", "whitequark/slash_newline_in_heredocs.txt" ] diff --git a/test/prism/ruby/ruby_parser_test.rb b/test/prism/ruby/ruby_parser_test.rb index fe410c8144..1aa0f540cc 100644 --- a/test/prism/ruby/ruby_parser_test.rb +++ b/test/prism/ruby/ruby_parser_test.rb @@ -38,6 +38,9 @@ module Prism "unparser/corpus/literal/kwbegin.txt", "unparser/corpus/literal/send.txt", "whitequark/masgn_const.txt", + "whitequark/pattern_matching_constants.txt", + "whitequark/pattern_matching_implicit_array_match.txt", + "whitequark/pattern_matching_single_match.txt", "whitequark/ruby_bug_12402.txt", "whitequark/ruby_bug_14690.txt", "whitequark/space_args_block.txt" @@ -81,6 +84,8 @@ module Prism "whitequark/pattern_matching_single_line_allowed_omission_of_parentheses.txt", "whitequark/pattern_matching_single_line.txt", "whitequark/ruby_bug_11989.txt", + "whitequark/ruby_bug_18878.txt", + "whitequark/ruby_bug_19281.txt", "whitequark/slash_newline_in_heredocs.txt" ] |