diff options
Diffstat (limited to 'spec/ruby/core/string')
| -rw-r--r-- | spec/ruby/core/string/byteindex_spec.rb | 16 | ||||
| -rw-r--r-- | spec/ruby/core/string/index_spec.rb | 11 | ||||
| -rw-r--r-- | spec/ruby/core/string/rindex_spec.rb | 9 |
3 files changed, 36 insertions, 0 deletions
diff --git a/spec/ruby/core/string/byteindex_spec.rb b/spec/ruby/core/string/byteindex_spec.rb new file mode 100644 index 0000000000..af70c729e8 --- /dev/null +++ b/spec/ruby/core/string/byteindex_spec.rb @@ -0,0 +1,16 @@ +# -*- encoding: utf-8 -*- +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +describe "String#byteindex with Regexp" do + ruby_version_is "3.2" do + it "always clear $~" do + "a".byteindex(/a/) + $~.should_not == nil + + string = "blablabla" + string.byteindex(/bla/, string.bytesize + 1) + $~.should == nil + end + end +end diff --git a/spec/ruby/core/string/index_spec.rb b/spec/ruby/core/string/index_spec.rb index 2eeee9be87..93153e65f0 100644 --- a/spec/ruby/core/string/index_spec.rb +++ b/spec/ruby/core/string/index_spec.rb @@ -224,6 +224,17 @@ describe "String#index with Regexp" do $~.should == nil end + ruby_bug "#20421", ""..."3.2" do + it "always clear $~" do + "a".index(/a/) + $~.should_not == nil + + string = "blablabla" + string.index(/bla/, string.length + 1) + $~.should == nil + end + end + it "starts the search at the given offset" do "blablabla".index(/.{0}/, 5).should == 5 "blablabla".index(/.{1}/, 5).should == 5 diff --git a/spec/ruby/core/string/rindex_spec.rb b/spec/ruby/core/string/rindex_spec.rb index e795105e1d..cd2aabba34 100644 --- a/spec/ruby/core/string/rindex_spec.rb +++ b/spec/ruby/core/string/rindex_spec.rb @@ -265,6 +265,15 @@ describe "String#rindex with Regexp" do $~.should == nil end + it "always clear $~" do + "a".rindex(/a/) + $~.should_not == nil + + string = "blablabla" + string.rindex(/bla/, -(string.length + 1)) + $~.should == nil + end + it "starts the search at the given offset" do "blablabla".rindex(/.{0}/, 5).should == 5 "blablabla".rindex(/.{1}/, 5).should == 5 |
