Skip to content

Commit

Permalink
Merge pull request #855 from baweaver/baweaver/ruby-3/one-line-17260
Browse files Browse the repository at this point in the history
Adds spec for Feature#17260 and Feature#17231
  • Loading branch information
andrykonchin authored Jun 26, 2024
2 parents 9c57d41 + 90ef78c commit 9fbc6ed
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion language/pattern_matching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit 9fbc6ed

Please sign in to comment.