summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/shared
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string/shared')
-rw-r--r--spec/ruby/core/string/shared/eql.rb2
-rw-r--r--spec/ruby/core/string/shared/length.rb16
2 files changed, 17 insertions, 1 deletions
diff --git a/spec/ruby/core/string/shared/eql.rb b/spec/ruby/core/string/shared/eql.rb
index 85b861f4f1..b57d6895ff 100644
--- a/spec/ruby/core/string/shared/eql.rb
+++ b/spec/ruby/core/string/shared/eql.rb
@@ -21,7 +21,7 @@ describe :string_eql_value, shared: true do
end
it "considers encoding compatibility" do
- "hello".force_encoding("utf-8").send(@method, "hello".force_encoding("utf-32le")).should be_false
+ "abcd".force_encoding("utf-8").send(@method, "abcd".force_encoding("utf-32le")).should be_false
end
it "ignores subclass differences" do
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