From 332ea508ff0d84fabad26be6cd9830ebdd7f37fc Mon Sep 17 00:00:00 2001 From: Brandon Weaver Date: Tue, 5 Oct 2021 21:50:54 -0700 Subject: [PATCH] Adds spec for #17260 and #17231 Adds specs for one-line pattern matching syntax in Ruby 3.0+, including both Righthand Assignment (`=>`) and one-line match (`in`). --- language/pattern_matching_spec.rb | 49 +++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/language/pattern_matching_spec.rb b/language/pattern_matching_spec.rb index c6a3008458..8ebe00d706 100644 --- a/language/pattern_matching_spec.rb +++ b/language/pattern_matching_spec.rb @@ -10,12 +10,49 @@ end ruby_version_is "3.0" do - it "can be standalone assoc operator that deconstructs value" do - suppress_warning do - eval(<<-RUBY).should == [0, 1] - [0, 1] => [a, b] - [a, b] - RUBY + describe "Rightward assignment (`=>`)" do + it "can be standalone assoc operator that deconstructs value" do + suppress_warning do + eval(<<~RUBY).should == [0, 1] + [0, 1] => [a, b] + [a, b] + RUBY + end + end + + it "can work with keywords" do + suppress_warning do + eval(<<~RUBY).should == [0, 1] + { a: 0, b: 1 } => { a:, b: } + [a, b] + RUBY + end + end + end + + describe "One-line pattern matching" do + it "can be used to check if a pattern matches for Array-like entities" do + suppress_warning do + eval(<<~RUBY).should == true + [0, 1] in [a, b] + RUBY + + eval(<<~RUBY).should == false + [0, 1] in [a, b, c] + RUBY + end + end + + it "can be used to check if a pattern matches for Hash-like entities" do + suppress_warning do + eval(<<~RUBY).should == true + { a: 0, b: 1 } in { a:, b: } + RUBY + + eval(<<~RUBY).should == false + { a: 0, b: 1 } in { a:, b:, c: } + RUBY + end end end end