From 90ef78c9397dfe414b576687b6e2004359bdd107 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 | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/language/pattern_matching_spec.rb b/language/pattern_matching_spec.rb index 8c5df06a1..52608b48b 100644 --- a/language/pattern_matching_spec.rb +++ b/language/pattern_matching_spec.rb @@ -5,7 +5,7 @@ ScratchPad.record [] end - describe "can be standalone assoc operator that" do + describe "Rightward assignment (`=>`) that can be standalone assoc operator that" do it "deconstructs value" do suppress_warning do [0, 1] => [a, b] @@ -22,6 +22,23 @@ [a, defined?(b)].should == [0, nil] end end + + it "can work with keywords" do + { a: 0, b: 1 } => { a:, b: } + [a, b].should == [0, 1] + end + end + + describe "One-line pattern matching" do + it "can be used to check if a pattern matches for Array-like entities" do + ([0, 1] in [a, b]).should == true + ([0, 1] in [a, b, c]).should == false + end + + it "can be used to check if a pattern matches for Hash-like entities" do + ({ a: 0, b: 1 } in { a:, b: }).should == true + ({ a: 0, b: 1 } in { a:, b:, c: }).should == false + end end describe "find pattern" do