summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/regexp_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/optional/capi/regexp_spec.rb')
-rw-r--r--spec/ruby/optional/capi/regexp_spec.rb47
1 files changed, 46 insertions, 1 deletions
diff --git a/spec/ruby/optional/capi/regexp_spec.rb b/spec/ruby/optional/capi/regexp_spec.rb
index 806157368d..f233b5e3b3 100644
--- a/spec/ruby/optional/capi/regexp_spec.rb
+++ b/spec/ruby/optional/capi/regexp_spec.rb
@@ -77,7 +77,52 @@ describe "C-API Regexp function" do
end
it "returns MatchData when used with rb_reg_match" do
- @p.rb_reg_match_backref_get(/a/, 'ab')[0].should == 'a'
+ @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 == nil
+
+ thr.join
+ end
+ end
+
+ describe "rb_memcicmp" do
+ it "returns 0 for identical strings" do
+ @p.rb_memcicmp('Hello', 'Hello').should == 0
+ end
+
+ it "returns 0 for strings which only differ in case" do
+ @p.rb_memcicmp('Hello', 'HELLO').should == 0
+ @p.rb_memcicmp('HELLO', 'Hello').should == 0
+ end
+
+ it "returns the difference between the first non matching characters" do
+ @p.rb_memcicmp('Hello', 'HELLP').should == -1
+ @p.rb_memcicmp('HELLp', 'Hello').should == 1
end
end
end