summaryrefslogtreecommitdiff
path: root/spec/ruby/shared/string
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/shared/string')
-rw-r--r--spec/ruby/shared/string/end_with.rb17
-rw-r--r--spec/ruby/shared/string/start_with.rb20
-rw-r--r--spec/ruby/shared/string/times.rb42
3 files changed, 39 insertions, 40 deletions
diff --git a/spec/ruby/shared/string/end_with.rb b/spec/ruby/shared/string/end_with.rb
index 5f2a011235..8eb9693395 100644
--- a/spec/ruby/shared/string/end_with.rb
+++ b/spec/ruby/shared/string/end_with.rb
@@ -30,15 +30,15 @@ describe :end_with, shared: true do
it "ignores arguments not convertible to string" do
"hello".send(@method).should_not.end_with?()
- -> { "hello".send(@method).end_with?(1) }.should raise_error(TypeError)
- -> { "hello".send(@method).end_with?(["o"]) }.should raise_error(TypeError)
- -> { "hello".send(@method).end_with?(1, nil, "o") }.should raise_error(TypeError)
+ -> { "hello".send(@method).end_with?(1) }.should.raise(TypeError)
+ -> { "hello".send(@method).end_with?(["o"]) }.should.raise(TypeError)
+ -> { "hello".send(@method).end_with?(1, nil, "o") }.should.raise(TypeError)
end
it "uses only the needed arguments" do
find = mock('h')
find.should_not_receive(:to_str)
- "hello".send(@method).should.end_with?("o",find)
+ "hello".send(@method).should.end_with?("o", find)
end
it "works for multibyte strings" do
@@ -49,6 +49,13 @@ describe :end_with, shared: true do
pat = "ア".encode Encoding::EUC_JP
-> do
"あれ".send(@method).end_with?(pat)
- end.should raise_error(Encoding::CompatibilityError)
+ end.should.raise(Encoding::CompatibilityError)
+ end
+
+ it "checks that we are starting to match at the head of a character" do
+ "\xC3\xA9".send(@method).should_not.end_with?("\xA9")
+ "\xe3\x81\x82".send(@method).should_not.end_with?("\x82")
+ "\xd8\x00\xdc\x00".dup.force_encoding("UTF-16BE").send(@method).should_not.end_with?(
+ "\xdc\x00".dup.force_encoding("UTF-16BE"))
end
end
diff --git a/spec/ruby/shared/string/start_with.rb b/spec/ruby/shared/string/start_with.rb
index d8d6e13f6a..fe12e28969 100644
--- a/spec/ruby/shared/string/start_with.rb
+++ b/spec/ruby/shared/string/start_with.rb
@@ -26,9 +26,9 @@ describe :start_with, shared: true do
it "ignores arguments not convertible to string" do
"hello".send(@method).should_not.start_with?()
- -> { "hello".send(@method).start_with?(1) }.should raise_error(TypeError)
- -> { "hello".send(@method).start_with?(["h"]) }.should raise_error(TypeError)
- -> { "hello".send(@method).start_with?(1, nil, "h") }.should raise_error(TypeError)
+ -> { "hello".send(@method).start_with?(1) }.should.raise(TypeError)
+ -> { "hello".send(@method).start_with?(["h"]) }.should.raise(TypeError)
+ -> { "hello".send(@method).start_with?(1, nil, "h") }.should.raise(TypeError)
end
it "uses only the needed arguments" do
@@ -60,13 +60,17 @@ describe :start_with, shared: true do
it "sets Regexp.last_match if it returns true" do
regexp = /test-(\d+)/
- "test-1337".send(@method).start_with?(regexp).should be_true
- Regexp.last_match.should_not be_nil
+ "test-1337".send(@method).start_with?(regexp).should == true
+ Regexp.last_match.should_not == nil
Regexp.last_match[1].should == "1337"
$1.should == "1337"
- "test-asdf".send(@method).start_with?(regexp).should be_false
- Regexp.last_match.should be_nil
- $1.should be_nil
+ "test-asdf".send(@method).start_with?(regexp).should == false
+ Regexp.last_match.should == nil
+ $1.should == nil
+ end
+
+ it "checks that we are not matching part of a character" do
+ "\xC3\xA9".send(@method).should_not.start_with?("\xC3")
end
end
diff --git a/spec/ruby/shared/string/times.rb b/spec/ruby/shared/string/times.rb
index 4dd59884c8..0a16ba8b82 100644
--- a/spec/ruby/shared/string/times.rb
+++ b/spec/ruby/shared/string/times.rb
@@ -18,53 +18,41 @@ describe :string_times, shared: true do
end
it "raises an ArgumentError when given integer is negative" do
- -> { @object.call("cool", -3) }.should raise_error(ArgumentError)
- -> { @object.call("cool", -3.14) }.should raise_error(ArgumentError)
- -> { @object.call("cool", min_long) }.should raise_error(ArgumentError)
+ -> { @object.call("cool", -3) }.should.raise(ArgumentError)
+ -> { @object.call("cool", -3.14) }.should.raise(ArgumentError)
+ -> { @object.call("cool", min_long) }.should.raise(ArgumentError)
end
it "raises a RangeError when given integer is a Bignum" do
- -> { @object.call("cool", 999999999999999999999) }.should raise_error(RangeError)
- -> { @object.call("", 999999999999999999999) }.should raise_error(RangeError)
+ -> { @object.call("cool", 999999999999999999999) }.should.raise(RangeError)
+ -> { @object.call("", 999999999999999999999) }.should.raise(RangeError)
end
it "works with huge long values when string is empty" do
@object.call("", max_long).should == ""
end
- it "returns subclass instances" do
- @object.call(MyString.new("cool"), 0).should be_an_instance_of(MyString)
- @object.call(MyString.new("cool"), 1).should be_an_instance_of(MyString)
- @object.call(MyString.new("cool"), 2).should be_an_instance_of(MyString)
- end
-
- ruby_version_is ''...'2.7' do
- it "always taints the result when self is tainted" do
- ["", "OK", MyString.new(""), MyString.new("OK")].each do |str|
- str.taint
-
- [0, 1, 2].each do |arg|
- @object.call(str, arg).should.tainted?
- end
- end
- end
+ it "returns String instances" do
+ @object.call(MyString.new("cool"), 0).should.instance_of?(String)
+ @object.call(MyString.new("cool"), 1).should.instance_of?(String)
+ @object.call(MyString.new("cool"), 2).should.instance_of?(String)
end
it "returns a String in the same encoding as self" do
- str = "\xE3\x81\x82".force_encoding Encoding::UTF_8
+ str = "\xE3\x81\x82".dup.force_encoding Encoding::UTF_8
result = @object.call(str, 2)
- result.encoding.should equal(Encoding::UTF_8)
+ result.encoding.should.equal?(Encoding::UTF_8)
end
- platform_is wordsize: 32 do
+ platform_is c_long_size: 32 do
it "raises an ArgumentError if the length of the resulting string doesn't fit into a long" do
- -> { @object.call("abc", (2 ** 31) - 1) }.should raise_error(ArgumentError)
+ -> { @object.call("abc", (2 ** 31) - 1) }.should.raise(ArgumentError)
end
end
- platform_is wordsize: 64 do
+ platform_is c_long_size: 64 do
it "raises an ArgumentError if the length of the resulting string doesn't fit into a long" do
- -> { @object.call("abc", (2 ** 63) - 1) }.should raise_error(ArgumentError)
+ -> { @object.call("abc", (2 ** 63) - 1) }.should.raise(ArgumentError)
end
end
end