diff options
Diffstat (limited to 'spec/ruby/core/string')
| -rw-r--r-- | spec/ruby/core/string/capitalize_spec.rb | 139 | ||||
| -rw-r--r-- | spec/ruby/core/string/casecmp_spec.rb | 20 | ||||
| -rw-r--r-- | spec/ruby/core/string/downcase_spec.rb | 139 | ||||
| -rw-r--r-- | spec/ruby/core/string/swapcase_spec.rb | 129 | ||||
| -rw-r--r-- | spec/ruby/core/string/upcase_spec.rb | 130 |
5 files changed, 532 insertions, 25 deletions
diff --git a/spec/ruby/core/string/capitalize_spec.rb b/spec/ruby/core/string/capitalize_spec.rb index e279f7d061..10f9ab00a1 100644 --- a/spec/ruby/core/string/capitalize_spec.rb +++ b/spec/ruby/core/string/capitalize_spec.rb @@ -26,8 +26,65 @@ describe "String#capitalize" do end ruby_version_is '2.4' do - it "works for all of Unicode" do - "äöü".capitalize.should == "Äöü" + describe "full Unicode case mapping" do + it "works for all of Unicode with no option" do + "äöÜ".capitalize.should == "Äöü" + end + + it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do + "ß".capitalize.should == "Ss" + end + + it "updates string metadata" do + capitalized = "ßeT".capitalize + + capitalized.should == "Sset" + capitalized.size.should == 4 + capitalized.bytesize.should == 4 + capitalized.ascii_only?.should be_true + end + end + + describe "ASCII-only case mapping" do + it "does not capitalize non-ASCII characters" do + "ßet".capitalize(:ascii).should == "ßet" + end + end + + describe "full Unicode case mapping adapted for Turkic languages" do + it "capitalizes ASCII characters according to Turkic semantics" do + "iSa".capitalize(:turkic).should == "İsa" + end + + it "allows Lithuanian as an extra option" do + "iSa".capitalize(:turkic, :lithuanian).should == "İsa" + end + + it "does not allow any other additional option" do + lambda { "iSa".capitalize(:turkic, :ascii) }.should raise_error(ArgumentError) + end + end + + describe "full Unicode case mapping adapted for Lithuanian" do + it "currently works the same as full Unicode case mapping" do + "iß".capitalize(:lithuanian).should == "Iß" + end + + it "allows Turkic as an extra option (and applies Turkic semantics)" do + "iß".capitalize(:lithuanian, :turkic).should == "İß" + end + + it "does not allow any other additional option" do + lambda { "iß".capitalize(:lithuanian, :ascii) }.should raise_error(ArgumentError) + end + end + + it "does not allow the :fold option for upcasing" do + lambda { "abc".capitalize(:fold) }.should raise_error(ArgumentError) + end + + it "does not allow invalid options" do + lambda { "abc".capitalize(:invalid_option) }.should raise_error(ArgumentError) end end @@ -45,10 +102,80 @@ describe "String#capitalize!" do end ruby_version_is '2.4' do - it "capitalizes self in place for all of Unicode" do - a = "äöü" - a.capitalize!.should equal(a) - a.should == "Äöü" + describe "full Unicode case mapping" do + it "modifies self in place for all of Unicode with no option" do + a = "äöÜ" + a.capitalize! + a.should == "Äöü" + end + + it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do + a = "ß" + a.capitalize! + a.should == "Ss" + end + + it "updates string metadata" do + capitalized = "ßeT" + capitalized.capitalize! + + capitalized.should == "Sset" + capitalized.size.should == 4 + capitalized.bytesize.should == 4 + capitalized.ascii_only?.should be_true + end + end + + describe "modifies self in place for ASCII-only case mapping" do + it "does not capitalize non-ASCII characters" do + a = "ßet" + a.capitalize!(:ascii) + a.should == "ßet" + end + end + + describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do + it "capitalizes ASCII characters according to Turkic semantics" do + a = "iSa" + a.capitalize!(:turkic) + a.should == "İsa" + end + + it "allows Lithuanian as an extra option" do + a = "iSa" + a.capitalize!(:turkic, :lithuanian) + a.should == "İsa" + end + + it "does not allow any other additional option" do + lambda { a = "iSa"; a.capitalize!(:turkic, :ascii) }.should raise_error(ArgumentError) + end + end + + 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.capitalize!(:lithuanian) + a.should == "Iß" + end + + it "allows Turkic as an extra option (and applies Turkic semantics)" do + a = "iß" + a.capitalize!(:lithuanian, :turkic) + a.should == "İß" + end + + it "does not allow any other additional option" do + lambda { a = "iß"; a.capitalize!(:lithuanian, :ascii) }.should raise_error(ArgumentError) + end + end + + it "does not allow the :fold option for upcasing" do + lambda { a = "abc"; a.capitalize!(:fold) }.should raise_error(ArgumentError) + end + + it "does not allow invalid options" do + lambda { a = "abc"; a.capitalize!(:invalid_option) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/string/casecmp_spec.rb b/spec/ruby/core/string/casecmp_spec.rb index 9e89e1314d..87be999964 100644 --- a/spec/ruby/core/string/casecmp_spec.rb +++ b/spec/ruby/core/string/casecmp_spec.rb @@ -37,6 +37,10 @@ describe "String#casecmp independent of case" do end end + it "returns nil if incompatible encodings" do + "あれ".casecmp("れ".encode(Encoding::EUC_JP)).should be_nil + end + describe "in UTF-8 mode" do describe "for non-ASCII characters" do before :each do @@ -96,6 +100,12 @@ describe "String#casecmp independent of case" do it "returns 1 when numerically greater than other" do @lower_a_tilde.casecmp(@upper_a_tilde).should == 1 end + + ruby_version_is "2.4" do + it "does not case fold" do + "ß".casecmp("ss").should == 1 + end + end end describe "when comparing a subclass instance" do @@ -138,6 +148,10 @@ ruby_version_is "2.4" do "abc".casecmp?(other).should == true end + it "returns nil if incompatible encodings" do + "あれ".casecmp?("れ".encode(Encoding::EUC_JP)).should be_nil + end + describe 'for UNICODE characters' do it 'returns true when downcase(:fold) on unicode' do 'äöü'.casecmp?('ÄÖÜ').should == true @@ -181,6 +195,12 @@ ruby_version_is "2.4" do end end + ruby_version_is "2.4" do + it "case folds" do + "ß".casecmp?("ss").should be_true + end + end + ruby_version_is "2.4" ... "2.5" do it "raises a TypeError if other can't be converted to a string" do lambda { "abc".casecmp?(mock('abc')) }.should raise_error(TypeError) diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb index 30116db5e6..9fb93902b1 100644 --- a/spec/ruby/core/string/downcase_spec.rb +++ b/spec/ruby/core/string/downcase_spec.rb @@ -23,8 +23,64 @@ describe "String#downcase" do end ruby_version_is '2.4' do - it "works for all of Unicode" do - "ÄÖÜ".downcase.should == "äöü" + 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 + + downcased.should == "king" + downcased.size.should == 4 + downcased.bytesize.should == 4 + downcased.ascii_only?.should be_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 + 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 "allows Lithuanian as an extra option" do + "İ".downcase(:turkic, :lithuanian).should == "i" + end + + it "does not allow any other additional option" do + lambda { "İ".downcase(:turkic, :ascii) }.should raise_error(ArgumentError) + end + 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 "allows Turkic as an extra option (and applies Turkic semantics)" do + "İS".downcase(:lithuanian, :turkic).should == "is" + end + + it "does not allow any other additional option" do + lambda { "İS".downcase(:lithuanian, :ascii) }.should raise_error(ArgumentError) + end + end + + describe "case folding" do + it "case folds special characters" do + "ß".downcase.should == "ß" + "ß".downcase(:fold).should == "ss" + end + end + + it "does not allow invalid options" do + lambda { "ABC".downcase(:invalid_option) }.should raise_error(ArgumentError) end end @@ -47,10 +103,81 @@ describe "String#downcase!" do end ruby_version_is '2.4' do - it "modifies self in place for all of Unicode" do - a = "ÄÖÜ" - a.downcase!.should equal(a) - a.should == "äöü" + 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! + + downcased.should == "king" + downcased.size.should == 4 + downcased.bytesize.should == 4 + downcased.ascii_only?.should be_true + end + 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 + 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 + + it "allows Lithuanian as an extra option" do + a = "İ" + a.downcase!(:turkic, :lithuanian) + a.should == "i" + end + + it "does not allow any other additional option" do + lambda { a = "İ"; a.downcase!(:turkic, :ascii) }.should raise_error(ArgumentError) + end + 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 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 + lambda { a = "İS"; a.downcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError) + end + end + + describe "case folding" do + it "case folds special characters" do + a = "ß" + a.downcase! + a.should == "ß" + + a.downcase!(:fold) + a.should == "ss" + end + end + + it "does not allow invalid options" do + lambda { a = "ABC"; a.downcase!(:invalid_option) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/string/swapcase_spec.rb b/spec/ruby/core/string/swapcase_spec.rb index 6d00906aad..bb89dee48f 100644 --- a/spec/ruby/core/string/swapcase_spec.rb +++ b/spec/ruby/core/string/swapcase_spec.rb @@ -23,8 +23,61 @@ describe "String#swapcase" do end ruby_version_is '2.4' do - it "works for all of Unicode" do - "äÖü".swapcase.should == "ÄöÜ" + describe "full Unicode case mapping" do + it "works for all of Unicode with no option" do + "äÖü".swapcase.should == "ÄöÜ" + end + + it "updates string metadata" do + swapcased = "Aßet".swapcase + + swapcased.should == "aSSET" + swapcased.size.should == 5 + swapcased.bytesize.should == 5 + swapcased.ascii_only?.should be_true + end + end + + describe "ASCII-only case mapping" do + it "does not swapcase non-ASCII characters" do + "aßet".swapcase(:ascii).should == "AßET" + end + end + + describe "full Unicode case mapping adapted for Turkic languages" do + it "swaps case of ASCII characters according to Turkic semantics" do + "aiS".swapcase(:turkic).should == "Aİs" + end + + it "allows Lithuanian as an extra option" do + "aiS".swapcase(:turkic, :lithuanian).should == "Aİs" + end + + it "does not allow any other additional option" do + lambda { "aiS".swapcase(:turkic, :ascii) }.should raise_error(ArgumentError) + end + end + + describe "full Unicode case mapping adapted for Lithuanian" do + it "currently works the same as full Unicode case mapping" do + "Iß".swapcase(:lithuanian).should == "iSS" + end + + it "allows Turkic as an extra option (and applies Turkic semantics)" do + "iS".swapcase(:lithuanian, :turkic).should == "İs" + end + + it "does not allow any other additional option" do + lambda { "aiS".swapcase(:lithuanian, :ascii) }.should raise_error(ArgumentError) + end + end + + it "does not allow the :fold option for upcasing" do + lambda { "abc".swapcase(:fold) }.should raise_error(ArgumentError) + end + + it "does not allow invalid options" do + lambda { "abc".swapcase(:invalid_option) }.should raise_error(ArgumentError) end end @@ -42,10 +95,74 @@ describe "String#swapcase!" do end ruby_version_is '2.4' do - it "modifies self in place for all of Unicode" do - a = "äÖü" - a.swapcase!.should equal(a) - a.should == "ÄöÜ" + describe "full Unicode case mapping" do + it "modifies self in place for all of Unicode with no option" do + a = "äÖü" + a.swapcase! + a.should == "ÄöÜ" + end + + it "updates string metadata" do + swapcased = "Aßet" + swapcased.swapcase! + + swapcased.should == "aSSET" + swapcased.size.should == 5 + swapcased.bytesize.should == 5 + swapcased.ascii_only?.should be_true + end + end + + describe "modifies self in place for ASCII-only case mapping" do + it "does not swapcase non-ASCII characters" do + a = "aßet" + a.swapcase!(:ascii) + a.should == "AßET" + end + end + + describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do + it "swaps case of ASCII characters according to Turkic semantics" do + a = "aiS" + a.swapcase!(:turkic) + a.should == "Aİs" + end + + it "allows Lithuanian as an extra option" do + a = "aiS" + a.swapcase!(:turkic, :lithuanian) + a.should == "Aİs" + end + + it "does not allow any other additional option" do + lambda { a = "aiS"; a.swapcase!(:turkic, :ascii) }.should raise_error(ArgumentError) + end + end + + describe "full Unicode case mapping adapted for Lithuanian" do + it "currently works the same as full Unicode case mapping" do + a = "Iß" + a.swapcase!(:lithuanian) + a.should == "iSS" + end + + it "allows Turkic as an extra option (and applies Turkic semantics)" do + a = "iS" + a.swapcase!(:lithuanian, :turkic) + a.should == "İs" + end + + it "does not allow any other additional option" do + lambda { a = "aiS"; a.swapcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError) + end + end + + it "does not allow the :fold option for upcasing" do + lambda { a = "abc"; a.swapcase!(:fold) }.should raise_error(ArgumentError) + end + + it "does not allow invalid options" do + lambda { a = "abc"; a.swapcase!(:invalid_option) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/string/upcase_spec.rb b/spec/ruby/core/string/upcase_spec.rb index 001cf1f495..347f567be9 100644 --- a/spec/ruby/core/string/upcase_spec.rb +++ b/spec/ruby/core/string/upcase_spec.rb @@ -23,8 +23,61 @@ describe "String#upcase" do end ruby_version_is '2.4' do - it "works for all of Unicode" do - "äöü".upcase.should == "ÄÖÜ" + describe "full Unicode case mapping" do + it "works for all of Unicode with no option" do + "äöü".upcase.should == "ÄÖÜ" + end + + it "updates string metadata" do + upcased = "aßet".upcase + + upcased.should == "ASSET" + upcased.size.should == 5 + upcased.bytesize.should == 5 + upcased.ascii_only?.should be_true + end + end + + describe "ASCII-only case mapping" do + it "does not upcase non-ASCII characters" do + "aßet".upcase(:ascii).should == "AßET" + end + end + + describe "full Unicode case mapping adapted for Turkic languages" do + it "upcases ASCII characters according to Turkic semantics" do + "i".upcase(:turkic).should == "İ" + end + + it "allows Lithuanian as an extra option" do + "i".upcase(:turkic, :lithuanian).should == "İ" + end + + it "does not allow any other additional option" do + lambda { "i".upcase(:turkic, :ascii) }.should raise_error(ArgumentError) + end + end + + 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" + end + + it "allows Turkic as an extra option (and applies Turkic semantics)" do + "iß".upcase(:lithuanian, :turkic).should == "İSS" + end + + it "does not allow any other additional option" do + lambda { "iß".upcase(:lithuanian, :ascii) }.should raise_error(ArgumentError) + end + end + + it "does not allow the :fold option for upcasing" do + lambda { "abc".upcase(:fold) }.should raise_error(ArgumentError) + end + + it "does not allow invalid options" do + lambda { "abc".upcase(:invalid_option) }.should raise_error(ArgumentError) end end @@ -46,12 +99,75 @@ describe "String#upcase!" do a.should == "HELLO" end - ruby_version_is '2.4' do - it "modifies self in place for all of Unicode" do - a = "äöü" - a.upcase!.should equal(a) - a.should == "ÄÖÜ" + 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 + + it "updates string metadata for self" do + upcased = "aßet" + upcased.upcase! + + upcased.should == "ASSET" + upcased.size.should == 5 + upcased.bytesize.should == 5 + upcased.ascii_only?.should be_true + end + end + + 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" + end + end + + 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 == "İ" + end + + it "allows Lithuanian as an extra option" do + a = "i" + a.upcase!(:turkic, :lithuanian) + a.should == "İ" + end + + it "does not allow any other additional option" do + lambda { a = "i"; a.upcase!(:turkic, :ascii) }.should raise_error(ArgumentError) + end + end + + 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" + end + + it "allows Turkic as an extra option (and applies Turkic semantics)" do + a = "iß" + a.upcase!(:lithuanian, :turkic) + a.should == "İSS" + end + + it "does not allow any other additional option" do + lambda { a = "iß"; a.upcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError) + end + end + + it "does not allow the :fold option for upcasing" do + lambda { a = "abc"; a.upcase!(:fold) }.should raise_error(ArgumentError) + end + + it "does not allow invalid options" do + lambda { a = "abc"; a.upcase!(:invalid_option) }.should raise_error(ArgumentError) end end |
