summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string
diff options
context:
space:
mode:
authorBenoit Daloze <[email protected]>2021-07-29 22:11:21 +0200
committerBenoit Daloze <[email protected]>2021-07-29 22:11:21 +0200
commit6998d758248d778fa95b008c78d05473e48b8428 (patch)
tree8abc6926f647ea5f374a5b34c3a4820c5861e32e /spec/ruby/core/string
parent15d05f8120745a121b93fab9fd2addf5f094e8d2 (diff)
Update to ruby/spec@b65d01f
Diffstat (limited to 'spec/ruby/core/string')
-rw-r--r--spec/ruby/core/string/gsub_spec.rb8
-rw-r--r--spec/ruby/core/string/index_spec.rb1
-rw-r--r--spec/ruby/core/string/scrub_spec.rb6
-rw-r--r--spec/ruby/core/string/shared/slice.rb12
-rw-r--r--spec/ruby/core/string/split_spec.rb152
-rw-r--r--spec/ruby/core/string/uminus_spec.rb40
6 files changed, 100 insertions, 119 deletions
diff --git a/spec/ruby/core/string/gsub_spec.rb b/spec/ruby/core/string/gsub_spec.rb
index 6789199ff3..ad41b7e0a2 100644
--- a/spec/ruby/core/string/gsub_spec.rb
+++ b/spec/ruby/core/string/gsub_spec.rb
@@ -594,6 +594,14 @@ describe "String#gsub with pattern and without replacement and block" do
end
end
+describe "String#gsub with a string pattern" do
+ it "handles multibyte characters" do
+ "é".gsub("é", "â").should == "â"
+ "aé".gsub("é", "â").should == "aâ"
+ "éa".gsub("é", "â").should == "âa"
+ end
+end
+
describe "String#gsub! with pattern and replacement" do
it "modifies self in place and returns self" do
a = "hello"
diff --git a/spec/ruby/core/string/index_spec.rb b/spec/ruby/core/string/index_spec.rb
index 8d2c8af193..5d77a88e4e 100644
--- a/spec/ruby/core/string/index_spec.rb
+++ b/spec/ruby/core/string/index_spec.rb
@@ -146,6 +146,7 @@ describe "String#index with String" do
it "returns the character index after offset" do
"われわれ".index("わ", 1).should == 2
+ "ありがとうありがとう".index("が", 3).should == 7
end
it "returns the character index after a partial first match" do
diff --git a/spec/ruby/core/string/scrub_spec.rb b/spec/ruby/core/string/scrub_spec.rb
index b513acfb70..5c67ad01bc 100644
--- a/spec/ruby/core/string/scrub_spec.rb
+++ b/spec/ruby/core/string/scrub_spec.rb
@@ -119,4 +119,10 @@ describe "String#scrub!" do
input.scrub!
input.instance_variable_get(:@a).should == 'b'
end
+
+ it "accepts a frozen string as a replacement" do
+ input = "a\xE2"
+ input.scrub!('.'.freeze)
+ input.should == 'a.'
+ end
end
diff --git a/spec/ruby/core/string/shared/slice.rb b/spec/ruby/core/string/shared/slice.rb
index a674e0b6ef..1db8fd6730 100644
--- a/spec/ruby/core/string/shared/slice.rb
+++ b/spec/ruby/core/string/shared/slice.rb
@@ -327,13 +327,11 @@ describe :string_slice_range, shared: true do
-> { "hello".send(@method, 0..bignum_value) }.should raise_error(RangeError)
end
- ruby_version_is "2.6" do
- it "works with endless ranges" do
- "hello there".send(@method, eval("(2..)")).should == "llo there"
- "hello there".send(@method, eval("(2...)")).should == "llo there"
- "hello there".send(@method, eval("(-4..)")).should == "here"
- "hello there".send(@method, eval("(-4...)")).should == "here"
- end
+ it "works with endless ranges" do
+ "hello there".send(@method, eval("(2..)")).should == "llo there"
+ "hello there".send(@method, eval("(2...)")).should == "llo there"
+ "hello there".send(@method, eval("(-4..)")).should == "here"
+ "hello there".send(@method, eval("(-4...)")).should == "here"
end
ruby_version_is "2.7" do
diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb
index e3641b33e0..a373be360d 100644
--- a/spec/ruby/core/string/split_spec.rb
+++ b/spec/ruby/core/string/split_spec.rb
@@ -471,108 +471,106 @@ describe "String#split with Regexp" do
results.should == [%w[a b c d e]] * 10
end
- ruby_version_is "2.6" do
- context "when a block is given" do
- it "yields each split substring with default pattern" do
- a = []
- returned_object = "chunky bacon".split { |str| a << str.capitalize }
+ context "when a block is given" do
+ it "yields each split substring with default pattern" do
+ a = []
+ returned_object = "chunky bacon".split { |str| a << str.capitalize }
- returned_object.should == "chunky bacon"
- a.should == ["Chunky", "Bacon"]
- end
+ returned_object.should == "chunky bacon"
+ a.should == ["Chunky", "Bacon"]
+ end
- it "yields each split substring with default pattern for a non-ASCII string" do
- a = []
- returned_object = "l'été arrive bientôt".split { |str| a << str }
+ it "yields each split substring with default pattern for a non-ASCII string" do
+ a = []
+ returned_object = "l'été arrive bientôt".split { |str| a << str }
- returned_object.should == "l'été arrive bientôt"
- a.should == ["l'été", "arrive", "bientôt"]
- end
+ returned_object.should == "l'été arrive bientôt"
+ a.should == ["l'été", "arrive", "bientôt"]
+ end
- it "yields the string when limit is 1" do
- a = []
- returned_object = "chunky bacon".split("", 1) { |str| a << str.capitalize }
+ it "yields the string when limit is 1" do
+ a = []
+ returned_object = "chunky bacon".split("", 1) { |str| a << str.capitalize }
- returned_object.should == "chunky bacon"
- a.should == ["Chunky bacon"]
- end
+ returned_object.should == "chunky bacon"
+ a.should == ["Chunky bacon"]
+ end
- it "yields each split letter" do
- a = []
- returned_object = "chunky".split("", 0) { |str| a << str.capitalize }
+ it "yields each split letter" do
+ a = []
+ returned_object = "chunky".split("", 0) { |str| a << str.capitalize }
- returned_object.should == "chunky"
- a.should == %w(C H U N K Y)
- end
+ returned_object.should == "chunky"
+ a.should == %w(C H U N K Y)
+ end
- it "yields each split substring with a pattern" do
- a = []
- returned_object = "chunky-bacon".split("-", 0) { |str| a << str.capitalize }
+ it "yields each split substring with a pattern" do
+ a = []
+ returned_object = "chunky-bacon".split("-", 0) { |str| a << str.capitalize }
- returned_object.should == "chunky-bacon"
- a.should == ["Chunky", "Bacon"]
- end
+ returned_object.should == "chunky-bacon"
+ a.should == ["Chunky", "Bacon"]
+ end
- it "yields each split substring with empty regexp pattern" do
- a = []
- returned_object = "chunky".split(//) { |str| a << str.capitalize }
+ it "yields each split substring with empty regexp pattern" do
+ a = []
+ returned_object = "chunky".split(//) { |str| a << str.capitalize }
- returned_object.should == "chunky"
- a.should == %w(C H U N K Y)
- end
+ returned_object.should == "chunky"
+ a.should == %w(C H U N K Y)
+ end
- it "yields each split substring with empty regexp pattern and limit" do
- a = []
- returned_object = "chunky".split(//, 3) { |str| a << str.capitalize }
+ it "yields each split substring with empty regexp pattern and limit" do
+ a = []
+ returned_object = "chunky".split(//, 3) { |str| a << str.capitalize }
- returned_object.should == "chunky"
- a.should == %w(C H Unky)
- end
+ returned_object.should == "chunky"
+ a.should == %w(C H Unky)
+ end
- it "yields each split substring with a regexp pattern" do
- a = []
- returned_object = "chunky:bacon".split(/:/) { |str| a << str.capitalize }
+ it "yields each split substring with a regexp pattern" do
+ a = []
+ returned_object = "chunky:bacon".split(/:/) { |str| a << str.capitalize }
- returned_object.should == "chunky:bacon"
- a.should == ["Chunky", "Bacon"]
- end
+ returned_object.should == "chunky:bacon"
+ a.should == ["Chunky", "Bacon"]
+ end
- it "returns a string as is (and doesn't call block) if it is empty" do
- a = []
- returned_object = "".split { |str| a << str.capitalize }
+ it "returns a string as is (and doesn't call block) if it is empty" do
+ a = []
+ returned_object = "".split { |str| a << str.capitalize }
- returned_object.should == ""
- a.should == []
- end
+ returned_object.should == ""
+ a.should == []
end
+ end
- describe "for a String subclass" do
- ruby_version_is ''...'3.0' do
- it "yields instances of the same subclass" do
- a = []
- StringSpecs::MyString.new("a|b").split("|") { |str| a << str }
- first, last = a
+ describe "for a String subclass" do
+ ruby_version_is ''...'3.0' do
+ it "yields instances of the same subclass" do
+ a = []
+ StringSpecs::MyString.new("a|b").split("|") { |str| a << str }
+ first, last = a
- first.should be_an_instance_of(StringSpecs::MyString)
- first.should == "a"
+ first.should be_an_instance_of(StringSpecs::MyString)
+ first.should == "a"
- last.should be_an_instance_of(StringSpecs::MyString)
- last.should == "b"
- end
+ last.should be_an_instance_of(StringSpecs::MyString)
+ last.should == "b"
end
+ end
- ruby_version_is '3.0' do
- it "yields instances of String" do
- a = []
- StringSpecs::MyString.new("a|b").split("|") { |str| a << str }
- first, last = a
+ ruby_version_is '3.0' do
+ it "yields instances of String" do
+ a = []
+ StringSpecs::MyString.new("a|b").split("|") { |str| a << str }
+ first, last = a
- first.should be_an_instance_of(String)
- first.should == "a"
+ first.should be_an_instance_of(String)
+ first.should == "a"
- last.should be_an_instance_of(String)
- last.should == "b"
- end
+ last.should be_an_instance_of(String)
+ last.should == "b"
end
end
end
diff --git a/spec/ruby/core/string/uminus_spec.rb b/spec/ruby/core/string/uminus_spec.rb
index 3a81b64126..800dca5044 100644
--- a/spec/ruby/core/string/uminus_spec.rb
+++ b/spec/ruby/core/string/uminus_spec.rb
@@ -31,43 +31,13 @@ describe 'String#-@' do
(-"unfrozen string").should_not equal(-"another unfrozen string")
end
- ruby_version_is ""..."2.6" do
- it "does not deduplicate already frozen strings" do
- dynamic = %w(this string is frozen).join(' ').freeze
+ it "deduplicates frozen strings" do
+ dynamic = %w(this string is frozen).join(' ').freeze
- dynamic.should_not equal("this string is frozen".freeze)
+ dynamic.should_not equal("this string is frozen".freeze)
- (-dynamic).should_not equal("this string is frozen".freeze)
- (-dynamic).should_not equal(-"this string is frozen".freeze)
- (-dynamic).should == "this string is frozen"
- end
-
- it "does not deduplicate tainted strings" do
- dynamic = %w(this string is frozen).join(' ')
- dynamic.taint
- (-dynamic).should_not equal("this string is frozen".freeze)
- (-dynamic).should_not equal(-"this string is frozen".freeze)
- (-dynamic).should == "this string is frozen"
- end
-
- it "does not deduplicate strings with additional instance variables" do
- dynamic = %w(this string is frozen).join(' ')
- dynamic.instance_variable_set(:@foo, :bar)
- (-dynamic).should_not equal("this string is frozen".freeze)
- (-dynamic).should_not equal(-"this string is frozen".freeze)
- (-dynamic).should == "this string is frozen"
- end
- end
-
- ruby_version_is "2.6" do
- it "deduplicates frozen strings" do
- dynamic = %w(this string is frozen).join(' ').freeze
-
- dynamic.should_not equal("this string is frozen".freeze)
-
- (-dynamic).should equal("this string is frozen".freeze)
- (-dynamic).should equal(-"this string is frozen".freeze)
- end
+ (-dynamic).should equal("this string is frozen".freeze)
+ (-dynamic).should equal(-"this string is frozen".freeze)
end
ruby_version_is "3.0" do