diff options
Diffstat (limited to 'spec/ruby/core/string/slice_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/slice_spec.rb | 137 |
1 files changed, 43 insertions, 94 deletions
diff --git a/spec/ruby/core/string/slice_spec.rb b/spec/ruby/core/string/slice_spec.rb index c9e13ed1bc..14e2251b3f 100644 --- a/spec/ruby/core/string/slice_spec.rb +++ b/spec/ruby/core/string/slice_spec.rb @@ -1,5 +1,5 @@ # -*- encoding: utf-8 -*- - +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/slice' @@ -54,9 +54,9 @@ describe "String#slice! with index" do end it "raises a FrozenError if self is frozen" do - -> { "hello".freeze.slice!(1) }.should raise_error(FrozenError) - -> { "hello".freeze.slice!(10) }.should raise_error(FrozenError) - -> { "".freeze.slice!(0) }.should raise_error(FrozenError) + -> { "hello".freeze.slice!(1) }.should.raise(FrozenError) + -> { "hello".freeze.slice!(10) }.should.raise(FrozenError) + -> { "".freeze.slice!(0) }.should.raise(FrozenError) end it "calls to_int on index" do @@ -110,13 +110,13 @@ describe "String#slice! with index, length" do end it "raises a FrozenError if self is frozen" do - -> { "hello".freeze.slice!(1, 2) }.should raise_error(FrozenError) - -> { "hello".freeze.slice!(10, 3) }.should raise_error(FrozenError) - -> { "hello".freeze.slice!(-10, 3)}.should raise_error(FrozenError) - -> { "hello".freeze.slice!(4, -3) }.should raise_error(FrozenError) - -> { "hello".freeze.slice!(10, 3) }.should raise_error(FrozenError) - -> { "hello".freeze.slice!(-10, 3)}.should raise_error(FrozenError) - -> { "hello".freeze.slice!(4, -3) }.should raise_error(FrozenError) + -> { "hello".freeze.slice!(1, 2) }.should.raise(FrozenError) + -> { "hello".freeze.slice!(10, 3) }.should.raise(FrozenError) + -> { "hello".freeze.slice!(-10, 3)}.should.raise(FrozenError) + -> { "hello".freeze.slice!(4, -3) }.should.raise(FrozenError) + -> { "hello".freeze.slice!(10, 3) }.should.raise(FrozenError) + -> { "hello".freeze.slice!(-10, 3)}.should.raise(FrozenError) + -> { "hello".freeze.slice!(4, -3) }.should.raise(FrozenError) end it "calls to_int on idx and length" do @@ -132,20 +132,10 @@ describe "String#slice! with index, length" do "hello".slice!(obj, obj).should == "ll" end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(0, 0).should be_an_instance_of(StringSpecs::MyString) - s.slice!(0, 4).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(0, 0).should be_an_instance_of(String) - s.slice!(0, 4).should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.slice!(0, 0).should.instance_of?(String) + s.slice!(0, 4).should.instance_of?(String) end it "returns the substring given by the character offsets" do @@ -185,20 +175,10 @@ describe "String#slice! Range" do b.should == "hello" end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(0...0).should be_an_instance_of(StringSpecs::MyString) - s.slice!(0..4).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(0...0).should be_an_instance_of(String) - s.slice!(0..4).should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.slice!(0...0).should.instance_of?(String) + s.slice!(0..4).should.instance_of?(String) end it "calls to_int on range arguments" do @@ -248,12 +228,12 @@ describe "String#slice! Range" do it "raises a FrozenError on a frozen instance that is modified" do - -> { "hello".freeze.slice!(1..3) }.should raise_error(FrozenError) + -> { "hello".freeze.slice!(1..3) }.should.raise(FrozenError) end # see redmine #1551 it "raises a FrozenError on a frozen instance that would not be modified" do - -> { "hello".freeze.slice!(10..20)}.should raise_error(FrozenError) + -> { "hello".freeze.slice!(10..20)}.should.raise(FrozenError) end end @@ -274,20 +254,10 @@ describe "String#slice! with Regexp" do s.should == "this is a string" end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(//).should be_an_instance_of(StringSpecs::MyString) - s.slice!(/../).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(//).should be_an_instance_of(String) - s.slice!(/../).should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.slice!(//).should.instance_of?(String) + s.slice!(/../).should.instance_of?(String) end it "returns the matching portion of self with a multi byte character" do @@ -304,11 +274,11 @@ describe "String#slice! with Regexp" do end it "raises a FrozenError on a frozen instance that is modified" do - -> { "this is a string".freeze.slice!(/s.*t/) }.should raise_error(FrozenError) + -> { "this is a string".freeze.slice!(/s.*t/) }.should.raise(FrozenError) end it "raises a FrozenError on a frozen instance that would not be modified" do - -> { "this is a string".freeze.slice!(/zzz/) }.should raise_error(FrozenError) + -> { "this is a string".freeze.slice!(/zzz/) }.should.raise(FrozenError) end end @@ -344,20 +314,10 @@ describe "String#slice! with Regexp, index" do "har".slice!(/(.)(.)(.)/, obj).should == "a" end - ruby_version_is ''...'3.0' do - it "returns subclass instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(/(.)(.)/, 0).should be_an_instance_of(StringSpecs::MyString) - s.slice!(/(.)(.)/, 1).should be_an_instance_of(StringSpecs::MyString) - end - end - - ruby_version_is '3.0' do - it "returns String instances" do - s = StringSpecs::MyString.new("hello") - s.slice!(/(.)(.)/, 0).should be_an_instance_of(String) - s.slice!(/(.)(.)/, 1).should be_an_instance_of(String) - end + it "returns String instances" do + s = StringSpecs::MyString.new("hello") + s.slice!(/(.)(.)/, 0).should.instance_of?(String) + s.slice!(/(.)(.)/, 1).should.instance_of?(String) end it "returns the encoding aware capture for the given index" do @@ -382,9 +342,9 @@ describe "String#slice! with Regexp, index" do end it "raises a FrozenError if self is frozen" do - -> { "this is a string".freeze.slice!(/s.*t/) }.should raise_error(FrozenError) - -> { "this is a string".freeze.slice!(/zzz/, 0)}.should raise_error(FrozenError) - -> { "this is a string".freeze.slice!(/(.)/, 2)}.should raise_error(FrozenError) + -> { "this is a string".freeze.slice!(/s.*t/) }.should.raise(FrozenError) + -> { "this is a string".freeze.slice!(/zzz/, 0)}.should.raise(FrozenError) + -> { "this is a string".freeze.slice!(/(.)/, 2)}.should.raise(FrozenError) end end @@ -412,30 +372,19 @@ describe "String#slice! with String" do o = mock('x') o.should_not_receive(:to_str) - -> { "hello".slice!(o) }.should raise_error(TypeError) - end - - ruby_version_is ''...'3.0' do - it "returns a subclass instance when given a subclass instance" do - s = StringSpecs::MyString.new("el") - r = "hello".slice!(s) - r.should == "el" - r.should be_an_instance_of(StringSpecs::MyString) - end + -> { "hello".slice!(o) }.should.raise(TypeError) end - ruby_version_is '3.0' do - it "returns a subclass instance when given a subclass instance" do - s = StringSpecs::MyString.new("el") - r = "hello".slice!(s) - r.should == "el" - r.should be_an_instance_of(String) - end + it "returns a subclass instance when given a subclass instance" do + s = StringSpecs::MyString.new("el") + r = "hello".slice!(s) + r.should == "el" + r.should.instance_of?(String) end it "raises a FrozenError if self is frozen" do - -> { "hello hello".freeze.slice!('llo') }.should raise_error(FrozenError) - -> { "this is a string".freeze.slice!('zzz')}.should raise_error(FrozenError) - -> { "this is a string".freeze.slice!('zzz')}.should raise_error(FrozenError) + -> { "hello hello".freeze.slice!('llo') }.should.raise(FrozenError) + -> { "this is a string".freeze.slice!('zzz')}.should.raise(FrozenError) + -> { "this is a string".freeze.slice!('zzz')}.should.raise(FrozenError) end end |
