1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2019-07-27 12:40:09 +02:00
parent a06301b103
commit 5c276e1cc9
1247 changed files with 5316 additions and 5028 deletions

View file

@ -214,9 +214,9 @@ describe "String#gsub with pattern and replacement" do
end
it "raises a TypeError when pattern can't be converted to a string" do
lambda { "hello".gsub([], "x") }.should raise_error(TypeError)
lambda { "hello".gsub(Object.new, "x") }.should raise_error(TypeError)
lambda { "hello".gsub(nil, "x") }.should raise_error(TypeError)
-> { "hello".gsub([], "x") }.should raise_error(TypeError)
-> { "hello".gsub(Object.new, "x") }.should raise_error(TypeError)
-> { "hello".gsub(nil, "x") }.should raise_error(TypeError)
end
it "tries to convert replacement to a string using to_str" do
@ -227,9 +227,9 @@ describe "String#gsub with pattern and replacement" do
end
it "raises a TypeError when replacement can't be converted to a string" do
lambda { "hello".gsub(/[aeiou]/, []) }.should raise_error(TypeError)
lambda { "hello".gsub(/[aeiou]/, Object.new) }.should raise_error(TypeError)
lambda { "hello".gsub(/[aeiou]/, nil) }.should raise_error(TypeError)
-> { "hello".gsub(/[aeiou]/, []) }.should raise_error(TypeError)
-> { "hello".gsub(/[aeiou]/, Object.new) }.should raise_error(TypeError)
-> { "hello".gsub(/[aeiou]/, nil) }.should raise_error(TypeError)
end
it "returns subclass instances when called on a subclass" do
@ -298,7 +298,7 @@ describe "String#gsub with pattern and Hash" do
it "uses the hash's value set from default_proc for missing keys" do
hsh = {}
hsh.default_proc = lambda { |k,v| 'lamb' }
hsh.default_proc = -> k, v { 'lamb' }
"food!".gsub(/./, hsh).should == "lamblamblamblamblamb"
end
@ -387,7 +387,7 @@ describe "String#gsub! with pattern and Hash" do
it "uses the hash's value set from default_proc for missing keys" do
hsh = {}
hsh.default_proc = lambda { |k,v| 'lamb' }
hsh.default_proc = -> k, v { 'lamb' }
"food!".gsub!(/./, hsh).should == "lamblamblamblamblamb"
end
@ -536,8 +536,8 @@ describe "String#gsub with pattern and block" do
s = "hllëllo"
s2 = "hellö"
lambda { s.gsub(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError)
lambda { s2.gsub(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError)
-> { s.gsub(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError)
-> { s2.gsub(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError)
end
it "replaces the incompatible part properly even if the encodings are not compatible" do
@ -549,7 +549,7 @@ describe "String#gsub with pattern and block" do
not_supported_on :opal do
it "raises an ArgumentError if encoding is not valid" do
x92 = [0x92].pack('C').force_encoding('utf-8')
lambda { "a#{x92}b".gsub(/[^\x00-\x7f]/u, '') }.should raise_error(ArgumentError)
-> { "a#{x92}b".gsub(/[^\x00-\x7f]/u, '') }.should raise_error(ArgumentError)
end
end
end
@ -607,9 +607,9 @@ describe "String#gsub! with pattern and replacement" do
s = "hello"
s.freeze
lambda { s.gsub!(/ROAR/, "x") }.should raise_error(frozen_error_class)
lambda { s.gsub!(/e/, "e") }.should raise_error(frozen_error_class)
lambda { s.gsub!(/[aeiou]/, '*') }.should raise_error(frozen_error_class)
-> { s.gsub!(/ROAR/, "x") }.should raise_error(frozen_error_class)
-> { s.gsub!(/e/, "e") }.should raise_error(frozen_error_class)
-> { s.gsub!(/[aeiou]/, '*') }.should raise_error(frozen_error_class)
end
end
@ -644,9 +644,9 @@ describe "String#gsub! with pattern and block" do
s = "hello"
s.freeze
lambda { s.gsub!(/ROAR/) { "x" } }.should raise_error(frozen_error_class)
lambda { s.gsub!(/e/) { "e" } }.should raise_error(frozen_error_class)
lambda { s.gsub!(/[aeiou]/) { '*' } }.should raise_error(frozen_error_class)
-> { s.gsub!(/ROAR/) { "x" } }.should raise_error(frozen_error_class)
-> { s.gsub!(/e/) { "e" } }.should raise_error(frozen_error_class)
-> { s.gsub!(/[aeiou]/) { '*' } }.should raise_error(frozen_error_class)
end
it "uses the compatible encoding if they are compatible" do
@ -661,8 +661,8 @@ describe "String#gsub! with pattern and block" do
s = "hllëllo"
s2 = "hellö"
lambda { s.gsub!(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError)
lambda { s2.gsub!(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError)
-> { s.gsub!(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError)
-> { s2.gsub!(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError)
end
it "replaces the incompatible part properly even if the encodings are not compatible" do
@ -674,7 +674,7 @@ describe "String#gsub! with pattern and block" do
not_supported_on :opal do
it "raises an ArgumentError if encoding is not valid" do
x92 = [0x92].pack('C').force_encoding('utf-8')
lambda { "a#{x92}b".gsub!(/[^\x00-\x7f]/u, '') }.should raise_error(ArgumentError)
-> { "a#{x92}b".gsub!(/[^\x00-\x7f]/u, '') }.should raise_error(ArgumentError)
end
end
end