summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/downcase_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string/downcase_spec.rb')
-rw-r--r--spec/ruby/core/string/downcase_spec.rb49
1 files changed, 32 insertions, 17 deletions
diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb
index 9d57ea8e25..2d260f23f1 100644
--- a/spec/ruby/core/string/downcase_spec.rb
+++ b/spec/ruby/core/string/downcase_spec.rb
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
+# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
@@ -8,6 +9,10 @@ describe "String#downcase" do
"hello".downcase.should == "hello"
end
+ it "returns a String in the same encoding as self" do
+ "hELLO".encode("US-ASCII").downcase.encoding.should == Encoding::US_ASCII
+ end
+
describe "full Unicode case mapping" do
it "works for all of Unicode with no option" do
"ÄÖÜ".downcase.should == "äöü"
@@ -27,6 +32,10 @@ describe "String#downcase" do
it "does not downcase non-ASCII characters" do
"CÅR".downcase(:ascii).should == "cÅr"
end
+
+ it "works with substrings" do
+ "prefix TÉ"[-2..-1].downcase(:ascii).should == "tÉ"
+ end
end
describe "full Unicode case mapping adapted for Turkic languages" do
@@ -39,7 +48,7 @@ describe "String#downcase" do
end
it "does not allow any other additional option" do
- lambda { "İ".downcase(:turkic, :ascii) }.should raise_error(ArgumentError)
+ -> { "İ".downcase(:turkic, :ascii) }.should raise_error(ArgumentError)
end
end
@@ -53,7 +62,7 @@ describe "String#downcase" do
end
it "does not allow any other additional option" do
- lambda { "İS".downcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
+ -> { "İS".downcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
end
end
@@ -65,17 +74,11 @@ describe "String#downcase" do
end
it "does not allow invalid options" do
- lambda { "ABC".downcase(:invalid_option) }.should raise_error(ArgumentError)
- end
-
- it "taints result when self is tainted" do
- "".taint.downcase.tainted?.should == true
- "x".taint.downcase.tainted?.should == true
- "X".taint.downcase.tainted?.should == true
+ -> { "ABC".downcase(:invalid_option) }.should raise_error(ArgumentError)
end
- it "returns a subclass instance for subclasses" do
- StringSpecs::MyString.new("FOObar").downcase.should be_an_instance_of(StringSpecs::MyString)
+ it "returns a String instance for subclasses" do
+ StringSpecs::MyString.new("FOObar").downcase.should be_an_instance_of(String)
end
end
@@ -86,6 +89,12 @@ describe "String#downcase!" do
a.should == "hello"
end
+ it "modifies self in place for non-ascii-compatible encodings" do
+ a = "HeLlO".encode("utf-16le")
+ a.downcase!
+ a.should == "hello".encode("utf-16le")
+ end
+
describe "full Unicode case mapping" do
it "modifies self in place for all of Unicode with no option" do
a = "ÄÖÜ"
@@ -110,6 +119,12 @@ describe "String#downcase!" do
a.downcase!(:ascii)
a.should == "cÅr"
end
+
+ it "works for non-ascii-compatible encodings" do
+ a = "ABC".encode("utf-16le")
+ a.downcase!(:ascii)
+ a.should == "abc".encode("utf-16le")
+ end
end
describe "full Unicode case mapping adapted for Turkic languages" do
@@ -126,7 +141,7 @@ describe "String#downcase!" do
end
it "does not allow any other additional option" do
- lambda { a = "İ"; a.downcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
+ -> { a = "İ"; a.downcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
end
end
@@ -144,7 +159,7 @@ describe "String#downcase!" do
end
it "does not allow any other additional option" do
- lambda { a = "İS"; a.downcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
+ -> { a = "İS"; a.downcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
end
end
@@ -160,7 +175,7 @@ describe "String#downcase!" do
end
it "does not allow invalid options" do
- lambda { a = "ABC"; a.downcase!(:invalid_option) }.should raise_error(ArgumentError)
+ -> { a = "ABC"; a.downcase!(:invalid_option) }.should raise_error(ArgumentError)
end
it "returns nil if no modifications were made" do
@@ -169,9 +184,9 @@ describe "String#downcase!" do
a.should == "hello"
end
- it "raises a #{frozen_error_class} when self is frozen" do
- lambda { "HeLlo".freeze.downcase! }.should raise_error(frozen_error_class)
- lambda { "hello".freeze.downcase! }.should raise_error(frozen_error_class)
+ it "raises a FrozenError when self is frozen" do
+ -> { "HeLlo".freeze.downcase! }.should raise_error(FrozenError)
+ -> { "hello".freeze.downcase! }.should raise_error(FrozenError)
end
it "sets the result String encoding to the source String encoding" do