1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59432 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-07-27 12:10:41 +00:00
parent 819977e410
commit 0cb5fa5877
21 changed files with 329 additions and 461 deletions

View file

@ -29,6 +29,10 @@ describe :string_slice, shared: true do
lambda { "hello".send(@method, {}) }.should raise_error(TypeError)
lambda { "hello".send(@method, []) }.should raise_error(TypeError)
end
it "raises a RangeError if the index is too big" do
lambda { "hello".send(@method, bignum_value) }.should raise_error(RangeError)
end
end
describe :string_slice_index_length, shared: true do
@ -85,6 +89,21 @@ describe :string_slice_index_length, shared: true do
str.send(@method, 2,1).tainted?.should == true
end
it "returns a string with the same encoding" do
s = "hello there"
s.send(@method, 1, 9).encoding.should == s.encoding
a = "hello".force_encoding("binary")
b = " there".force_encoding("ISO-8859-1")
c = (a + b).force_encoding(Encoding::US_ASCII)
c.send(@method, 0, 5).encoding.should == Encoding::US_ASCII
c.send(@method, 5, 6).encoding.should == Encoding::US_ASCII
c.send(@method, 1, 3).encoding.should == Encoding::US_ASCII
c.send(@method, 8, 2).encoding.should == Encoding::US_ASCII
c.send(@method, 1, 10).encoding.should == Encoding::US_ASCII
end
it "returns nil if the offset falls outside of self" do
"hello there".send(@method, 20,3).should == nil
"hello there".send(@method, -20,3).should == nil
@ -135,6 +154,11 @@ describe :string_slice_index_length, shared: true do
lambda { "hello".send(@method, nil, nil) }.should raise_error(TypeError)
end
it "raises a RangeError if the index or length is too big" do
lambda { "hello".send(@method, bignum_value, 1) }.should raise_error(RangeError)
lambda { "hello".send(@method, 0, bignum_value) }.should raise_error(RangeError)
end
it "returns subclass instances" do
s = StringSpecs::MyString.new("hello")
s.send(@method, 0,0).should be_an_instance_of(StringSpecs::MyString)