diff options
author | Andrew Konchin <[email protected]> | 2024-07-01 15:38:25 +0300 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2024-07-02 13:33:48 +0200 |
commit | cee62c6738c42ce774e96e180cf2d46afb8e9cbe (patch) | |
tree | 52a37ef94e90f99f8471dbba4d6659ca5dc6c532 /spec/ruby/language/pattern_matching_spec.rb | |
parent | d7af8afe1b85b8de04cd77c673b0f6ef3f3627fa (diff) |
Update to ruby/spec@f8987ac
Diffstat (limited to 'spec/ruby/language/pattern_matching_spec.rb')
-rw-r--r-- | spec/ruby/language/pattern_matching_spec.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/spec/ruby/language/pattern_matching_spec.rb b/spec/ruby/language/pattern_matching_spec.rb index 8c5df06a17..52608b48be 100644 --- a/spec/ruby/language/pattern_matching_spec.rb +++ b/spec/ruby/language/pattern_matching_spec.rb @@ -5,7 +5,7 @@ describe "Pattern matching" do 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 @@ describe "Pattern matching" do [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 |