diff options
Diffstat (limited to 'spec/ruby/core/string/inspect_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/inspect_spec.rb | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/spec/ruby/core/string/inspect_spec.rb b/spec/ruby/core/string/inspect_spec.rb index 8ddbae132a..8b91ce2f84 100644 --- a/spec/ruby/core/string/inspect_spec.rb +++ b/spec/ruby/core/string/inspect_spec.rb @@ -3,20 +3,8 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "String#inspect" do - ruby_version_is ''...'2.7' do - it "taints the result if self is tainted" do - "foo".taint.inspect.tainted?.should == true - "foo\n".taint.inspect.tainted?.should == true - end - - it "untrusts the result if self is untrusted" do - "foo".untrust.inspect.untrusted?.should == true - "foo\n".untrust.inspect.untrusted?.should == true - end - end - it "does not return a subclass instance" do - StringSpecs::MyString.new.inspect.should be_an_instance_of(String) + StringSpecs::MyString.new.inspect.should.instance_of?(String) end it "returns a string with special characters replaced with \\<char> notation" do @@ -31,6 +19,21 @@ describe "String#inspect" do ].should be_computed_by(:inspect) end + it "returns a string with special characters replaced with \\<char> notation for UTF-16" do + pairs = [ + ["\a", '"\\a"'], + ["\b", '"\\b"'], + ["\t", '"\\t"'], + ["\n", '"\\n"'], + ["\v", '"\\v"'], + ["\f", '"\\f"'], + ["\r", '"\\r"'], + ["\e", '"\\e"'] + ].map { |str, result| [str.encode('UTF-16LE'), result] } + + pairs.should be_computed_by(:inspect) + end + it "returns a string with \" and \\ escaped with a backslash" do [ ["\"", '"\\""'], ["\\", '"\\\\"'] @@ -319,6 +322,15 @@ describe "String#inspect" do 0.chr.inspect.should == '"\\x00"' end + it "uses \\x notation for broken UTF-8 sequences" do + "\xF0\x9F".inspect.should == '"\\xF0\\x9F"' + end + + it "works for broken US-ASCII strings" do + s = "©".dup.force_encoding("US-ASCII") + s.inspect.should == '"\xC2\xA9"' + end + describe "when default external is UTF-8" do before :each do @extenc, Encoding.default_external = Encoding.default_external, Encoding::UTF_8 @@ -498,5 +510,11 @@ describe "String#inspect" do "\u{3042}".encode("EUC-JP").inspect.should == '"\\x{A4A2}"' end end + + describe "and the string has both ASCII-compatible and ASCII-incompatible chars" do + it "returns a string with the non-ASCII characters replaced by \\u notation" do + "hello привет".encode("utf-16le").inspect.should == '"hello \\u043F\\u0440\\u0438\\u0432\\u0435\\u0442"' + end + end end end |
