From 4053e8ba0d39b688440fedee2ab3fffabcd64312 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 10 Jan 2022 16:29:54 +0100 Subject: Update to ruby/spec@226cfdc --- spec/ruby/language/pattern_matching_spec.rb | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'spec/ruby/language/pattern_matching_spec.rb') diff --git a/spec/ruby/language/pattern_matching_spec.rb b/spec/ruby/language/pattern_matching_spec.rb index e4abae9412..5f5e2f4902 100644 --- a/spec/ruby/language/pattern_matching_spec.rb +++ b/spec/ruby/language/pattern_matching_spec.rb @@ -1297,6 +1297,65 @@ ruby_version_is "2.7" do a RUBY end + + it "supports pinning instance variables" do + eval(<<~RUBY).should == true + @a = /a/ + case 'abc' + in ^@a + true + end + RUBY + end + + it "supports pinning class variables" do + result = nil + Module.new do + result = module_eval(<<~RUBY) + @@a = 0..10 + + case 2 + in ^@@a + true + end + RUBY + end + + result.should == true + end + + it "supports pinning global variables" do + eval(<<~RUBY).should == true + $a = /a/ + case 'abc' + in ^$a + true + end + RUBY + end + + it "supports pinning expressions" do + eval(<<~RUBY).should == true + case 'abc' + in ^(/a/) + true + end + RUBY + + eval(<<~RUBY).should == true + case {name: '2.6', released_at: Time.new(2018, 12, 25)} + in {released_at: ^(Time.new(2010)..Time.new(2020))} + true + end + RUBY + + eval(<<~RUBY).should == true + case 0 + in ^(0+0) + true + end + RUBY + end end end end -- cgit v1.2.3