2017-05-07 08:04:49 -04:00
|
|
|
# -*- encoding: utf-8 -*-
|
2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/classes'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "String#upcase" do
|
|
|
|
it "returns a copy of self with all lowercase letters upcased" do
|
|
|
|
"Hello".upcase.should == "HELLO"
|
|
|
|
"hello".upcase.should == "HELLO"
|
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
describe "full Unicode case mapping" do
|
|
|
|
it "works for all of Unicode with no option" do
|
|
|
|
"äöü".upcase.should == "ÄÖÜ"
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "updates string metadata" do
|
|
|
|
upcased = "aßet".upcase
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
upcased.should == "ASSET"
|
|
|
|
upcased.size.should == 5
|
|
|
|
upcased.bytesize.should == 5
|
|
|
|
upcased.ascii_only?.should be_true
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
describe "ASCII-only case mapping" do
|
|
|
|
it "does not upcase non-ASCII characters" do
|
|
|
|
"aßet".upcase(:ascii).should == "AßET"
|
2018-06-13 17:58:54 -04:00
|
|
|
end
|
2019-04-27 12:53:23 -04:00
|
|
|
end
|
2018-06-13 17:58:54 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
describe "full Unicode case mapping adapted for Turkic languages" do
|
|
|
|
it "upcases ASCII characters according to Turkic semantics" do
|
|
|
|
"i".upcase(:turkic).should == "İ"
|
2018-06-13 17:58:54 -04:00
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "allows Lithuanian as an extra option" do
|
|
|
|
"i".upcase(:turkic, :lithuanian).should == "İ"
|
2018-06-13 17:58:54 -04:00
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "does not allow any other additional option" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { "i".upcase(:turkic, :ascii) }.should raise_error(ArgumentError)
|
2019-04-27 12:53:23 -04:00
|
|
|
end
|
|
|
|
end
|
2018-06-13 17:58:54 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
describe "full Unicode case mapping adapted for Lithuanian" do
|
|
|
|
it "currently works the same as full Unicode case mapping" do
|
|
|
|
"iß".upcase(:lithuanian).should == "ISS"
|
2018-06-13 17:58:54 -04:00
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "allows Turkic as an extra option (and applies Turkic semantics)" do
|
|
|
|
"iß".upcase(:lithuanian, :turkic).should == "İSS"
|
2018-06-13 17:58:54 -04:00
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "does not allow any other additional option" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { "iß".upcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
|
2017-05-19 04:19:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "does not allow the :fold option for upcasing" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { "abc".upcase(:fold) }.should raise_error(ArgumentError)
|
2019-04-27 12:53:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not allow invalid options" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { "abc".upcase(:invalid_option) }.should raise_error(ArgumentError)
|
2019-04-27 12:53:23 -04:00
|
|
|
end
|
|
|
|
|
2019-09-24 23:59:12 -04:00
|
|
|
ruby_version_is ''...'2.7' do
|
|
|
|
it "taints result when self is tainted" do
|
2020-05-03 06:28:29 -04:00
|
|
|
"".taint.upcase.should.tainted?
|
|
|
|
"X".taint.upcase.should.tainted?
|
|
|
|
"x".taint.upcase.should.tainted?
|
2019-09-24 23:59:12 -04:00
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2020-10-24 14:52:30 -04:00
|
|
|
ruby_version_is ''...'3.0' do
|
|
|
|
it "returns a subclass instance for subclasses" do
|
|
|
|
StringSpecs::MyString.new("fooBAR").upcase.should be_an_instance_of(StringSpecs::MyString)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ruby_version_is '3.0' do
|
|
|
|
it "returns a String instance for subclasses" do
|
|
|
|
StringSpecs::MyString.new("fooBAR").upcase.should be_an_instance_of(String)
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "String#upcase!" do
|
|
|
|
it "modifies self in place" do
|
|
|
|
a = "HeLlO"
|
|
|
|
a.upcase!.should equal(a)
|
|
|
|
a.should == "HELLO"
|
|
|
|
end
|
|
|
|
|
2020-01-28 14:47:48 -05:00
|
|
|
it "modifies self in place for non-ascii-compatible encodings" do
|
|
|
|
a = "HeLlO".encode("utf-16le")
|
|
|
|
a.upcase!
|
|
|
|
a.should == "HELLO".encode("utf-16le")
|
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
describe "full Unicode case mapping" do
|
|
|
|
it "modifies self in place for all of Unicode with no option" do
|
|
|
|
a = "äöü"
|
|
|
|
a.upcase!
|
|
|
|
a.should == "ÄÖÜ"
|
|
|
|
end
|
2018-06-13 17:58:54 -04:00
|
|
|
|
2020-01-28 14:47:48 -05:00
|
|
|
it "works for non-ascii-compatible encodings" do
|
|
|
|
a = "äöü".encode("utf-16le")
|
|
|
|
a.upcase!
|
|
|
|
a.should == "ÄÖÜ".encode("utf-16le")
|
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "updates string metadata for self" do
|
|
|
|
upcased = "aßet"
|
|
|
|
upcased.upcase!
|
2018-06-13 17:58:54 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
upcased.should == "ASSET"
|
|
|
|
upcased.size.should == 5
|
|
|
|
upcased.bytesize.should == 5
|
|
|
|
upcased.ascii_only?.should be_true
|
2018-06-13 17:58:54 -04:00
|
|
|
end
|
2019-04-27 12:53:23 -04:00
|
|
|
end
|
2018-06-13 17:58:54 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
describe "modifies self in place for ASCII-only case mapping" do
|
|
|
|
it "does not upcase non-ASCII characters" do
|
|
|
|
a = "aßet"
|
|
|
|
a.upcase!(:ascii)
|
|
|
|
a.should == "AßET"
|
2018-06-13 17:58:54 -04:00
|
|
|
end
|
2020-01-28 14:47:48 -05:00
|
|
|
|
|
|
|
it "works for non-ascii-compatible encodings" do
|
|
|
|
a = "abc".encode("utf-16le")
|
|
|
|
a.upcase!(:ascii)
|
|
|
|
a.should == "ABC".encode("utf-16le")
|
|
|
|
end
|
2019-04-27 12:53:23 -04:00
|
|
|
end
|
2018-06-13 17:58:54 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
|
|
|
|
it "upcases ASCII characters according to Turkic semantics" do
|
|
|
|
a = "i"
|
|
|
|
a.upcase!(:turkic)
|
|
|
|
a.should == "İ"
|
2018-06-13 17:58:54 -04:00
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "allows Lithuanian as an extra option" do
|
|
|
|
a = "i"
|
|
|
|
a.upcase!(:turkic, :lithuanian)
|
|
|
|
a.should == "İ"
|
|
|
|
end
|
2018-06-13 17:58:54 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "does not allow any other additional option" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { a = "i"; a.upcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
|
2019-04-27 12:53:23 -04:00
|
|
|
end
|
|
|
|
end
|
2018-06-13 17:58:54 -04:00
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
describe "modifies self in place for full Unicode case mapping adapted for Lithuanian" do
|
|
|
|
it "currently works the same as full Unicode case mapping" do
|
|
|
|
a = "iß"
|
|
|
|
a.upcase!(:lithuanian)
|
|
|
|
a.should == "ISS"
|
2018-06-13 17:58:54 -04:00
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "allows Turkic as an extra option (and applies Turkic semantics)" do
|
|
|
|
a = "iß"
|
|
|
|
a.upcase!(:lithuanian, :turkic)
|
|
|
|
a.should == "İSS"
|
2018-06-13 17:58:54 -04:00
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "does not allow any other additional option" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { a = "iß"; a.upcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
|
2017-10-28 11:15:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-27 12:53:23 -04:00
|
|
|
it "does not allow the :fold option for upcasing" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { a = "abc"; a.upcase!(:fold) }.should raise_error(ArgumentError)
|
2019-04-27 12:53:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not allow invalid options" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { a = "abc"; a.upcase!(:invalid_option) }.should raise_error(ArgumentError)
|
2019-04-27 12:53:23 -04:00
|
|
|
end
|
|
|
|
|
2017-05-07 08:04:49 -04:00
|
|
|
it "returns nil if no modifications were made" do
|
|
|
|
a = "HELLO"
|
|
|
|
a.upcase!.should == nil
|
|
|
|
a.should == "HELLO"
|
|
|
|
end
|
|
|
|
|
2020-02-08 21:07:01 -05:00
|
|
|
it "raises a FrozenError when self is frozen" do
|
|
|
|
-> { "HeLlo".freeze.upcase! }.should raise_error(FrozenError)
|
|
|
|
-> { "HELLO".freeze.upcase! }.should raise_error(FrozenError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|