Fix indentation

This commit is contained in:
Kazuki Tsujimoto 2020-11-07 22:12:22 +09:00
parent 640fd94eff
commit 5823f6c25b
No known key found for this signature in database
GPG Key ID: BCEA306C49B81CD7

View File

@ -23,10 +23,10 @@ ruby_version_is "2.7" do
it "extends case expression with case/in construction" do it "extends case expression with case/in construction" do
eval(<<~RUBY).should == :bar eval(<<~RUBY).should == :bar
case [0, 1] case [0, 1]
in [0] in [0]
:foo :foo
in [0, 1] in [0, 1]
:bar :bar
end end
RUBY RUBY
end end
@ -34,8 +34,8 @@ ruby_version_is "2.7" do
it "allows using then operator" do it "allows using then operator" do
eval(<<~RUBY).should == :bar eval(<<~RUBY).should == :bar
case [0, 1] case [0, 1]
in [0] then :foo in [0] then :foo
in [0, 1] then :bar in [0, 1] then :bar
end end
RUBY RUBY
end end
@ -59,8 +59,8 @@ ruby_version_is "2.7" do
it "binds variables" do it "binds variables" do
eval(<<~RUBY).should == 1 eval(<<~RUBY).should == 1
case [0, 1] case [0, 1]
in [0, a] in [0, a]
a a
end end
RUBY RUBY
end end
@ -69,8 +69,8 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~RUBY eval <<~RUBY
case [] case []
when 1 == 1 when 1 == 1
in [] in []
end end
RUBY RUBY
}.should raise_error(SyntaxError, /syntax error, unexpected `in'/) }.should raise_error(SyntaxError, /syntax error, unexpected `in'/)
@ -78,8 +78,8 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~RUBY eval <<~RUBY
case [] case []
in [] in []
when 1 == 1 when 1 == 1
end end
RUBY RUBY
}.should raise_error(SyntaxError, /syntax error, unexpected `when'/) }.should raise_error(SyntaxError, /syntax error, unexpected `when'/)
@ -88,12 +88,12 @@ ruby_version_is "2.7" do
it "checks patterns until the first matching" do it "checks patterns until the first matching" do
eval(<<~RUBY).should == :bar eval(<<~RUBY).should == :bar
case [0, 1] case [0, 1]
in [0] in [0]
:foo :foo
in [0, 1] in [0, 1]
:bar :bar
in [0, 1] in [0, 1]
:baz :baz
end end
RUBY RUBY
end end
@ -101,10 +101,10 @@ ruby_version_is "2.7" do
it "executes else clause if no pattern matches" do it "executes else clause if no pattern matches" do
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case [0, 1] case [0, 1]
in [0] in [0]
true true
else else
false false
end end
RUBY RUBY
end end
@ -113,7 +113,7 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~RUBY eval <<~RUBY
case [0, 1] case [0, 1]
in [0] in [0]
end end
RUBY RUBY
}.should raise_error(NoMatchingPatternError, /\[0, 1\]/) }.should raise_error(NoMatchingPatternError, /\[0, 1\]/)
@ -123,8 +123,8 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~RUBY eval <<~RUBY
case 0 case 0
in 1 + 1 in 1 + 1
true true
end end
RUBY RUBY
}.should raise_error(SyntaxError, /unexpected/) }.should raise_error(SyntaxError, /unexpected/)
@ -134,8 +134,8 @@ ruby_version_is "2.7" do
it "supports if guard" do it "supports if guard" do
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case 0 case 0
in 0 if false in 0 if false
true true
else else
false false
end end
@ -143,8 +143,8 @@ ruby_version_is "2.7" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case 0 case 0
in 0 if true in 0 if true
true true
else else
false false
end end
@ -154,8 +154,8 @@ ruby_version_is "2.7" do
it "supports unless guard" do it "supports unless guard" do
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case 0 case 0
in 0 unless true in 0 unless true
true true
else else
false false
end end
@ -163,8 +163,8 @@ ruby_version_is "2.7" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case 0 case 0
in 0 unless false in 0 unless false
true true
else else
false false
end end
@ -174,8 +174,8 @@ ruby_version_is "2.7" do
it "makes bound variables visible in guard" do it "makes bound variables visible in guard" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case [0, 1] case [0, 1]
in [a, 1] if a >= 0 in [a, 1] if a >= 0
true true
end end
RUBY RUBY
end end
@ -183,7 +183,7 @@ ruby_version_is "2.7" do
it "does not evaluate guard if pattern does not match" do it "does not evaluate guard if pattern does not match" do
eval <<~RUBY eval <<~RUBY
case 0 case 0
in 1 if (ScratchPad << :foo) || true in 1 if (ScratchPad << :foo) || true
else else
end end
RUBY RUBY
@ -194,10 +194,10 @@ ruby_version_is "2.7" do
it "takes guards into account when there are several matching patterns" do it "takes guards into account when there are several matching patterns" do
eval(<<~RUBY).should == :bar eval(<<~RUBY).should == :bar
case 0 case 0
in 0 if false in 0 if false
:foo :foo
in 0 if true in 0 if true
:bar :bar
end end
RUBY RUBY
end end
@ -205,8 +205,8 @@ ruby_version_is "2.7" do
it "executes else clause if no guarded pattern matches" do it "executes else clause if no guarded pattern matches" do
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case 0 case 0
in 0 if false in 0 if false
true true
else else
false false
end end
@ -217,7 +217,7 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~RUBY eval <<~RUBY
case [0, 1] case [0, 1]
in [0, 1] if false in [0, 1] if false
end end
RUBY RUBY
}.should raise_error(NoMatchingPatternError, /\[0, 1\]/) }.should raise_error(NoMatchingPatternError, /\[0, 1\]/)
@ -228,36 +228,36 @@ ruby_version_is "2.7" do
it "matches an object such that pattern === object" do it "matches an object such that pattern === object" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case 0 case 0
in 0 in 0
true true
end end
RUBY RUBY
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case 0 case 0
in (-1..1) in (-1..1)
true true
end end
RUBY RUBY
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case 0 case 0
in Integer in Integer
true true
end end
RUBY RUBY
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case "0" case "0"
in /0/ in /0/
true true
end end
RUBY RUBY
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case "0" case "0"
in ->(s) { s == "0" } in ->(s) { s == "0" }
true true
end end
RUBY RUBY
end end
@ -267,8 +267,8 @@ ruby_version_is "2.7" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case "x" case "x"
in "#{x + ""}" in "#{x + ""}"
true true
end end
RUBY RUBY
end end
@ -278,8 +278,8 @@ ruby_version_is "2.7" do
it "matches a value and binds variable name to this value" do it "matches a value and binds variable name to this value" do
eval(<<~RUBY).should == 0 eval(<<~RUBY).should == 0
case 0 case 0
in a in a
a a
end end
RUBY RUBY
end end
@ -287,7 +287,7 @@ ruby_version_is "2.7" do
it "makes bounded variable visible outside a case statement scope" do it "makes bounded variable visible outside a case statement scope" do
eval(<<~RUBY).should == 0 eval(<<~RUBY).should == 0
case 0 case 0
in a in a
end end
a a
@ -297,9 +297,9 @@ ruby_version_is "2.7" do
it "create local variables even if a pattern doesn't match" do it "create local variables even if a pattern doesn't match" do
eval(<<~RUBY).should == [0, nil, nil] eval(<<~RUBY).should == [0, nil, nil]
case 0 case 0
in a in a
in b in b
in c in c
end end
[a, b, c] [a, b, c]
@ -309,8 +309,8 @@ ruby_version_is "2.7" do
it "allow using _ name to drop values" do it "allow using _ name to drop values" do
eval(<<~RUBY).should == 0 eval(<<~RUBY).should == 0
case [0, 1] case [0, 1]
in [a, _] in [a, _]
a a
end end
RUBY RUBY
end end
@ -318,8 +318,8 @@ ruby_version_is "2.7" do
it "supports using _ in a pattern several times" do it "supports using _ in a pattern several times" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case [0, 1, 2] case [0, 1, 2]
in [0, _, _] in [0, _, _]
true true
end end
RUBY RUBY
end end
@ -327,15 +327,15 @@ ruby_version_is "2.7" do
it "supports using any name with _ at the beginning in a pattern several times" do it "supports using any name with _ at the beginning in a pattern several times" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case [0, 1, 2] case [0, 1, 2]
in [0, _x, _x] in [0, _x, _x]
true true
end end
RUBY RUBY
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case {a: 0, b: 1, c: 2} case {a: 0, b: 1, c: 2}
in {a: 0, b: _x, c: _x} in {a: 0, b: _x, c: _x}
true true
end end
RUBY RUBY
end end
@ -344,7 +344,7 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~RUBY eval <<~RUBY
case [0] case [0]
in [a, a] in [a, a]
end end
RUBY RUBY
}.should raise_error(SyntaxError, /duplicated variable name/) }.should raise_error(SyntaxError, /duplicated variable name/)
@ -355,8 +355,8 @@ ruby_version_is "2.7" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case 0 case 0
in ^a in ^a
true true
end end
RUBY RUBY
end end
@ -364,15 +364,15 @@ ruby_version_is "2.7" do
it "allows applying ^ operator to bound variables" do it "allows applying ^ operator to bound variables" do
eval(<<~RUBY).should == 1 eval(<<~RUBY).should == 1
case [1, 1] case [1, 1]
in [n, ^n] in [n, ^n]
n n
end end
RUBY RUBY
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case [1, 2] case [1, 2]
in [n, ^n] in [n, ^n]
true true
else else
false false
end end
@ -383,8 +383,8 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~RUBY eval <<~RUBY
case [1, 2] case [1, 2]
in [^n, n] in [^n, n]
true true
else else
false false
end end
@ -397,8 +397,8 @@ ruby_version_is "2.7" do
it "matches if any of patterns matches" do it "matches if any of patterns matches" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case 0 case 0
in 0 | 1 | 2 in 0 | 1 | 2
true true
end end
RUBY RUBY
end end
@ -407,7 +407,7 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~RUBY eval <<~RUBY
case [0, 1] case [0, 1]
in [0, 0] | [0, a] in [0, 0] | [0, a]
end end
RUBY RUBY
}.should raise_error(SyntaxError, /illegal variable in alternative pattern/) }.should raise_error(SyntaxError, /illegal variable in alternative pattern/)
@ -416,10 +416,10 @@ ruby_version_is "2.7" do
it "support underscore prefixed variables in alternation" do it "support underscore prefixed variables in alternation" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case [0, 1] case [0, 1]
in [1, _] in [1, _]
false false
in [0, 0] | [0, _a] in [0, 0] | [0, _a]
true true
end end
RUBY RUBY
end end
@ -429,8 +429,8 @@ ruby_version_is "2.7" do
it "binds a variable to a value if pattern matches" do it "binds a variable to a value if pattern matches" do
eval(<<~RUBY).should == 0 eval(<<~RUBY).should == 0
case 0 case 0
in Integer => n in Integer => n
n n
end end
RUBY RUBY
end end
@ -438,8 +438,8 @@ ruby_version_is "2.7" do
it "can be used as a nested pattern" do it "can be used as a nested pattern" do
eval(<<~RUBY).should == [2, 3] eval(<<~RUBY).should == [2, 3]
case [1, [2, 3]] case [1, [2, 3]]
in [1, Array => ary] in [1, Array => ary]
ary ary
end end
RUBY RUBY
end end
@ -449,8 +449,8 @@ ruby_version_is "2.7" do
it "supports form Constant(pat, pat, ...)" do it "supports form Constant(pat, pat, ...)" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case [0, 1, 2] case [0, 1, 2]
in Array(0, 1, 2) in Array(0, 1, 2)
true true
end end
RUBY RUBY
end end
@ -458,8 +458,8 @@ ruby_version_is "2.7" do
it "supports form Constant[pat, pat, ...]" do it "supports form Constant[pat, pat, ...]" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case [0, 1, 2] case [0, 1, 2]
in Array[0, 1, 2] in Array[0, 1, 2]
true true
end end
RUBY RUBY
end end
@ -467,8 +467,8 @@ ruby_version_is "2.7" do
it "supports form [pat, pat, ...]" do it "supports form [pat, pat, ...]" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case [0, 1, 2] case [0, 1, 2]
in [0, 1, 2] in [0, 1, 2]
true true
end end
RUBY RUBY
end end
@ -476,22 +476,22 @@ ruby_version_is "2.7" do
it "supports form pat, pat, ..." do it "supports form pat, pat, ..." do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case [0, 1, 2] case [0, 1, 2]
in 0, 1, 2 in 0, 1, 2
true true
end end
RUBY RUBY
eval(<<~RUBY).should == 1 eval(<<~RUBY).should == 1
case [0, 1, 2] case [0, 1, 2]
in 0, a, 2 in 0, a, 2
a a
end end
RUBY RUBY
eval(<<~RUBY).should == [1, 2] eval(<<~RUBY).should == [1, 2]
case [0, 1, 2] case [0, 1, 2]
in 0, *rest in 0, *rest
rest rest
end end
RUBY RUBY
end end
@ -502,8 +502,8 @@ ruby_version_is "2.7" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case obj case obj
in [Integer, Integer] in [Integer, Integer]
true true
end end
RUBY RUBY
end end
@ -511,8 +511,8 @@ ruby_version_is "2.7" do
it "does not match object if Constant === object returns false" do it "does not match object if Constant === object returns false" do
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case [0, 1, 2] case [0, 1, 2]
in String[0, 1, 2] in String[0, 1, 2]
true true
else else
false false
end end
@ -524,8 +524,8 @@ ruby_version_is "2.7" do
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case obj case obj
in Object[] in Object[]
true true
else else
false false
end end
@ -539,7 +539,7 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~RUBY eval <<~RUBY
case obj case obj
in Object[] in Object[]
else else
end end
RUBY RUBY
@ -552,8 +552,8 @@ ruby_version_is "2.7" do
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case obj case obj
in Object[0] in Object[0]
true true
else else
false false
end end
@ -563,8 +563,8 @@ ruby_version_is "2.7" do
it "binds variables" do it "binds variables" do
eval(<<~RUBY).should == [0, 1, 2] eval(<<~RUBY).should == [0, 1, 2]
case [0, 1, 2] case [0, 1, 2]
in [a, b, c] in [a, b, c]
[a, b, c] [a, b, c]
end end
RUBY RUBY
end end
@ -572,8 +572,8 @@ ruby_version_is "2.7" do
it "supports splat operator *rest" do it "supports splat operator *rest" do
eval(<<~RUBY).should == [1, 2] eval(<<~RUBY).should == [1, 2]
case [0, 1, 2] case [0, 1, 2]
in [0, *rest] in [0, *rest]
rest rest
end end
RUBY RUBY
end end
@ -581,8 +581,8 @@ ruby_version_is "2.7" do
it "does not match partially by default" do it "does not match partially by default" do
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case [0, 1, 2, 3] case [0, 1, 2, 3]
in [1, 2] in [1, 2]
true true
else else
false false
end end
@ -592,15 +592,15 @@ ruby_version_is "2.7" do
it "does match partially from the array beginning if list + , syntax used" do it "does match partially from the array beginning if list + , syntax used" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case [0, 1, 2, 3] case [0, 1, 2, 3]
in [0, 1,] in [0, 1,]
true true
end end
RUBY RUBY
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case [0, 1, 2, 3] case [0, 1, 2, 3]
in 0, 1,; in 0, 1,;
true true
end end
RUBY RUBY
end end
@ -608,8 +608,8 @@ ruby_version_is "2.7" do
it "matches [] with []" do it "matches [] with []" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case [] case []
in [] in []
true true
end end
RUBY RUBY
end end
@ -617,8 +617,8 @@ ruby_version_is "2.7" do
it "matches anything with *" do it "matches anything with *" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case [0, 1] case [0, 1]
in *; in *;
true true
end end
RUBY RUBY
end end
@ -628,8 +628,8 @@ ruby_version_is "2.7" do
it "supports form Constant(id: pat, id: pat, ...)" do it "supports form Constant(id: pat, id: pat, ...)" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case {a: 0, b: 1} case {a: 0, b: 1}
in Hash(a: 0, b: 1) in Hash(a: 0, b: 1)
true true
end end
RUBY RUBY
end end
@ -637,8 +637,8 @@ ruby_version_is "2.7" do
it "supports form Constant[id: pat, id: pat, ...]" do it "supports form Constant[id: pat, id: pat, ...]" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case {a: 0, b: 1} case {a: 0, b: 1}
in Hash[a: 0, b: 1] in Hash[a: 0, b: 1]
true true
end end
RUBY RUBY
end end
@ -646,8 +646,8 @@ ruby_version_is "2.7" do
it "supports form {id: pat, id: pat, ...}" do it "supports form {id: pat, id: pat, ...}" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case {a: 0, b: 1} case {a: 0, b: 1}
in {a: 0, b: 1} in {a: 0, b: 1}
true true
end end
RUBY RUBY
end end
@ -655,22 +655,22 @@ ruby_version_is "2.7" do
it "supports form id: pat, id: pat, ..." do it "supports form id: pat, id: pat, ..." do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case {a: 0, b: 1} case {a: 0, b: 1}
in a: 0, b: 1 in a: 0, b: 1
true true
end end
RUBY RUBY
eval(<<~RUBY).should == [0, 1] eval(<<~RUBY).should == [0, 1]
case {a: 0, b: 1} case {a: 0, b: 1}
in a: a, b: b in a: a, b: b
[a, b] [a, b]
end end
RUBY RUBY
eval(<<~RUBY).should == { b: 1, c: 2 } eval(<<~RUBY).should == { b: 1, c: 2 }
case {a: 0, b: 1, c: 2} case {a: 0, b: 1, c: 2}
in a: 0, **rest in a: 0, **rest
rest rest
end end
RUBY RUBY
end end
@ -678,40 +678,40 @@ ruby_version_is "2.7" do
it "supports a: which means a: a" do it "supports a: which means a: a" do
eval(<<~RUBY).should == [0, 1] eval(<<~RUBY).should == [0, 1]
case {a: 0, b: 1} case {a: 0, b: 1}
in Hash(a:, b:) in Hash(a:, b:)
[a, b] [a, b]
end end
RUBY RUBY
a = b = nil a = b = nil
eval(<<~RUBY).should == [0, 1] eval(<<~RUBY).should == [0, 1]
case {a: 0, b: 1} case {a: 0, b: 1}
in Hash[a:, b:] in Hash[a:, b:]
[a, b] [a, b]
end end
RUBY RUBY
a = b = nil a = b = nil
eval(<<~RUBY).should == [0, 1] eval(<<~RUBY).should == [0, 1]
case {a: 0, b: 1} case {a: 0, b: 1}
in {a:, b:} in {a:, b:}
[a, b] [a, b]
end end
RUBY RUBY
a = nil a = nil
eval(<<~RUBY).should == [0, {b: 1, c: 2}] eval(<<~RUBY).should == [0, {b: 1, c: 2}]
case {a: 0, b: 1, c: 2} case {a: 0, b: 1, c: 2}
in {a:, **rest} in {a:, **rest}
[a, rest] [a, rest]
end end
RUBY RUBY
a = b = nil a = b = nil
eval(<<~RUBY).should == [0, 1] eval(<<~RUBY).should == [0, 1]
case {a: 0, b: 1} case {a: 0, b: 1}
in a:, b: in a:, b:
[a, b] [a, b]
end end
RUBY RUBY
end end
@ -719,8 +719,8 @@ ruby_version_is "2.7" do
it "can mix key (a:) and key-value (a: b) declarations" do it "can mix key (a:) and key-value (a: b) declarations" do
eval(<<~RUBY).should == [0, 1] eval(<<~RUBY).should == [0, 1]
case {a: 0, b: 1} case {a: 0, b: 1}
in Hash(a:, b: x) in Hash(a:, b: x)
[a, x] [a, x]
end end
RUBY RUBY
end end
@ -728,8 +728,8 @@ ruby_version_is "2.7" do
it "supports 'string': key literal" do it "supports 'string': key literal" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case {a: 0} case {a: 0}
in {"a": 0} in {"a": 0}
true true
end end
RUBY RUBY
end end
@ -738,7 +738,7 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~RUBY eval <<~RUBY
case {a: 1} case {a: 1}
in {"a" => 1} in {"a" => 1}
end end
RUBY RUBY
}.should raise_error(SyntaxError, /unexpected/) }.should raise_error(SyntaxError, /unexpected/)
@ -750,7 +750,7 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~'RUBY' eval <<~'RUBY'
case {a: 1} case {a: 1}
in {"#{x}": 1} in {"#{x}": 1}
end end
RUBY RUBY
}.should raise_error(SyntaxError, /symbol literal with interpolation is not allowed/) }.should raise_error(SyntaxError, /symbol literal with interpolation is not allowed/)
@ -760,7 +760,7 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~RUBY eval <<~RUBY
case {a: 1} case {a: 1}
in {a: 1, b: 2, a: 3} in {a: 1, b: 2, a: 3}
end end
RUBY RUBY
}.should raise_error(SyntaxError, /duplicated key name/) }.should raise_error(SyntaxError, /duplicated key name/)
@ -772,8 +772,8 @@ ruby_version_is "2.7" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case obj case obj
in {a: 1} in {a: 1}
true true
end end
RUBY RUBY
end end
@ -781,8 +781,8 @@ ruby_version_is "2.7" do
it "does not match object if Constant === object returns false" do it "does not match object if Constant === object returns false" do
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case {a: 1} case {a: 1}
in String[a: 1] in String[a: 1]
true true
else else
false false
end end
@ -794,8 +794,8 @@ ruby_version_is "2.7" do
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case obj case obj
in Object[a: 1] in Object[a: 1]
true true
else else
false false
end end
@ -809,7 +809,7 @@ ruby_version_is "2.7" do
-> { -> {
eval <<~RUBY eval <<~RUBY
case obj case obj
in Object[a: 1] in Object[a: 1]
end end
RUBY RUBY
}.should raise_error(TypeError, /deconstruct_keys must return Hash/) }.should raise_error(TypeError, /deconstruct_keys must return Hash/)
@ -821,8 +821,8 @@ ruby_version_is "2.7" do
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case obj case obj
in Object[a: 1] in Object[a: 1]
true true
else else
false false
end end
@ -835,8 +835,8 @@ ruby_version_is "2.7" do
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case obj case obj
in Object[a: 2] in Object[a: 2]
true true
else else
false false
end end
@ -853,7 +853,7 @@ ruby_version_is "2.7" do
eval <<~RUBY eval <<~RUBY
case obj case obj
in Object[a: 1, b: 2, c: 3] in Object[a: 1, b: 2, c: 3]
end end
RUBY RUBY
@ -870,7 +870,7 @@ ruby_version_is "2.7" do
eval <<~RUBY eval <<~RUBY
case obj case obj
in Object[a: 1, b: 2, **] in Object[a: 1, b: 2, **]
end end
RUBY RUBY
@ -887,7 +887,7 @@ ruby_version_is "2.7" do
eval <<~RUBY eval <<~RUBY
case obj case obj
in Object[a: 1, **rest] in Object[a: 1, **rest]
end end
RUBY RUBY
@ -897,8 +897,8 @@ ruby_version_is "2.7" do
it "binds variables" do it "binds variables" do
eval(<<~RUBY).should == [0, 1, 2] eval(<<~RUBY).should == [0, 1, 2]
case {a: 0, b: 1, c: 2} case {a: 0, b: 1, c: 2}
in {a: x, b: y, c: z} in {a: x, b: y, c: z}
[x, y, z] [x, y, z]
end end
RUBY RUBY
end end
@ -906,8 +906,8 @@ ruby_version_is "2.7" do
it "supports double splat operator **rest" do it "supports double splat operator **rest" do
eval(<<~RUBY).should == {b: 1, c: 2} eval(<<~RUBY).should == {b: 1, c: 2}
case {a: 0, b: 1, c: 2} case {a: 0, b: 1, c: 2}
in {a: 0, **rest} in {a: 0, **rest}
rest rest
end end
RUBY RUBY
end end
@ -915,15 +915,15 @@ ruby_version_is "2.7" do
it "treats **nil like there should not be any other keys in a matched Hash" do it "treats **nil like there should not be any other keys in a matched Hash" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case {a: 1, b: 2} case {a: 1, b: 2}
in {a: 1, b: 2, **nil} in {a: 1, b: 2, **nil}
true true
end end
RUBY RUBY
eval(<<~RUBY).should == false eval(<<~RUBY).should == false
case {a: 1, b: 2} case {a: 1, b: 2}
in {a: 1, **nil} in {a: 1, **nil}
true true
else else
false false
end end
@ -933,8 +933,8 @@ ruby_version_is "2.7" do
it "can match partially" do it "can match partially" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case {a: 1, b: 2} case {a: 1, b: 2}
in {a: 1} in {a: 1}
true true
end end
RUBY RUBY
end end
@ -942,8 +942,8 @@ ruby_version_is "2.7" do
it "matches {} with {}" do it "matches {} with {}" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case {} case {}
in {} in {}
true true
end end
RUBY RUBY
end end
@ -951,8 +951,8 @@ ruby_version_is "2.7" do
it "matches anything with **" do it "matches anything with **" do
eval(<<~RUBY).should == true eval(<<~RUBY).should == true
case {a: 1} case {a: 1}
in **; in **;
true true
end end
RUBY RUBY
end end
@ -974,8 +974,8 @@ ruby_version_is "2.7" do
result = eval(<<~RUBY) result = eval(<<~RUBY)
case [] case []
in [0] in [0]
true true
end end
RUBY RUBY
end end
@ -998,8 +998,8 @@ ruby_version_is "2.7" do
result = eval(<<~RUBY) result = eval(<<~RUBY)
case {} case {}
in a: 0 in a: 0
true true
end end
RUBY RUBY
end end
@ -1022,8 +1022,8 @@ ruby_version_is "2.7" do
result = eval(<<~RUBY) result = eval(<<~RUBY)
case {} case {}
in Array in Array
true true
end end
RUBY RUBY
end end