summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/shared/slice.rb
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2023-01-05 19:05:29 +0100
committerBenoit Daloze <eregontp@gmail.com>2023-01-05 19:05:29 +0100
commitbbf54ec334fe2edd7669a944d88d17efde49a412 (patch)
tree2941c7b711319b295aa3664b6a2b984e70a523b7 /spec/ruby/core/string/shared/slice.rb
parentcd5e6cc0ea48353c88d921b885b552dc76da255c (diff)
Update to ruby/spec@9d69b95
Diffstat (limited to 'spec/ruby/core/string/shared/slice.rb')
-rw-r--r--spec/ruby/core/string/shared/slice.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/spec/ruby/core/string/shared/slice.rb b/spec/ruby/core/string/shared/slice.rb
index 713234fffd..a7c1d05b56 100644
--- a/spec/ruby/core/string/shared/slice.rb
+++ b/spec/ruby/core/string/shared/slice.rb
@@ -80,7 +80,7 @@ describe :string_slice_index_length, shared: true do
"hello there".send(@method, -3,2).should == "er"
end
- it "returns a string with the same encoding" do
+ it "returns a string with the same encoding as self" do
s = "hello there"
s.send(@method, 1, 9).encoding.should == s.encoding
@@ -206,6 +206,10 @@ describe :string_slice_range, shared: true do
"x".send(@method, 1..-1).should == ""
end
+ it "returns a String in the same encoding as self" do
+ "hello there".encode("US-ASCII").send(@method, 1..1).encoding.should == Encoding::US_ASCII
+ end
+
it "returns nil if the beginning of the range falls outside of self" do
"hello there".send(@method, 12..-1).should == nil
"hello there".send(@method, 20..25).should == nil
@@ -328,7 +332,8 @@ describe :string_slice_regexp, shared: true do
"hello there".send(@method, /xyz/).should == nil
end
- not_supported_on :opal do
+ it "returns a String in the same encoding as self" do
+ "hello there".encode("US-ASCII").send(@method, /[aeiou](.)\1/).encoding.should == Encoding::US_ASCII
end
ruby_version_is ''...'3.0' do
@@ -391,6 +396,10 @@ describe :string_slice_regexp_index, shared: true do
$~[1].should == nil
end
+ it "returns a String in the same encoding as self" do
+ "hello there".encode("US-ASCII").send(@method, /[aeiou](.)\1/, 0).encoding.should == Encoding::US_ASCII
+ end
+
it "calls to_int on the given index" do
obj = mock('2')
obj.should_receive(:to_int).and_return(2)