Skip to content

Commit 12c704a

Browse files
palkaneregon
authored andcommitted
Add specs for pinning vars/exprs
1 parent 7f22a0b commit 12c704a

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

language/pattern_matching_spec.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,65 @@ def ===(obj)
12971297
a
12981298
RUBY
12991299
end
1300+
1301+
it "supports pinning instance variables" do
1302+
eval(<<~RUBY).should == true
1303+
@a = /a/
1304+
case 'abc'
1305+
in ^@a
1306+
true
1307+
end
1308+
RUBY
1309+
end
1310+
1311+
it "supports pinning class variables" do
1312+
result = nil
1313+
Module.new do
1314+
result = module_eval(<<~RUBY)
1315+
@@a = 0..10
1316+
1317+
case 2
1318+
in ^@@a
1319+
true
1320+
end
1321+
RUBY
1322+
end
1323+
1324+
result.should == true
1325+
end
1326+
1327+
it "supports pinning global variables" do
1328+
eval(<<~RUBY).should == true
1329+
$a = /a/
1330+
case 'abc'
1331+
in ^$a
1332+
true
1333+
end
1334+
RUBY
1335+
end
1336+
1337+
it "supports pinning expressions" do
1338+
eval(<<~RUBY).should == true
1339+
case 'abc'
1340+
in ^(/a/)
1341+
true
1342+
end
1343+
RUBY
1344+
1345+
eval(<<~RUBY).should == true
1346+
case {name: '2.6', released_at: Time.new(2018, 12, 25)}
1347+
in {released_at: ^(Time.new(2010)..Time.new(2020))}
1348+
true
1349+
end
1350+
RUBY
1351+
1352+
eval(<<~RUBY).should == true
1353+
case 0
1354+
in ^(0+0)
1355+
true
1356+
end
1357+
RUBY
1358+
end
13001359
end
13011360
end
13021361
end

0 commit comments

Comments
 (0)