summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/element_set_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string/element_set_spec.rb')
-rw-r--r--spec/ruby/core/string/element_set_spec.rb45
1 files changed, 14 insertions, 31 deletions
diff --git a/spec/ruby/core/string/element_set_spec.rb b/spec/ruby/core/string/element_set_spec.rb
index 641d46bc91..e7599f832c 100644
--- a/spec/ruby/core/string/element_set_spec.rb
+++ b/spec/ruby/core/string/element_set_spec.rb
@@ -1,11 +1,12 @@
# -*- encoding: utf-8 -*-
+# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
# TODO: Add missing String#[]= specs:
# String#[re, idx] = obj
-describe "String#[]= with Fixnum index" do
+describe "String#[]= with Integer index" do
it "replaces the char at idx with other_str" do
a = "hello"
a[0] = "bam"
@@ -14,18 +15,6 @@ describe "String#[]= with Fixnum index" do
a.should == "bamelo"
end
- ruby_version_is ''...'2.7' do
- it "taints self if other_str is tainted" do
- a = "hello"
- a[0] = "".taint
- a.should.tainted?
-
- a = "hello"
- a[0] = "x".taint
- a.should.tainted?
- end
- end
-
it "raises an IndexError without changing self if idx is outside of self" do
str = "hello"
@@ -85,7 +74,7 @@ describe "String#[]= with Fixnum index" do
-> { "test"[1] = nil }.should raise_error(TypeError)
end
- it "raises a TypeError if passed a Fixnum replacement" do
+ it "raises a TypeError if passed an Integer replacement" do
-> { "abc"[1] = 65 }.should raise_error(TypeError)
end
@@ -102,7 +91,7 @@ describe "String#[]= with Fixnum index" do
str.should == "あa"
end
- it "raises a TypeError if #to_int does not return an Fixnum" do
+ it "raises a TypeError if #to_int does not return an Integer" do
index = mock("string element set")
index.should_receive(:to_int).and_return('1')
@@ -141,6 +130,12 @@ describe "String#[]= with Fixnum index" do
str.encoding.should equal(Encoding::BINARY)
end
+ it "updates the string to a compatible encoding" do
+ str = " "
+ str[1] = [0xB9].pack("C*")
+ str.encoding.should == Encoding::ASCII_8BIT
+ end
+
it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
str = "あれ"
rep = "が".encode Encoding::EUC_JP
@@ -243,7 +238,7 @@ describe "String#[]= with a Regexp index" do
str.should == "axc"
end
- it "raises a TypeError if #to_int does not return a Fixnum" do
+ it "raises a TypeError if #to_int does not return an Integer" do
ref = mock("string element set regexp ref")
ref.should_receive(:to_int).and_return(nil)
@@ -363,11 +358,11 @@ describe "String#[]= with a Range index" do
end
it "raises a RangeError if negative Range begin is out of range" do
- -> { "abc"[-4..-2] = "x" }.should raise_error(RangeError)
+ -> { "abc"[-4..-2] = "x" }.should raise_error(RangeError, "-4..-2 out of range")
end
it "raises a RangeError if positive Range begin is greater than String size" do
- -> { "abc"[4..2] = "x" }.should raise_error(RangeError)
+ -> { "abc"[4..2] = "x" }.should raise_error(RangeError, "4..2 out of range")
end
it "uses the Range end as an index rather than a count" do
@@ -438,7 +433,7 @@ describe "String#[]= with a Range index" do
end
end
-describe "String#[]= with Fixnum index, count" do
+describe "String#[]= with Integer index, count" do
it "starts at idx and overwrites count characters before inserting the rest of other_str" do
a = "hello"
a[0, 2] = "xx"
@@ -487,18 +482,6 @@ describe "String#[]= with Fixnum index, count" do
a.should == "hellobob"
end
- ruby_version_is ''...'2.7' do
- it "taints self if other_str is tainted" do
- a = "hello"
- a[0, 0] = "".taint
- a.should.tainted?
-
- a = "hello"
- a[1, 4] = "x".taint
- a.should.tainted?
- end
- end
-
it "calls #to_int to convert the index and count objects" do
index = mock("string element set index")
index.should_receive(:to_int).and_return(-4)