From d80e44deec77678fe2d72f94c17b2409b3e794d5 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 27 Jun 2019 21:02:36 +0200 Subject: Update to ruby/spec@8d74d49 --- spec/ruby/core/string/ascii_only_spec.rb | 4 ++-- spec/ruby/core/string/b_spec.rb | 6 +++--- spec/ruby/core/string/bytesize_spec.rb | 2 -- spec/ruby/core/string/element_set_spec.rb | 20 +++++++++--------- spec/ruby/core/string/encode_spec.rb | 10 +++++++-- spec/ruby/core/string/encoding_spec.rb | 8 ++++---- spec/ruby/core/string/force_encoding_spec.rb | 4 ++-- spec/ruby/core/string/gsub_spec.rb | 8 ++++---- spec/ruby/core/string/modulo_spec.rb | 4 ++-- spec/ruby/core/string/shared/chars.rb | 2 +- spec/ruby/core/string/shared/concat.rb | 12 +++++------ spec/ruby/core/string/shared/encode.rb | 28 +++++++++++++------------- spec/ruby/core/string/shared/length.rb | 2 +- spec/ruby/core/string/undump_spec.rb | 2 +- spec/ruby/core/string/unpack/a_spec.rb | 6 +++--- spec/ruby/core/string/unpack/at_spec.rb | 2 +- spec/ruby/core/string/unpack/b_spec.rb | 2 +- spec/ruby/core/string/unpack/c_spec.rb | 2 +- spec/ruby/core/string/unpack/comment_spec.rb | 2 +- spec/ruby/core/string/unpack/h_spec.rb | 10 ++++++++- spec/ruby/core/string/unpack/m_spec.rb | 2 +- spec/ruby/core/string/unpack/shared/float.rb | 2 +- spec/ruby/core/string/unpack/shared/integer.rb | 2 +- spec/ruby/core/string/unpack/u_spec.rb | 6 +++--- spec/ruby/core/string/unpack/w_spec.rb | 2 +- spec/ruby/core/string/unpack/x_spec.rb | 2 +- spec/ruby/core/string/unpack/z_spec.rb | 2 +- spec/ruby/core/string/valid_encoding_spec.rb | 4 ++-- 28 files changed, 85 insertions(+), 73 deletions(-) (limited to 'spec/ruby/core/string') diff --git a/spec/ruby/core/string/ascii_only_spec.rb b/spec/ruby/core/string/ascii_only_spec.rb index e9f2dc1a36..c7e02fd874 100644 --- a/spec/ruby/core/string/ascii_only_spec.rb +++ b/spec/ruby/core/string/ascii_only_spec.rb @@ -24,9 +24,9 @@ describe "String#ascii_only?" do end describe "with non-ASCII only characters" do - it "returns false if the encoding is ASCII-8BIT" do + it "returns false if the encoding is BINARY" do chr = 128.chr - chr.encoding.should == Encoding::ASCII_8BIT + chr.encoding.should == Encoding::BINARY chr.ascii_only?.should be_false end diff --git a/spec/ruby/core/string/b_spec.rb b/spec/ruby/core/string/b_spec.rb index 638971f9ce..8555dd8dc7 100644 --- a/spec/ruby/core/string/b_spec.rb +++ b/spec/ruby/core/string/b_spec.rb @@ -2,9 +2,9 @@ require_relative '../../spec_helper' describe "String#b" do - it "returns an ASCII-8BIT encoded string" do - "Hello".b.should == "Hello".force_encoding(Encoding::ASCII_8BIT) - "こんちには".b.should == "こんちには".force_encoding(Encoding::ASCII_8BIT) + it "returns an BINARY encoded string" do + "Hello".b.should == "Hello".force_encoding(Encoding::BINARY) + "こんちには".b.should == "こんちには".force_encoding(Encoding::BINARY) end it "returns new string without modifying self" do diff --git a/spec/ruby/core/string/bytesize_spec.rb b/spec/ruby/core/string/bytesize_spec.rb index b63d718c6c..b8b07cfbec 100644 --- a/spec/ruby/core/string/bytesize_spec.rb +++ b/spec/ruby/core/string/bytesize_spec.rb @@ -3,8 +3,6 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' describe "#String#bytesize" do - it "needs to be reviewed for spec completeness" - it "returns the length of self in bytes" do "hello".bytesize.should == 5 " ".bytesize.should == 1 diff --git a/spec/ruby/core/string/element_set_spec.rb b/spec/ruby/core/string/element_set_spec.rb index f85256d36e..1fdf72ab0f 100644 --- a/spec/ruby/core/string/element_set_spec.rb +++ b/spec/ruby/core/string/element_set_spec.rb @@ -134,9 +134,9 @@ describe "String#[]= with Fixnum index" do it "encodes the String in an encoding compatible with the replacement" do str = " ".force_encoding Encoding::US_ASCII - rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT + rep = [160].pack('C').force_encoding Encoding::BINARY str[0] = rep - str.encoding.should equal(Encoding::ASCII_8BIT) + str.encoding.should equal(Encoding::BINARY) end it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do @@ -190,9 +190,9 @@ describe "String#[]= with String index" do it "encodes the String in an encoding compatible with the replacement" do str = " ".force_encoding Encoding::US_ASCII - rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT + rep = [160].pack('C').force_encoding Encoding::BINARY str[" "] = rep - str.encoding.should equal(Encoding::ASCII_8BIT) + str.encoding.should equal(Encoding::BINARY) end it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do @@ -303,9 +303,9 @@ describe "String#[]= with a Regexp index" do it "encodes the String in an encoding compatible with the replacement" do str = " ".force_encoding Encoding::US_ASCII - rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT + rep = [160].pack('C').force_encoding Encoding::BINARY str[/ /] = rep - str.encoding.should equal(Encoding::ASCII_8BIT) + str.encoding.should equal(Encoding::BINARY) end it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do @@ -424,9 +424,9 @@ describe "String#[]= with a Range index" do it "encodes the String in an encoding compatible with the replacement" do str = " ".force_encoding Encoding::US_ASCII - rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT + rep = [160].pack('C').force_encoding Encoding::BINARY str[0..1] = rep - str.encoding.should equal(Encoding::ASCII_8BIT) + str.encoding.should equal(Encoding::BINARY) end it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do @@ -589,9 +589,9 @@ describe "String#[]= with Fixnum index, count" do it "encodes the String in an encoding compatible with the replacement" do str = " ".force_encoding Encoding::US_ASCII - rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT + rep = [160].pack('C').force_encoding Encoding::BINARY str[0, 1] = rep - str.encoding.should equal(Encoding::ASCII_8BIT) + str.encoding.should equal(Encoding::BINARY) end it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do diff --git a/spec/ruby/core/string/encode_spec.rb b/spec/ruby/core/string/encode_spec.rb index 0be26011ea..67a25aff04 100644 --- a/spec/ruby/core/string/encode_spec.rb +++ b/spec/ruby/core/string/encode_spec.rb @@ -30,7 +30,7 @@ describe "String#encode" do it "encodes an ascii substring of a binary string to UTF-8" do x82 = [0x82].pack('C') - str = "#{x82}foo".force_encoding("ascii-8bit")[1..-1].encode("utf-8") + str = "#{x82}foo".force_encoding("binary")[1..-1].encode("utf-8") str.should == "foo".force_encoding("utf-8") str.encoding.should equal(Encoding::UTF_8) end @@ -60,12 +60,18 @@ describe "String#encode" do "\rfoo".encode(universal_newline: true).should == "\nfoo" end + + it "replaces invalid encoding" do + encoded = "ち\xE3\x81\xFF".encode("UTF-16LE", invalid: :replace, replace: "?") + encoded.should == "\u3061??".encode("UTF-16LE") + encoded.encode("UTF-8").should == "ち??" + end end describe "when passed to, from" do it "returns a copy in the destination encoding when both encodings are the same" do str = "あ" - str.force_encoding("ascii-8bit") + str.force_encoding("binary") encoded = str.encode("utf-8", "utf-8") encoded.should_not equal(str) diff --git a/spec/ruby/core/string/encoding_spec.rb b/spec/ruby/core/string/encoding_spec.rb index 6182e8eb50..4d17a39f29 100644 --- a/spec/ruby/core/string/encoding_spec.rb +++ b/spec/ruby/core/string/encoding_spec.rb @@ -125,13 +125,13 @@ describe "String#encoding for Strings with \\x escapes" do s.encoding.should == Encoding::US_ASCII end - it "returns ASCII-8BIT when an escape creates a byte with the 8th bit set if the source encoding is US-ASCII" do + it "returns BINARY when an escape creates a byte with the 8th bit set if the source encoding is US-ASCII" do __ENCODING__.should == Encoding::US_ASCII str = " " str.encoding.should == Encoding::US_ASCII str += [0xDF].pack('C') str.ascii_only?.should be_false - str.encoding.should == Encoding::ASCII_8BIT + str.encoding.should == Encoding::BINARY end # TODO: Deal with case when the byte in question isn't valid in the source @@ -155,7 +155,7 @@ describe "String#encoding for Strings with \\x escapes" do default_external = Encoding.default_external Encoding.default_external = Encoding::SHIFT_JIS "\x50".encoding.should == Encoding::US_ASCII - [0xD4].pack('C').encoding.should == Encoding::ASCII_8BIT + [0xD4].pack('C').encoding.should == Encoding::BINARY Encoding.default_external = default_external end @@ -166,7 +166,7 @@ describe "String#encoding for Strings with \\x escapes" do Encoding.default_external = Encoding::SHIFT_JIS x50 = "\x50" x50.encoding.should == Encoding::US_ASCII - [0xD4].pack('C').encoding.should == Encoding::ASCII_8BIT + [0xD4].pack('C').encoding.should == Encoding::BINARY Encoding.default_external = default_external Encoding.default_internal = default_internal end diff --git a/spec/ruby/core/string/force_encoding_spec.rb b/spec/ruby/core/string/force_encoding_spec.rb index 83641a37b4..7a5503de56 100644 --- a/spec/ruby/core/string/force_encoding_spec.rb +++ b/spec/ruby/core/string/force_encoding_spec.rb @@ -19,9 +19,9 @@ describe "String#force_encoding" do "abc".force_encoding("internal").encoding.should == Encoding::US_ASCII end - it "defaults to ASCII-8BIT if special encoding name is not set" do + it "defaults to BINARY if special encoding name is not set" do Encoding.default_internal = nil - "abc".force_encoding("internal").encoding.should == Encoding::ASCII_8BIT + "abc".force_encoding("internal").encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/core/string/gsub_spec.rb b/spec/ruby/core/string/gsub_spec.rb index a94010edea..29b65c72a7 100644 --- a/spec/ruby/core/string/gsub_spec.rb +++ b/spec/ruby/core/string/gsub_spec.rb @@ -528,8 +528,8 @@ describe "String#gsub with pattern and block" do s = "hello" s2 = "#{195.chr}#{192.chr}#{195.chr}" - s.gsub(/l/) { |bar| 195.chr }.encoding.should == Encoding::ASCII_8BIT - s2.gsub("#{192.chr}") { |bar| "hello" }.encoding.should == Encoding::ASCII_8BIT + s.gsub(/l/) { |bar| 195.chr }.encoding.should == Encoding::BINARY + s2.gsub("#{192.chr}") { |bar| "hello" }.encoding.should == Encoding::BINARY end it "raises an Encoding::CompatibilityError if the encodings are not compatible" do @@ -653,8 +653,8 @@ describe "String#gsub! with pattern and block" do s = "hello" s2 = "#{195.chr}#{192.chr}#{195.chr}" - s.gsub!(/l/) { |bar| 195.chr }.encoding.should == Encoding::ASCII_8BIT - s2.gsub!("#{192.chr}") { |bar| "hello" }.encoding.should == Encoding::ASCII_8BIT + s.gsub!(/l/) { |bar| 195.chr }.encoding.should == Encoding::BINARY + s2.gsub!("#{192.chr}") { |bar| "hello" }.encoding.should == Encoding::BINARY end it "raises an Encoding::CompatibilityError if the encodings are not compatible" do diff --git a/spec/ruby/core/string/modulo_spec.rb b/spec/ruby/core/string/modulo_spec.rb index 72738ece24..fc4972b9d7 100644 --- a/spec/ruby/core/string/modulo_spec.rb +++ b/spec/ruby/core/string/modulo_spec.rb @@ -21,13 +21,13 @@ describe "String#%" do describe "output's encoding" do it "is the same as the format string if passed value is encoding-compatible" do - [Encoding::ASCII_8BIT, Encoding::US_ASCII, Encoding::UTF_8, Encoding::SHIFT_JIS].each do |encoding| + [Encoding::BINARY, Encoding::US_ASCII, Encoding::UTF_8, Encoding::SHIFT_JIS].each do |encoding| ("hello %s!".encode(encoding) % "world").encoding.should == encoding end end it "negotiates a compatible encoding if necessary" do - ("hello %s" % 195.chr).encoding.should == Encoding::ASCII_8BIT + ("hello %s" % 195.chr).encoding.should == Encoding::BINARY ("hello %s".encode("shift_jis") % "wörld").encoding.should == Encoding::UTF_8 end diff --git a/spec/ruby/core/string/shared/chars.rb b/spec/ruby/core/string/shared/chars.rb index d37bc50675..c8716521bd 100644 --- a/spec/ruby/core/string/shared/chars.rb +++ b/spec/ruby/core/string/shared/chars.rb @@ -22,7 +22,7 @@ describe :string_chars, shared: true do it "returns characters in the same encoding as self" do "&%".force_encoding('Shift_JIS').send(@method).to_a.all? {|c| c.encoding.name.should == 'Shift_JIS'} - "&%".encode('ASCII-8BIT').send(@method).to_a.all? {|c| c.encoding.name.should == 'ASCII-8BIT'} + "&%".encode('BINARY').send(@method).to_a.all? {|c| c.encoding.should == Encoding::BINARY } end it "works with multibyte characters" do diff --git a/spec/ruby/core/string/shared/concat.rb b/spec/ruby/core/string/shared/concat.rb index bc38ba9a8b..0a87410f2f 100644 --- a/spec/ruby/core/string/shared/concat.rb +++ b/spec/ruby/core/string/shared/concat.rb @@ -60,13 +60,13 @@ describe :string_concat, shared: true do end # #5855 - it "returns a ASCII-8BIT string if self is US-ASCII and the argument is between 128-255 (inclusive)" do + it "returns a BINARY string if self is US-ASCII and the argument is between 128-255 (inclusive)" do a = ("".encode(Encoding::US_ASCII).send(@method, 128)) - a.encoding.should == Encoding::ASCII_8BIT + a.encoding.should == Encoding::BINARY a.should == 128.chr a = ("".encode(Encoding::US_ASCII).send(@method, 255)) - a.encoding.should == Encoding::ASCII_8BIT + a.encoding.should == Encoding::BINARY a.should == 255.chr end @@ -152,9 +152,9 @@ describe :string_concat_encoding, shared: true do end end - describe "when self is ASCII-8BIT and argument is US-ASCII" do - it "uses ASCII-8BIT encoding" do - "abc".encode("ASCII-8BIT").send(@method, "123".encode("US-ASCII")).encoding.should == Encoding::ASCII_8BIT + describe "when self is BINARY and argument is US-ASCII" do + it "uses BINARY encoding" do + "abc".encode("BINARY").send(@method, "123".encode("US-ASCII")).encoding.should == Encoding::BINARY end end end diff --git a/spec/ruby/core/string/shared/encode.rb b/spec/ruby/core/string/shared/encode.rb index 71d46b1bd3..d13db1945e 100644 --- a/spec/ruby/core/string/shared/encode.rb +++ b/spec/ruby/core/string/shared/encode.rb @@ -9,18 +9,18 @@ describe :string_encode, shared: true do it "transcodes a 7-bit String despite no generic converting being available" do lambda do - Encoding::Converter.new Encoding::Emacs_Mule, Encoding::ASCII_8BIT + Encoding::Converter.new Encoding::Emacs_Mule, Encoding::BINARY end.should raise_error(Encoding::ConverterNotFoundError) Encoding.default_internal = Encoding::Emacs_Mule - str = "\x79".force_encoding Encoding::ASCII_8BIT + str = "\x79".force_encoding Encoding::BINARY - str.send(@method).should == "y".force_encoding(Encoding::ASCII_8BIT) + str.send(@method).should == "y".force_encoding(Encoding::BINARY) end it "raises an Encoding::ConverterNotFoundError when no conversion is possible" do Encoding.default_internal = Encoding::Emacs_Mule - str = [0x80].pack('C').force_encoding Encoding::ASCII_8BIT + str = [0x80].pack('C').force_encoding Encoding::BINARY lambda { str.send(@method) }.should raise_error(Encoding::ConverterNotFoundError) end end @@ -52,15 +52,15 @@ describe :string_encode, shared: true do it "transcodes a 7-bit String despite no generic converting being available" do lambda do - Encoding::Converter.new Encoding::Emacs_Mule, Encoding::ASCII_8BIT + Encoding::Converter.new Encoding::Emacs_Mule, Encoding::BINARY end.should raise_error(Encoding::ConverterNotFoundError) - str = "\x79".force_encoding Encoding::ASCII_8BIT - str.send(@method, Encoding::Emacs_Mule).should == "y".force_encoding(Encoding::ASCII_8BIT) + str = "\x79".force_encoding Encoding::BINARY + str.send(@method, Encoding::Emacs_Mule).should == "y".force_encoding(Encoding::BINARY) end it "raises an Encoding::ConverterNotFoundError when no conversion is possible" do - str = [0x80].pack('C').force_encoding Encoding::ASCII_8BIT + str = [0x80].pack('C').force_encoding Encoding::BINARY lambda do str.send(@method, Encoding::Emacs_Mule) end.should raise_error(Encoding::ConverterNotFoundError) @@ -95,7 +95,7 @@ describe :string_encode, shared: true do it "raises an Encoding::ConverterNotFoundError when no conversion is possible despite 'invalid: :replace, undef: :replace'" do Encoding.default_internal = Encoding::Emacs_Mule - str = [0x80].pack('C').force_encoding Encoding::ASCII_8BIT + str = [0x80].pack('C').force_encoding Encoding::BINARY lambda do str.send(@method, invalid: :replace, undef: :replace) end.should raise_error(Encoding::ConverterNotFoundError) @@ -153,7 +153,7 @@ describe :string_encode, shared: true do describe "when passed to, from, options" do it "replaces undefined characters in the destination encoding" do - str = "あ?あ".force_encoding Encoding::ASCII_8BIT + str = "あ?あ".force_encoding Encoding::BINARY result = str.send(@method, "euc-jp", "utf-8", undef: :replace) xA4xA2 = [0xA4, 0xA2].pack('CC').force_encoding('utf-8') result.should == "#{xA4xA2}?#{xA4xA2}".force_encoding("euc-jp") @@ -161,7 +161,7 @@ describe :string_encode, shared: true do it "replaces invalid characters in the destination encoding" do xFF = [0xFF].pack('C').force_encoding('utf-8') - str = "ab#{xFF}c".force_encoding Encoding::ASCII_8BIT + str = "ab#{xFF}c".force_encoding Encoding::BINARY str.send(@method, "iso-8859-1", "utf-8", invalid: :replace).should == "ab?c" end @@ -170,7 +170,7 @@ describe :string_encode, shared: true do to.should_receive(:to_str).and_return("iso-8859-1") xFF = [0xFF].pack('C').force_encoding('utf-8') - str = "ab#{xFF}c".force_encoding Encoding::ASCII_8BIT + str = "ab#{xFF}c".force_encoding Encoding::BINARY str.send(@method, to, "utf-8", invalid: :replace).should == "ab?c" end @@ -179,7 +179,7 @@ describe :string_encode, shared: true do from.should_receive(:to_str).and_return("utf-8") xFF = [0xFF].pack('C').force_encoding('utf-8') - str = "ab#{xFF}c".force_encoding Encoding::ASCII_8BIT + str = "ab#{xFF}c".force_encoding Encoding::BINARY str.send(@method, "iso-8859-1", from, invalid: :replace).should == "ab?c" end @@ -188,7 +188,7 @@ describe :string_encode, shared: true do options.should_receive(:to_hash).and_return({ invalid: :replace }) xFF = [0xFF].pack('C').force_encoding('utf-8') - str = "ab#{xFF}c".force_encoding Encoding::ASCII_8BIT + str = "ab#{xFF}c".force_encoding Encoding::BINARY str.send(@method, "iso-8859-1", "utf-8", options).should == "ab?c" end end diff --git a/spec/ruby/core/string/shared/length.rb b/spec/ruby/core/string/shared/length.rb index cea287d7a2..f387fb251c 100644 --- a/spec/ruby/core/string/shared/length.rb +++ b/spec/ruby/core/string/shared/length.rb @@ -21,6 +21,6 @@ describe :string_length, shared: true do str = 'こにちわ' str.send(@method) - str.force_encoding('ASCII-8BIT').send(@method).should == 12 + str.force_encoding('BINARY').send(@method).should == 12 end end diff --git a/spec/ruby/core/string/undump_spec.rb b/spec/ruby/core/string/undump_spec.rb index ec13308c16..315d27cad4 100644 --- a/spec/ruby/core/string/undump_spec.rb +++ b/spec/ruby/core/string/undump_spec.rb @@ -430,7 +430,7 @@ ruby_version_is '2.5' do end it "raises RuntimeError if there is malformed dump of non ASCII-compatible string" do - -> { '"".force_encoding("ASCII-8BIT"'.undump }.should raise_error(RuntimeError, /invalid dumped string/) + -> { '"".force_encoding("BINARY"'.undump }.should raise_error(RuntimeError, /invalid dumped string/) -> { '"".force_encoding("Unknown")'.undump }.should raise_error(RuntimeError, /dumped string has unknown encoding name/) -> { '"".force_encoding()'.undump }.should raise_error(RuntimeError, /invalid dumped string/) end diff --git a/spec/ruby/core/string/unpack/a_spec.rb b/spec/ruby/core/string/unpack/a_spec.rb index 3de338e2e1..2d83b4c824 100644 --- a/spec/ruby/core/string/unpack/a_spec.rb +++ b/spec/ruby/core/string/unpack/a_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' @@ -32,7 +32,7 @@ describe "String#unpack with format 'A'" do it "decodes into raw (ascii) string values" do str = "str".force_encoding('UTF-8').unpack("A*")[0] - str.encoding.name.should == 'ASCII-8BIT' + str.encoding.should == Encoding::BINARY end end @@ -60,7 +60,7 @@ describe "String#unpack with format 'a'" do it "decodes into raw (ascii) string values" do str = "".unpack("a*")[0] - str.encoding.name.should == 'ASCII-8BIT' + str.encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/core/string/unpack/at_spec.rb b/spec/ruby/core/string/unpack/at_spec.rb index a5f97b64f0..d8e55a1020 100644 --- a/spec/ruby/core/string/unpack/at_spec.rb +++ b/spec/ruby/core/string/unpack/at_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/unpack/b_spec.rb b/spec/ruby/core/string/unpack/b_spec.rb index a0bbc3d421..1a838d6c7c 100644 --- a/spec/ruby/core/string/unpack/b_spec.rb +++ b/spec/ruby/core/string/unpack/b_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/unpack/c_spec.rb b/spec/ruby/core/string/unpack/c_spec.rb index bdcbd87663..ed8caa4895 100644 --- a/spec/ruby/core/string/unpack/c_spec.rb +++ b/spec/ruby/core/string/unpack/c_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/unpack/comment_spec.rb b/spec/ruby/core/string/unpack/comment_spec.rb index 7e7adbf54f..e18a53df3c 100644 --- a/spec/ruby/core/string/unpack/comment_spec.rb +++ b/spec/ruby/core/string/unpack/comment_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' diff --git a/spec/ruby/core/string/unpack/h_spec.rb b/spec/ruby/core/string/unpack/h_spec.rb index 07d52149d1..f2f5dcf396 100644 --- a/spec/ruby/core/string/unpack/h_spec.rb +++ b/spec/ruby/core/string/unpack/h_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' @@ -63,6 +63,10 @@ describe "String#unpack with format 'H'" do it "ignores spaces between directives" do "\x01\x10".unpack("H H").should == ["0", "1"] end + + it "should make strings with US_ASCII encoding" do + "\x01".unpack("H")[0].encoding.should == Encoding::US_ASCII + end end describe "String#unpack with format 'h'" do @@ -124,4 +128,8 @@ describe "String#unpack with format 'h'" do it "ignores spaces between directives" do "\x01\x10".unpack("h h").should == ["1", "0"] end + + it "should make strings with US_ASCII encoding" do + "\x01".unpack("h")[0].encoding.should == Encoding::US_ASCII + end end diff --git a/spec/ruby/core/string/unpack/m_spec.rb b/spec/ruby/core/string/unpack/m_spec.rb index d714f6fbcb..96841f24cb 100644 --- a/spec/ruby/core/string/unpack/m_spec.rb +++ b/spec/ruby/core/string/unpack/m_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/unpack/shared/float.rb b/spec/ruby/core/string/unpack/shared/float.rb index 208dc357af..99bd8a3401 100644 --- a/spec/ruby/core/string/unpack/shared/float.rb +++ b/spec/ruby/core/string/unpack/shared/float.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- describe :string_unpack_float_le, shared: true do it "decodes one float for a single format character" do diff --git a/spec/ruby/core/string/unpack/shared/integer.rb b/spec/ruby/core/string/unpack/shared/integer.rb index 03dfb5c682..cbaa743683 100644 --- a/spec/ruby/core/string/unpack/shared/integer.rb +++ b/spec/ruby/core/string/unpack/shared/integer.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- describe :string_unpack_16bit_le, shared: true do it "decodes one short for a single format character" do diff --git a/spec/ruby/core/string/unpack/u_spec.rb b/spec/ruby/core/string/unpack/u_spec.rb index ee1d6c68e7..8db6de1ab3 100644 --- a/spec/ruby/core/string/unpack/u_spec.rb +++ b/spec/ruby/core/string/unpack/u_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' @@ -31,10 +31,10 @@ describe "String#unpack with format 'u'" do it "decodes into raw (ascii) string values" do str = "".unpack("u")[0] - str.encoding.name.should == 'ASCII-8BIT' + str.encoding.should == Encoding::BINARY str = "1".force_encoding('UTF-8').unpack("u")[0] - str.encoding.name.should == 'ASCII-8BIT' + str.encoding.should == Encoding::BINARY end it "decodes the complete string ignoring newlines when given a single directive" do diff --git a/spec/ruby/core/string/unpack/w_spec.rb b/spec/ruby/core/string/unpack/w_spec.rb index 8ff926783e..166ae58869 100644 --- a/spec/ruby/core/string/unpack/w_spec.rb +++ b/spec/ruby/core/string/unpack/w_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/unpack/x_spec.rb b/spec/ruby/core/string/unpack/x_spec.rb index 22b641b732..5adcb720d1 100644 --- a/spec/ruby/core/string/unpack/x_spec.rb +++ b/spec/ruby/core/string/unpack/x_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/unpack/z_spec.rb b/spec/ruby/core/string/unpack/z_spec.rb index 2de624a74d..552851ce04 100644 --- a/spec/ruby/core/string/unpack/z_spec.rb +++ b/spec/ruby/core/string/unpack/z_spec.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# -*- encoding: binary -*- require_relative '../../../spec_helper' require_relative '../fixtures/classes' require_relative 'shared/basic' diff --git a/spec/ruby/core/string/valid_encoding_spec.rb b/spec/ruby/core/string/valid_encoding_spec.rb index 54109386ba..09916df079 100644 --- a/spec/ruby/core/string/valid_encoding_spec.rb +++ b/spec/ruby/core/string/valid_encoding_spec.rb @@ -9,12 +9,12 @@ describe "String#valid_encoding?" do it "returns true if self is valid in the current encoding and other encodings" do str = "\x77" str.force_encoding('utf-8').valid_encoding?.should be_true - str.force_encoding('ascii-8bit').valid_encoding?.should be_true + str.force_encoding('binary').valid_encoding?.should be_true end it "returns true for all encodings self is valid in" do str = "\u{6754}" - str.force_encoding('ASCII-8BIT').valid_encoding?.should be_true + str.force_encoding('BINARY').valid_encoding?.should be_true str.force_encoding('UTF-8').valid_encoding?.should be_true str.force_encoding('US-ASCII').valid_encoding?.should be_false str.force_encoding('Big5').valid_encoding?.should be_false -- cgit v1.2.3