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.rb253
1 files changed, 124 insertions, 129 deletions
diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb
index 9fb93902b1..4f7f44e5d4 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,193 +9,187 @@ describe "String#downcase" do
"hello".downcase.should == "hello"
end
- ruby_version_is ''...'2.4' do
- it "is locale insensitive (only replaces A-Z)" do
- "ÄÖÜ".downcase.should == "ÄÖÜ"
-
- str = Array.new(256) { |c| c.chr }.join
- expected = Array.new(256) do |i|
- c = i.chr
- c.between?("A", "Z") ? c.downcase : c
- end.join
-
- str.downcase.should == expected
- end
+ it "returns a String in the same encoding as self" do
+ "hELLO".encode("US-ASCII").downcase.encoding.should == Encoding::US_ASCII
end
- ruby_version_is '2.4' do
- describe "full Unicode case mapping" do
- it "works for all of Unicode with no option" do
- "ÄÖÜ".downcase.should == "äöü"
- end
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "ÄÖÜ".downcase.should == "äöü"
+ end
- it "updates string metadata" do
- downcased = "\u{212A}ING".downcase
+ it "updates string metadata" do
+ downcased = "\u{212A}ING".downcase
- downcased.should == "king"
- downcased.size.should == 4
- downcased.bytesize.should == 4
- downcased.ascii_only?.should be_true
- end
+ downcased.should == "king"
+ downcased.size.should == 4
+ downcased.bytesize.should == 4
+ downcased.ascii_only?.should == true
end
+ end
- describe "ASCII-only case mapping" do
- it "does not downcase non-ASCII characters" do
- "CÅR".downcase(:ascii).should == "cÅr"
- end
+ describe "ASCII-only case mapping" do
+ it "does not downcase non-ASCII characters" do
+ "CÅR".downcase(:ascii).should == "cÅr"
end
- describe "full Unicode case mapping adapted for Turkic languages" do
- it "downcases characters according to Turkic semantics" do
- "İ".downcase(:turkic).should == "i"
- end
+ it "works with substrings" do
+ "prefix TÉ"[-2..-1].downcase(:ascii).should == "tÉ"
+ end
+ end
- it "allows Lithuanian as an extra option" do
- "İ".downcase(:turkic, :lithuanian).should == "i"
- end
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "downcases characters according to Turkic semantics" do
+ "İ".downcase(:turkic).should == "i"
+ end
- it "does not allow any other additional option" do
- lambda { "İ".downcase(:turkic, :ascii) }.should raise_error(ArgumentError)
- end
+ it "allows Lithuanian as an extra option" do
+ "İ".downcase(:turkic, :lithuanian).should == "i"
end
- describe "full Unicode case mapping adapted for Lithuanian" do
- it "currently works the same as full Unicode case mapping" do
- "İS".downcase(:lithuanian).should == "i\u{307}s"
- end
+ it "does not allow any other additional option" do
+ -> { "İ".downcase(:turkic, :ascii) }.should.raise(ArgumentError)
+ end
+ end
- it "allows Turkic as an extra option (and applies Turkic semantics)" do
- "İS".downcase(:lithuanian, :turkic).should == "is"
- end
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "İS".downcase(:lithuanian).should == "i\u{307}s"
+ end
- it "does not allow any other additional option" do
- lambda { "İS".downcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
- end
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "İS".downcase(:lithuanian, :turkic).should == "is"
end
- describe "case folding" do
- it "case folds special characters" do
- "ß".downcase.should == "ß"
- "ß".downcase(:fold).should == "ss"
- end
+ it "does not allow any other additional option" do
+ -> { "İS".downcase(:lithuanian, :ascii) }.should.raise(ArgumentError)
end
+ end
- it "does not allow invalid options" do
- lambda { "ABC".downcase(:invalid_option) }.should raise_error(ArgumentError)
+ describe "case folding" do
+ it "case folds special characters" do
+ "ß".downcase.should == "ß"
+ "ß".downcase(:fold).should == "ss"
end
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
+ it "does not allow invalid options" do
+ -> { "ABC".downcase(:invalid_option) }.should.raise(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.instance_of?(String)
end
end
describe "String#downcase!" do
it "modifies self in place" do
a = "HeLlO"
- a.downcase!.should equal(a)
+ a.downcase!.should.equal?(a)
a.should == "hello"
end
- ruby_version_is '2.4' do
- describe "full Unicode case mapping" do
- it "modifies self in place for all of Unicode with no option" do
- a = "ÄÖÜ"
- a.downcase!
- a.should == "äöü"
- end
-
- it "updates string metadata" do
- downcased = "\u{212A}ING"
- downcased.downcase!
+ 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
- downcased.should == "king"
- downcased.size.should == 4
- downcased.bytesize.should == 4
- downcased.ascii_only?.should be_true
- end
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
+ a = "ÄÖÜ"
+ a.downcase!
+ a.should == "äöü"
end
- describe "ASCII-only case mapping" do
- it "does not downcase non-ASCII characters" do
- a = "CÅR"
- a.downcase!(:ascii)
- a.should == "cÅr"
- end
+ it "updates string metadata" do
+ downcased = "\u{212A}ING"
+ downcased.downcase!
+
+ downcased.should == "king"
+ downcased.size.should == 4
+ downcased.bytesize.should == 4
+ downcased.ascii_only?.should == true
end
+ end
- describe "full Unicode case mapping adapted for Turkic languages" do
- it "downcases characters according to Turkic semantics" do
- a = "İ"
- a.downcase!(:turkic)
- a.should == "i"
- end
+ describe "ASCII-only case mapping" do
+ it "does not downcase non-ASCII characters" do
+ a = "CÅR"
+ a.downcase!(:ascii)
+ a.should == "cÅr"
+ end
- it "allows Lithuanian as an extra option" do
- a = "İ"
- a.downcase!(:turkic, :lithuanian)
- a.should == "i"
- 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
- it "does not allow any other additional option" do
- lambda { a = "İ"; a.downcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "downcases characters according to Turkic semantics" do
+ a = "İ"
+ a.downcase!(:turkic)
+ a.should == "i"
end
- describe "full Unicode case mapping adapted for Lithuanian" do
- it "currently works the same as full Unicode case mapping" do
- a = "İS"
- a.downcase!(:lithuanian)
- a.should == "i\u{307}s"
- end
+ it "allows Lithuanian as an extra option" do
+ a = "İ"
+ a.downcase!(:turkic, :lithuanian)
+ a.should == "i"
+ end
- it "allows Turkic as an extra option (and applies Turkic semantics)" do
- a = "İS"
- a.downcase!(:lithuanian, :turkic)
- a.should == "is"
- end
+ it "does not allow any other additional option" do
+ -> { a = "İ"; a.downcase!(:turkic, :ascii) }.should.raise(ArgumentError)
+ end
+ end
- it "does not allow any other additional option" do
- lambda { a = "İS"; a.downcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = "İS"
+ a.downcase!(:lithuanian)
+ a.should == "i\u{307}s"
end
- describe "case folding" do
- it "case folds special characters" do
- a = "ß"
- a.downcase!
- a.should == "ß"
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = "İS"
+ a.downcase!(:lithuanian, :turkic)
+ a.should == "is"
+ end
- a.downcase!(:fold)
- a.should == "ss"
- end
+ it "does not allow any other additional option" do
+ -> { a = "İS"; a.downcase!(:lithuanian, :ascii) }.should.raise(ArgumentError)
end
+ end
+
+ describe "case folding" do
+ it "case folds special characters" do
+ a = "ß"
+ a.downcase!
+ a.should == "ß"
- it "does not allow invalid options" do
- lambda { a = "ABC"; a.downcase!(:invalid_option) }.should raise_error(ArgumentError)
+ a.downcase!(:fold)
+ a.should == "ss"
end
end
+ it "does not allow invalid options" do
+ -> { a = "ABC"; a.downcase!(:invalid_option) }.should.raise(ArgumentError)
+ end
+
it "returns nil if no modifications were made" do
a = "hello"
a.downcase!.should == nil
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(FrozenError)
+ -> { "hello".freeze.downcase! }.should.raise(FrozenError)
end
- with_feature :encoding do
- it "sets the result String encoding to the source String encoding" do
- "ABC".downcase.encoding.should equal(Encoding::UTF_8)
- end
+ it "sets the result String encoding to the source String encoding" do
+ "ABC".downcase.encoding.should.equal?(Encoding::UTF_8)
end
end