diff options
Diffstat (limited to 'spec/ruby/optional/capi/regexp_spec.rb')
-rw-r--r-- | spec/ruby/optional/capi/regexp_spec.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/ruby/optional/capi/regexp_spec.rb b/spec/ruby/optional/capi/regexp_spec.rb index 806157368d..81844e2a6e 100644 --- a/spec/ruby/optional/capi/regexp_spec.rb +++ b/spec/ruby/optional/capi/regexp_spec.rb @@ -80,4 +80,33 @@ describe "C-API Regexp function" do @p.rb_reg_match_backref_get(/a/, 'ab')[0].should == 'a' end end + + describe "rb_backref_set" do + before :each do + @md = "foo".match(/foo/) + $~ = nil + end + + it "sets the value of $~" do + @p.rb_backref_set(@md) + @p.rb_backref_get.should == @md + $~.should == @md + end + + it "sets a Thread-local value" do + running = false + + thr = Thread.new do + @p.rb_backref_set(@md) + @p.rb_backref_get.should == @md + $~.should == @md + running = true + end + + Thread.pass while thr.status and !running + $~.should be_nil + + thr.join + end + end end |