From e0c5488ff9308b1a16718c64bc9096caca88ed83 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 28 Jan 2022 14:42:38 +0100 Subject: Update to ruby/spec@902ab83 --- spec/ruby/language/pattern_matching_spec.rb | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'spec/ruby/language/pattern_matching_spec.rb') diff --git a/spec/ruby/language/pattern_matching_spec.rb b/spec/ruby/language/pattern_matching_spec.rb index 5f5e2f4902..c68b6caa34 100644 --- a/spec/ruby/language/pattern_matching_spec.rb +++ b/spec/ruby/language/pattern_matching_spec.rb @@ -74,6 +74,50 @@ ruby_version_is "2.7" do end RUBY end + + it "can be nested" do + eval(<<~RUBY).should == [[0, [2, 4, 6]], [[4, 16, 64]], 27] + case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]] + in [*pre, [*, 9, a], *post] + [pre, post, a] + else + false + end + RUBY + end + + it "can be nested with an array pattern" do + eval(<<~RUBY).should == [[4, 16, 64]] + case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]] + in [_, _, [*, 9, *], *post] + post + else + false + end + RUBY + end + + it "can be nested within a hash pattern" do + eval(<<~RUBY).should == [27] + case {a: [3, 9, 27]} + in {a: [*, 9, *post]} + post + else + false + end + RUBY + end + + it "can nest hash and array patterns" do + eval(<<~RUBY).should == [42, 2] + case [0, {a: 42, b: [0, 1]}, {a: 42, b: [1, 2]}] + in [*, {a:, b: [1, c]}, *] + [a, c] + else + false + end + RUBY + end end end -- cgit v1.2.3