Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions rakelib/whitequark.rake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace :whitequark do
# This object is going to collect all of the examples from the parser gem
# into a hash that we can use to generate our own tests.
COLLECTED = Hash.new { |hash, key| hash[key] = [] }
ALL_VERSIONS = %w[3.1 3.2]
ALL_VERSIONS = %w[3.1 3.2 3.3]

private

Expand All @@ -60,10 +60,10 @@ namespace :whitequark do
def assert_parses(_ast, code, _source_maps = "", versions = ALL_VERSIONS)
# We're going to skip any examples that are for older Ruby versions
# that we do not support.
return if (versions & %w[3.1 3.2]).empty?
return if (versions & ALL_VERSIONS).empty?

entry = caller.find { _1.include?("test_parser.rb") }
_, name = *entry.match(/\d+:in `(?:block in )?(?:test_|assert_parses_)?(.+)'/)
entry = caller_locations.find { _1.base_label.start_with?("test_") }
name = entry.base_label.delete_prefix("test_")

COLLECTED[name] << code
end
Expand Down Expand Up @@ -94,7 +94,8 @@ namespace :whitequark do
test/prism/fixtures/whitequark/if_while_after_class__since_32.txt
test/prism/fixtures/whitequark/next_block.txt
test/prism/fixtures/whitequark/next.txt
test/prism/fixtures/whitequark/pattern_match.txt
test/prism/fixtures/whitequark/pattern_matching_pin_variable.txt
test/prism/fixtures/whitequark/pattern_matching_hash_with_string_keys.txt
test/prism/fixtures/whitequark/range_endless.txt
test/prism/fixtures/whitequark/redo.txt
test/prism/fixtures/whitequark/retry.txt
Expand Down
3 changes: 2 additions & 1 deletion test/prism/fixtures/whitequark/LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
29 changes: 29 additions & 0 deletions test/prism/fixtures/whitequark/arg_combinations.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 57 additions & 0 deletions test/prism/fixtures/whitequark/block_arg_combinations.txt
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions test/prism/fixtures/whitequark/block_kwarg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f{ |foo:| }
5 changes: 5 additions & 0 deletions test/prism/fixtures/whitequark/block_kwarg_combinations.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
f{ |**baz, &b| }

f{ |foo: 1, &b| }

f{ |foo: 1, bar: 2, **baz, &b| }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f{ |a| }
7 changes: 7 additions & 0 deletions test/prism/fixtures/whitequark/find_pattern.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions test/prism/fixtures/whitequark/kwarg_combinations.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions test/prism/fixtures/whitequark/kwarg_no_paren.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def f foo:
; end

def f foo: -1
; end
2 changes: 2 additions & 0 deletions test/prism/fixtures/whitequark/lvar_injecting_match.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/(?<a>a)/ =~ 'a'; /#{}(?<b>b)/ =~ 'b'; a; b

/(?<match>bar)/ =~ 'bar'; match
19 changes: 19 additions & 0 deletions test/prism/fixtures/whitequark/marg_combinations.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f{ |a, b,| }
11 changes: 11 additions & 0 deletions test/prism/fixtures/whitequark/pattern_matching_const_pattern.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions test/prism/fixtures/whitequark/pattern_matching_constants.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case foo; in (1) then true; end
48 changes: 48 additions & 0 deletions test/prism/fixtures/whitequark/pattern_matching_hash.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
case foo; in x if true; nil; end

case foo; in x unless true; nil; end
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case foo; in self then true; end
1 change: 1 addition & 0 deletions test/prism/fixtures/whitequark/pattern_matching_lambda.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case foo; in ->{ 42 } then true; end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case foo; in 1 | 2 then true; end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case foo; in 1 => a then true; end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case foo; in **nil then true; end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case foo; in 1; end
11 changes: 11 additions & 0 deletions test/prism/fixtures/whitequark/pattern_matching_ranges.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case foo; in x then x; end
14 changes: 14 additions & 0 deletions test/prism/fixtures/whitequark/pin_expr.txt
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions test/prism/fixtures/whitequark/procarg0_legacy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f{ |a| }
1 change: 1 addition & 0 deletions test/prism/fixtures/whitequark/ruby_bug_18878.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo::Bar { |a| 42 }
7 changes: 7 additions & 0 deletions test/prism/fixtures/whitequark/ruby_bug_19281.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a.b (1;2),(3),(4)

a.b (;),(),()

p (1;2),(3),(4)

p (;),(),()
9 changes: 9 additions & 0 deletions test/prism/fixtures/whitequark/ruby_bug_19539.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<<' FOO'
[Bug #19539]
FOO


<<-' FOO'
[Bug #19539]
FOO

21 changes: 16 additions & 5 deletions test/prism/fixtures_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Loading
Loading