Skip to content

Commit 90ef78c

Browse files
baweaverandrykonchin
authored andcommitted
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`).
1 parent 9c57d41 commit 90ef78c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: language/pattern_matching_spec.rb

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
ScratchPad.record []
66
end
77

8-
describe "can be standalone assoc operator that" do
8+
describe "Rightward assignment (`=>`) that can be standalone assoc operator that" do
99
it "deconstructs value" do
1010
suppress_warning do
1111
[0, 1] => [a, b]
@@ -22,6 +22,23 @@
2222
[a, defined?(b)].should == [0, nil]
2323
end
2424
end
25+
26+
it "can work with keywords" do
27+
{ a: 0, b: 1 } => { a:, b: }
28+
[a, b].should == [0, 1]
29+
end
30+
end
31+
32+
describe "One-line pattern matching" do
33+
it "can be used to check if a pattern matches for Array-like entities" do
34+
([0, 1] in [a, b]).should == true
35+
([0, 1] in [a, b, c]).should == false
36+
end
37+
38+
it "can be used to check if a pattern matches for Hash-like entities" do
39+
({ a: 0, b: 1 } in { a:, b: }).should == true
40+
({ a: 0, b: 1 } in { a:, b:, c: }).should == false
41+
end
2542
end
2643

2744
describe "find pattern" do

0 commit comments

Comments
 (0)