mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[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:
parent
ca81142eff
commit
81079ebfd8
37 changed files with 322 additions and 9 deletions
|
@ -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
|
||||
|
|
29
test/prism/fixtures/whitequark/arg_combinations.txt
Normal file
29
test/prism/fixtures/whitequark/arg_combinations.txt
Normal 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
|
57
test/prism/fixtures/whitequark/block_arg_combinations.txt
Normal file
57
test/prism/fixtures/whitequark/block_arg_combinations.txt
Normal 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{ || }
|
1
test/prism/fixtures/whitequark/block_kwarg.txt
Normal file
1
test/prism/fixtures/whitequark/block_kwarg.txt
Normal file
|
@ -0,0 +1 @@
|
|||
f{ |foo:| }
|
|
@ -0,0 +1,5 @@
|
|||
f{ |**baz, &b| }
|
||||
|
||||
f{ |foo: 1, &b| }
|
||||
|
||||
f{ |foo: 1, bar: 2, **baz, &b| }
|
|
@ -0,0 +1 @@
|
|||
f{ |a| }
|
7
test/prism/fixtures/whitequark/find_pattern.txt
Normal file
7
test/prism/fixtures/whitequark/find_pattern.txt
Normal 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
|
7
test/prism/fixtures/whitequark/kwarg_combinations.txt
Normal file
7
test/prism/fixtures/whitequark/kwarg_combinations.txt
Normal 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
|
5
test/prism/fixtures/whitequark/kwarg_no_paren.txt
Normal file
5
test/prism/fixtures/whitequark/kwarg_no_paren.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
def f foo:
|
||||
; end
|
||||
|
||||
def f foo: -1
|
||||
; end
|
|
@ -1 +1,3 @@
|
|||
/(?<a>a)/ =~ 'a'; /#{}(?<b>b)/ =~ 'b'; a; b
|
||||
|
||||
/(?<match>bar)/ =~ 'bar'; match
|
||||
|
|
19
test/prism/fixtures/whitequark/marg_combinations.txt
Normal file
19
test/prism/fixtures/whitequark/marg_combinations.txt
Normal 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
|
|
@ -0,0 +1 @@
|
|||
f{ |a, b,| }
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
case foo; in (1) then true; end
|
48
test/prism/fixtures/whitequark/pattern_matching_hash.txt
Normal file
48
test/prism/fixtures/whitequark/pattern_matching_hash.txt
Normal 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
|
|
@ -0,0 +1,3 @@
|
|||
case foo; in x if true; nil; end
|
||||
|
||||
case foo; in x unless true; nil; end
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
case foo; in self then true; end
|
|
@ -0,0 +1 @@
|
|||
case foo; in ->{ 42 } then true; end
|
|
@ -0,0 +1 @@
|
|||
case foo; in 1 | 2 then true; end
|
|
@ -0,0 +1 @@
|
|||
case foo; in 1 => a then true; end
|
|
@ -0,0 +1 @@
|
|||
case foo; in **nil then true; end
|
|
@ -0,0 +1 @@
|
|||
case foo; in 1; end
|
11
test/prism/fixtures/whitequark/pattern_matching_ranges.txt
Normal file
11
test/prism/fixtures/whitequark/pattern_matching_ranges.txt
Normal 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
|
|
@ -0,0 +1 @@
|
|||
case foo; in x then x; end
|
14
test/prism/fixtures/whitequark/pin_expr.txt
Normal file
14
test/prism/fixtures/whitequark/pin_expr.txt
Normal 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
|
1
test/prism/fixtures/whitequark/procarg0_legacy.txt
Normal file
1
test/prism/fixtures/whitequark/procarg0_legacy.txt
Normal file
|
@ -0,0 +1 @@
|
|||
f{ |a| }
|
1
test/prism/fixtures/whitequark/ruby_bug_18878.txt
Normal file
1
test/prism/fixtures/whitequark/ruby_bug_18878.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Foo::Bar { |a| 42 }
|
7
test/prism/fixtures/whitequark/ruby_bug_19281.txt
Normal file
7
test/prism/fixtures/whitequark/ruby_bug_19281.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
a.b (1;2),(3),(4)
|
||||
|
||||
a.b (;),(),()
|
||||
|
||||
p (1;2),(3),(4)
|
||||
|
||||
p (;),(),()
|
9
test/prism/fixtures/whitequark/ruby_bug_19539.txt
Normal file
9
test/prism/fixtures/whitequark/ruby_bug_19539.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
<<' FOO'
|
||||
[Bug #19539]
|
||||
FOO
|
||||
|
||||
|
||||
<<-' FOO'
|
||||
[Bug #19539]
|
||||
FOO
|
||||
|
|
@ -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) }
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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"
|
||||
]
|
||||
|
|
|
@ -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"
|
||||
]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue