diff options
Diffstat (limited to 'spec/ruby/core/string/delete_prefix_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/delete_prefix_spec.rb | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/spec/ruby/core/string/delete_prefix_spec.rb b/spec/ruby/core/string/delete_prefix_spec.rb index 92c301b44a..fc69adcbad 100644 --- a/spec/ruby/core/string/delete_prefix_spec.rb +++ b/spec/ruby/core/string/delete_prefix_spec.rb @@ -1,83 +1,83 @@ # -*- encoding: utf-8 -*- +# frozen_string_literal: false require_relative '../../spec_helper' require_relative 'fixtures/classes' -ruby_version_is '2.5' do - describe "String#delete_prefix" do - it "returns a copy of the string, with the given prefix removed" do - 'hello'.delete_prefix('hell').should == 'o' - 'hello'.delete_prefix('hello').should == '' - end +describe "String#delete_prefix" do + it "returns a copy of the string, with the given prefix removed" do + 'hello'.delete_prefix('hell').should == 'o' + 'hello'.delete_prefix('hello').should == '' + end + + it "returns a copy of the string, when the prefix isn't found" do + s = 'hello' + r = s.delete_prefix('hello!') + r.should_not.equal? s + r.should == s + r = s.delete_prefix('ell') + r.should_not.equal? s + r.should == s + r = s.delete_prefix('') + r.should_not.equal? s + r.should == s + end - it "returns a copy of the string, when the prefix isn't found" do - s = 'hello' - r = s.delete_prefix('hello!') - r.should_not equal s - r.should == s - r = s.delete_prefix('ell') - r.should_not equal s - r.should == s - r = s.delete_prefix('') - r.should_not equal s - r.should == s - end + it "does not remove partial bytes, only full characters" do + "\xe3\x81\x82".delete_prefix("\xe3").should == "\xe3\x81\x82" + end - ruby_version_is ''...'2.7' do - it "taints resulting strings when other is tainted" do - 'hello'.taint.delete_prefix('hell').tainted?.should == true - 'hello'.taint.delete_prefix('').tainted?.should == true - end - end + it "doesn't set $~" do + $~ = nil - it "doesn't set $~" do - $~ = nil + 'hello'.delete_prefix('hell') + $~.should == nil + end - 'hello'.delete_prefix('hell') - $~.should == nil - end + it "calls to_str on its argument" do + o = mock('x') + o.should_receive(:to_str).and_return 'hell' + 'hello'.delete_prefix(o).should == 'o' + end - it "calls to_str on its argument" do - o = mock('x') - o.should_receive(:to_str).and_return 'hell' - 'hello'.delete_prefix(o).should == 'o' - end + it "returns a String instance when called on a subclass instance" do + s = StringSpecs::MyString.new('hello') + s.delete_prefix('hell').should.instance_of?(String) + end - it "returns a subclass instance when called on a subclass instance" do - s = StringSpecs::MyString.new('hello') - s.delete_prefix('hell').should be_an_instance_of(StringSpecs::MyString) - end + it "returns a String in the same encoding as self" do + 'hello'.encode("US-ASCII").delete_prefix('hell').encoding.should == Encoding::US_ASCII end +end - describe "String#delete_prefix!" do - it "removes the found prefix" do - s = 'hello' - s.delete_prefix!('hell').should equal(s) - s.should == 'o' - end +describe "String#delete_prefix!" do + it "removes the found prefix" do + s = 'hello' + s.delete_prefix!('hell').should.equal?(s) + s.should == 'o' + end - it "returns nil if no change is made" do - s = 'hello' - s.delete_prefix!('ell').should == nil - s.delete_prefix!('').should == nil - end + it "returns nil if no change is made" do + s = 'hello' + s.delete_prefix!('ell').should == nil + s.delete_prefix!('').should == nil + end - it "doesn't set $~" do - $~ = nil + it "doesn't set $~" do + $~ = nil - 'hello'.delete_prefix!('hell') - $~.should == nil - end + 'hello'.delete_prefix!('hell') + $~.should == nil + end - it "calls to_str on its argument" do - o = mock('x') - o.should_receive(:to_str).and_return 'hell' - 'hello'.delete_prefix!(o).should == 'o' - end + it "calls to_str on its argument" do + o = mock('x') + o.should_receive(:to_str).and_return 'hell' + 'hello'.delete_prefix!(o).should == 'o' + end - it "raises a #{frozen_error_class} when self is frozen" do - -> { 'hello'.freeze.delete_prefix!('hell') }.should raise_error(frozen_error_class) - -> { 'hello'.freeze.delete_prefix!('') }.should raise_error(frozen_error_class) - -> { ''.freeze.delete_prefix!('') }.should raise_error(frozen_error_class) - end + it "raises a FrozenError when self is frozen" do + -> { 'hello'.freeze.delete_prefix!('hell') }.should.raise(FrozenError) + -> { 'hello'.freeze.delete_prefix!('') }.should.raise(FrozenError) + -> { ''.freeze.delete_prefix!('') }.should.raise(FrozenError) end end |
