summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/shared/length.rb
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2021-11-29 15:50:28 +0100
committerBenoit Daloze <eregontp@gmail.com>2021-11-29 15:50:28 +0100
commit67a1e2258974df4b597d019739595c18fbb9a7c1 (patch)
tree992ad4fc0fc08a6af8f04373703a339f957eb143 /spec/ruby/core/string/shared/length.rb
parente6d93a27afa058319e6dad093bbef637e49fce47 (diff)
Update to ruby/spec@7f22a0b
Diffstat (limited to 'spec/ruby/core/string/shared/length.rb')
-rw-r--r--spec/ruby/core/string/shared/length.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/spec/ruby/core/string/shared/length.rb b/spec/ruby/core/string/shared/length.rb
index b9eae5170f..e931961455 100644
--- a/spec/ruby/core/string/shared/length.rb
+++ b/spec/ruby/core/string/shared/length.rb
@@ -36,4 +36,20 @@ describe :string_length, shared: true do
concat.force_encoding(Encoding::ASCII_8BIT)
concat.size.should == 4
end
+
+ it "adds 1 for every invalid byte in UTF-8" do
+ "\xF4\x90\x80\x80".size.should == 4
+ "a\xF4\x90\x80\x80b".size.should == 6
+ "é\xF4\x90\x80\x80è".size.should == 6
+ end
+
+ it "adds 1 (and not 2) for a incomplete surrogate in UTF-16" do
+ "\x00\xd8".force_encoding("UTF-16LE").size.should == 1
+ "\xd8\x00".force_encoding("UTF-16BE").size.should == 1
+ end
+
+ it "adds 1 for a broken sequence in UTF-32" do
+ "\x04\x03\x02\x01".force_encoding("UTF-32LE").size.should == 1
+ "\x01\x02\x03\x04".force_encoding("UTF-32BE").size.should == 1
+ end
end