Skip to content

Commit

Permalink
Fix and remove spec testing undefined behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
k-tsj committed Nov 7, 2020
1 parent 5b3572b commit 640fd94
Showing 1 changed file with 8 additions and 34 deletions.
42 changes: 8 additions & 34 deletions spec/ruby/language/pattern_matching_spec.rb
Original file line number Diff line number Diff line change
@@ -316,26 +316,26 @@
end

it "supports using _ in a pattern several times" do
eval(<<~RUBY).should == 2
eval(<<~RUBY).should == true
case [0, 1, 2]
in [0, _, _]
_
true
end
RUBY
end

it "supports using any name with _ at the beginning in a pattern several times" do
eval(<<~RUBY).should == 2
eval(<<~RUBY).should == true
case [0, 1, 2]
in [0, _x, _x]
_x
true
end
RUBY

eval(<<~RUBY).should == 2
eval(<<~RUBY).should == true
case {a: 0, b: 1, c: 2}
in {a: 0, b: _x, c: _x}
_x
true
end
RUBY
end
@@ -569,19 +569,6 @@ def obj.deconstruct; [1] end
RUBY
end

it "binds variable even if patter matches only partially" do
a = nil

eval(<<~RUBY).should == 0
case [0, 1, 2]
in [a, 1, 3]
else
end
a
RUBY
end

it "supports splat operator *rest" do
eval(<<~RUBY).should == [1, 2]
case [0, 1, 2]
@@ -870,7 +857,7 @@ def obj.deconstruct_keys(*args)
end
RUBY

ScratchPad.recorded.should == [[[:a, :b, :c]]]
ScratchPad.recorded.sort.should == [[[:a, :b, :c]]]
end

it "passes keys specified in pattern to #deconstruct_keys method if pattern contains double splat operator **" do
@@ -887,7 +874,7 @@ def obj.deconstruct_keys(*args)
end
RUBY

ScratchPad.recorded.should == [[[:a, :b]]]
ScratchPad.recorded.sort.should == [[[:a, :b]]]
end

it "passes nil to #deconstruct_keys method if pattern contains double splat operator **rest" do
@@ -916,19 +903,6 @@ def obj.deconstruct_keys(*args)
RUBY
end

it "binds variable even if pattern matches only partially" do
x = nil

eval(<<~RUBY).should == 0
case {a: 0, b: 1}
in {a: x, b: 2}
else
end
x
RUBY
end

it "supports double splat operator **rest" do
eval(<<~RUBY).should == {b: 1, c: 2}
case {a: 0, b: 1, c: 2}

0 comments on commit 640fd94

Please sign in to comment.