[ruby/prism] Import code samples for Ruby 3.3 from the parser gem

Slightly tweaking the import script becaues of backtrace format changes in Ruby 3.4

Most tests pass in all parsers, with only a handful of failures overall

9b5b785aa4
This commit is contained in:
Earlopain 2025-01-06 15:20:41 +01:00 committed by Kevin Newton
parent ca81142eff
commit 81079ebfd8
37 changed files with 322 additions and 9 deletions

View file

@ -1,4 +1,5 @@
Copyright (c) 2013-2016 whitequark <whitequark@whitequark.org>
Copyright (c) 2013-2024 parser project contributors
Copyright (c) 2013-2016 Catherine <whitequark@whitequark.org>
Parts of the source are derived from ruby_parser:
Copyright (c) Ryan Davis, seattle.rb

View file

@ -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

View file

@ -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{ || }

View file

@ -0,0 +1 @@
f{ |foo:| }

View file

@ -0,0 +1,5 @@
f{ |**baz, &b| }
f{ |foo: 1, &b| }
f{ |foo: 1, bar: 2, **baz, &b| }

View file

@ -0,0 +1 @@
f{ |a| }

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,5 @@
def f foo:
; end
def f foo: -1
; end

View file

@ -1 +1,3 @@
/(?<a>a)/ =~ 'a'; /#{}(?<b>b)/ =~ 'b'; a; b
/(?<match>bar)/ =~ 'bar'; match

View file

@ -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

View file

@ -0,0 +1 @@
f{ |a, b,| }

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1 @@
case foo; in (1) then true; end

View file

@ -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

View file

@ -0,0 +1,3 @@
case foo; in x if true; nil; end
case foo; in x unless true; nil; end

View file

@ -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

View file

@ -0,0 +1 @@
case foo; in self then true; end

View file

@ -0,0 +1 @@
case foo; in ->{ 42 } then true; end

View file

@ -0,0 +1 @@
case foo; in 1 | 2 then true; end

View file

@ -0,0 +1 @@
case foo; in 1 => a then true; end

View file

@ -0,0 +1 @@
case foo; in **nil then true; end

View file

@ -0,0 +1 @@
case foo; in 1; end

View file

@ -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

View file

@ -0,0 +1 @@
case foo; in x then x; end

View file

@ -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

View file

@ -0,0 +1 @@
f{ |a| }

View file

@ -0,0 +1 @@
Foo::Bar { |a| 42 }

View file

@ -0,0 +1,7 @@
a.b (1;2),(3),(4)
a.b (;),(),()
p (1;2),(3),(4)
p (;),(),()

View file

@ -0,0 +1,9 @@
<<' FOO'
[Bug #19539]
FOO
<<-' FOO'
[Bug #19539]
FOO

View file

@ -8,11 +8,22 @@ module Prism
class FixturesTest < TestCase
except = []
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" if RUBY_VERSION < "3.3.0"
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) }

View file

@ -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|

View file

@ -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",

View file

@ -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"
]

View file

@ -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"
]