diff options
author | Benoit Daloze <eregontp@gmail.com> | 2020-01-28 20:47:48 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2020-01-28 20:47:48 +0100 |
commit | 809f0b8a1357f14f9645210d4812f4400c8d397e (patch) | |
tree | 7ce6192f94b1dc4b004798aa5d0c4d6bac02577f /spec/ruby/core/string | |
parent | ed377cc9aaf1ccbede19ddc6c464f5fbf3cabc34 (diff) |
Update to ruby/spec@f8a2d54
Diffstat (limited to 'spec/ruby/core/string')
-rw-r--r-- | spec/ruby/core/string/capitalize_spec.rb | 18 | ||||
-rw-r--r-- | spec/ruby/core/string/downcase_spec.rb | 12 | ||||
-rw-r--r-- | spec/ruby/core/string/shared/length.rb | 13 | ||||
-rw-r--r-- | spec/ruby/core/string/split_spec.rb | 18 | ||||
-rw-r--r-- | spec/ruby/core/string/swapcase_spec.rb | 18 | ||||
-rw-r--r-- | spec/ruby/core/string/upcase_spec.rb | 18 |
6 files changed, 97 insertions, 0 deletions
diff --git a/spec/ruby/core/string/capitalize_spec.rb b/spec/ruby/core/string/capitalize_spec.rb index 41dd63f63e..376db3aa72 100644 --- a/spec/ruby/core/string/capitalize_spec.rb +++ b/spec/ruby/core/string/capitalize_spec.rb @@ -93,6 +93,12 @@ describe "String#capitalize!" do a.should == "Hello" end + it "modifies self in place for non-ascii-compatible encodings" do + a = "heLLo".encode("utf-16le") + a.capitalize! + 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 = "äöÜ" @@ -106,6 +112,12 @@ describe "String#capitalize!" do a.should == "Ss" end + it "works for non-ascii-compatible encodings" do + a = "äöü".encode("utf-16le") + a.capitalize! + a.should == "Äöü".encode("utf-16le") + end + it "updates string metadata" do capitalized = "ßeT" capitalized.capitalize! @@ -123,6 +135,12 @@ describe "String#capitalize!" do a.capitalize!(:ascii) a.should == "ßet" end + + it "works for non-ascii-compatible encodings" do + a = "aBc".encode("utf-16le") + a.capitalize!(:ascii) + a.should == "Abc".encode("utf-16le") + end end describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb index 84e94ee104..a78b6de373 100644 --- a/spec/ruby/core/string/downcase_spec.rb +++ b/spec/ruby/core/string/downcase_spec.rb @@ -88,6 +88,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 = "ÄÖÜ" @@ -112,6 +118,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 diff --git a/spec/ruby/core/string/shared/length.rb b/spec/ruby/core/string/shared/length.rb index f387fb251c..b9eae5170f 100644 --- a/spec/ruby/core/string/shared/length.rb +++ b/spec/ruby/core/string/shared/length.rb @@ -23,4 +23,17 @@ describe :string_length, shared: true do str.force_encoding('BINARY').send(@method).should == 12 end + + it "returns the correct length after force_encoding(BINARY)" do + utf8 = "あ" + ascii = "a" + concat = utf8 + ascii + + concat.encoding.should == Encoding::UTF_8 + concat.bytesize.should == 4 + + concat.size.should == 2 + concat.force_encoding(Encoding::ASCII_8BIT) + concat.size.should == 4 + end end diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb index cfb030ad8d..8a740b04ca 100644 --- a/spec/ruby/core/string/split_spec.rb +++ b/spec/ruby/core/string/split_spec.rb @@ -84,6 +84,24 @@ describe "String#split with String" do $; = old_fs end end + + ruby_version_is "2.7" do + context "when $; is not nil" do + before do + suppress_warning do + @old_value, $; = $;, 'foobar' + end + end + + after do + $; = @old_value + end + + it "warns" do + -> { "".split }.should complain(/warning: \$; is set to non-nil value/) + end + end + end end it "ignores leading and continuous whitespace when string is a single space" do diff --git a/spec/ruby/core/string/swapcase_spec.rb b/spec/ruby/core/string/swapcase_spec.rb index c1a1608a81..b5d9b20451 100644 --- a/spec/ruby/core/string/swapcase_spec.rb +++ b/spec/ruby/core/string/swapcase_spec.rb @@ -86,6 +86,12 @@ describe "String#swapcase!" do a.should == "CyBeR_pUnK11" end + it "modifies self in place for non-ascii-compatible encodings" do + a = "cYbEr_PuNk11".encode("utf-16le") + a.swapcase! + a.should == "CyBeR_pUnK11".encode("utf-16le") + end + describe "full Unicode case mapping" do it "modifies self in place for all of Unicode with no option" do a = "äÖü" @@ -93,6 +99,12 @@ describe "String#swapcase!" do a.should == "ÄöÜ" end + it "works for non-ascii-compatible encodings" do + a = "äÖü".encode("utf-16le") + a.swapcase! + a.should == "ÄöÜ".encode("utf-16le") + end + it "updates string metadata" do swapcased = "Aßet" swapcased.swapcase! @@ -110,6 +122,12 @@ describe "String#swapcase!" do a.swapcase!(:ascii) a.should == "AßET" end + + it "works for non-ascii-compatible encodings" do + a = "aBc".encode("utf-16le") + a.swapcase!(:ascii) + a.should == "AbC".encode("utf-16le") + end end describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do diff --git a/spec/ruby/core/string/upcase_spec.rb b/spec/ruby/core/string/upcase_spec.rb index eb7d708fe0..4857079a84 100644 --- a/spec/ruby/core/string/upcase_spec.rb +++ b/spec/ruby/core/string/upcase_spec.rb @@ -85,6 +85,12 @@ describe "String#upcase!" do a.should == "HELLO" end + 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 + describe "full Unicode case mapping" do it "modifies self in place for all of Unicode with no option" do a = "äöü" @@ -92,6 +98,12 @@ describe "String#upcase!" do a.should == "ÄÖÜ" end + it "works for non-ascii-compatible encodings" do + a = "äöü".encode("utf-16le") + a.upcase! + a.should == "ÄÖÜ".encode("utf-16le") + end + it "updates string metadata for self" do upcased = "aßet" upcased.upcase! @@ -109,6 +121,12 @@ describe "String#upcase!" do a.upcase!(:ascii) a.should == "AßET" end + + it "works for non-ascii-compatible encodings" do + a = "abc".encode("utf-16le") + a.upcase!(:ascii) + a.should == "ABC".encode("utf-16le") + end end describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do |