summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/dump_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string/dump_spec.rb')
-rw-r--r--spec/ruby/core/string/dump_spec.rb129
1 files changed, 43 insertions, 86 deletions
diff --git a/spec/ruby/core/string/dump_spec.rb b/spec/ruby/core/string/dump_spec.rb
index e67367b5b0..176be79db2 100644
--- a/spec/ruby/core/string/dump_spec.rb
+++ b/spec/ruby/core/string/dump_spec.rb
@@ -3,22 +3,12 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "String#dump" do
- it "taints the result if self is tainted" do
- "foo".taint.dump.tainted?.should == true
- "foo\n".taint.dump.tainted?.should == true
- end
-
- it "untrusts the result if self is untrusted" do
- "foo".untrust.dump.untrusted?.should == true
- "foo\n".untrust.dump.untrusted?.should == true
- end
-
it "does not take into account if a string is frozen" do
- "foo".freeze.dump.frozen?.should == false
+ "foo".freeze.dump.should_not.frozen?
end
- it "returns a subclass instance" do
- StringSpecs::MyString.new.dump.should be_an_instance_of(StringSpecs::MyString)
+ it "returns a String instance" do
+ StringSpecs::MyString.new.dump.should.instance_of?(String)
end
it "wraps string with \"" do
@@ -352,86 +342,53 @@ describe "String#dump" do
].should be_computed_by(:dump)
end
- ruby_version_is ''...'2.4' do
- it "returns a string with multi-byte UTF-8 characters replaced by \\u{} notation with lower-case hex digits" do
- [ [0200.chr('utf-8'), '"\u{80}"'],
- [0201.chr('utf-8'), '"\u{81}"'],
- [0202.chr('utf-8'), '"\u{82}"'],
- [0203.chr('utf-8'), '"\u{83}"'],
- [0204.chr('utf-8'), '"\u{84}"'],
- [0206.chr('utf-8'), '"\u{86}"'],
- [0207.chr('utf-8'), '"\u{87}"'],
- [0210.chr('utf-8'), '"\u{88}"'],
- [0211.chr('utf-8'), '"\u{89}"'],
- [0212.chr('utf-8'), '"\u{8a}"'],
- [0213.chr('utf-8'), '"\u{8b}"'],
- [0214.chr('utf-8'), '"\u{8c}"'],
- [0215.chr('utf-8'), '"\u{8d}"'],
- [0216.chr('utf-8'), '"\u{8e}"'],
- [0217.chr('utf-8'), '"\u{8f}"'],
- [0220.chr('utf-8'), '"\u{90}"'],
- [0221.chr('utf-8'), '"\u{91}"'],
- [0222.chr('utf-8'), '"\u{92}"'],
- [0223.chr('utf-8'), '"\u{93}"'],
- [0224.chr('utf-8'), '"\u{94}"'],
- [0225.chr('utf-8'), '"\u{95}"'],
- [0226.chr('utf-8'), '"\u{96}"'],
- [0227.chr('utf-8'), '"\u{97}"'],
- [0230.chr('utf-8'), '"\u{98}"'],
- [0231.chr('utf-8'), '"\u{99}"'],
- [0232.chr('utf-8'), '"\u{9a}"'],
- [0233.chr('utf-8'), '"\u{9b}"'],
- [0234.chr('utf-8'), '"\u{9c}"'],
- [0235.chr('utf-8'), '"\u{9d}"'],
- [0236.chr('utf-8'), '"\u{9e}"'],
- [0237.chr('utf-8'), '"\u{9f}"'],
- ].should be_computed_by(:dump)
- end
+ it "returns a string with multi-byte UTF-8 characters less than or equal 0xFFFF replaced by \\uXXXX notation with upper-case hex digits" do
+ [ [0200.chr('utf-8'), '"\u0080"'],
+ [0201.chr('utf-8'), '"\u0081"'],
+ [0202.chr('utf-8'), '"\u0082"'],
+ [0203.chr('utf-8'), '"\u0083"'],
+ [0204.chr('utf-8'), '"\u0084"'],
+ [0206.chr('utf-8'), '"\u0086"'],
+ [0207.chr('utf-8'), '"\u0087"'],
+ [0210.chr('utf-8'), '"\u0088"'],
+ [0211.chr('utf-8'), '"\u0089"'],
+ [0212.chr('utf-8'), '"\u008A"'],
+ [0213.chr('utf-8'), '"\u008B"'],
+ [0214.chr('utf-8'), '"\u008C"'],
+ [0215.chr('utf-8'), '"\u008D"'],
+ [0216.chr('utf-8'), '"\u008E"'],
+ [0217.chr('utf-8'), '"\u008F"'],
+ [0220.chr('utf-8'), '"\u0090"'],
+ [0221.chr('utf-8'), '"\u0091"'],
+ [0222.chr('utf-8'), '"\u0092"'],
+ [0223.chr('utf-8'), '"\u0093"'],
+ [0224.chr('utf-8'), '"\u0094"'],
+ [0225.chr('utf-8'), '"\u0095"'],
+ [0226.chr('utf-8'), '"\u0096"'],
+ [0227.chr('utf-8'), '"\u0097"'],
+ [0230.chr('utf-8'), '"\u0098"'],
+ [0231.chr('utf-8'), '"\u0099"'],
+ [0232.chr('utf-8'), '"\u009A"'],
+ [0233.chr('utf-8'), '"\u009B"'],
+ [0234.chr('utf-8'), '"\u009C"'],
+ [0235.chr('utf-8'), '"\u009D"'],
+ [0236.chr('utf-8'), '"\u009E"'],
+ [0237.chr('utf-8'), '"\u009F"'],
+ [0177777.chr('utf-8'), '"\uFFFF"'],
+ ].should be_computed_by(:dump)
end
- ruby_version_is '2.4' do
- it "returns a string with multi-byte UTF-8 characters replaced by \\u{} notation with upper-case hex digits" do
- [ [0200.chr('utf-8'), '"\u0080"'],
- [0201.chr('utf-8'), '"\u0081"'],
- [0202.chr('utf-8'), '"\u0082"'],
- [0203.chr('utf-8'), '"\u0083"'],
- [0204.chr('utf-8'), '"\u0084"'],
- [0206.chr('utf-8'), '"\u0086"'],
- [0207.chr('utf-8'), '"\u0087"'],
- [0210.chr('utf-8'), '"\u0088"'],
- [0211.chr('utf-8'), '"\u0089"'],
- [0212.chr('utf-8'), '"\u008A"'],
- [0213.chr('utf-8'), '"\u008B"'],
- [0214.chr('utf-8'), '"\u008C"'],
- [0215.chr('utf-8'), '"\u008D"'],
- [0216.chr('utf-8'), '"\u008E"'],
- [0217.chr('utf-8'), '"\u008F"'],
- [0220.chr('utf-8'), '"\u0090"'],
- [0221.chr('utf-8'), '"\u0091"'],
- [0222.chr('utf-8'), '"\u0092"'],
- [0223.chr('utf-8'), '"\u0093"'],
- [0224.chr('utf-8'), '"\u0094"'],
- [0225.chr('utf-8'), '"\u0095"'],
- [0226.chr('utf-8'), '"\u0096"'],
- [0227.chr('utf-8'), '"\u0097"'],
- [0230.chr('utf-8'), '"\u0098"'],
- [0231.chr('utf-8'), '"\u0099"'],
- [0232.chr('utf-8'), '"\u009A"'],
- [0233.chr('utf-8'), '"\u009B"'],
- [0234.chr('utf-8'), '"\u009C"'],
- [0235.chr('utf-8'), '"\u009D"'],
- [0236.chr('utf-8'), '"\u009E"'],
- [0237.chr('utf-8'), '"\u009F"'],
- ].should be_computed_by(:dump)
- end
+ it "returns a string with multi-byte UTF-8 characters greater than 0xFFFF replaced by \\u{XXXXXX} notation with upper-case hex digits" do
+ 0x10000.chr('utf-8').dump.should == '"\u{10000}"'
+ 0x10FFFF.chr('utf-8').dump.should == '"\u{10FFFF}"'
end
it "includes .force_encoding(name) if the encoding isn't ASCII compatible" do
- "\u{876}".encode('utf-16be').dump.end_with?(".force_encoding(\"UTF-16BE\")").should be_true
- "\u{876}".encode('utf-16le').dump.end_with?(".force_encoding(\"UTF-16LE\")").should be_true
+ "\u{876}".encode('utf-16be').dump.should.end_with?(".force_encoding(\"UTF-16BE\")")
+ "\u{876}".encode('utf-16le').dump.should.end_with?(".force_encoding(\"UTF-16LE\")")
end
- it "keeps origin encoding" do
+ it "returns a String in the same encoding as self" do
"foo".encode("ISO-8859-1").dump.encoding.should == Encoding::ISO_8859_1
"foo".encode('windows-1251').dump.encoding.should == Encoding::Windows_1251
1.chr.dump.encoding.should == Encoding::US_ASCII