mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@8d74d49
This commit is contained in:
parent
c940397116
commit
d80e44deec
157 changed files with 581 additions and 543 deletions
|
@ -78,7 +78,7 @@ Find
|
|||
Forwardable
|
||||
GetoptLong
|
||||
HMACConstants
|
||||
HashStringsASCII8BIT
|
||||
HashStringsBinary
|
||||
HashStringsUSASCII
|
||||
HashStringsUTF8
|
||||
IPAddr
|
||||
|
|
|
@ -6,24 +6,24 @@ describe 'The -K command line option' do
|
|||
end
|
||||
|
||||
describe 'sets __ENCODING__ and Encoding.default_external' do
|
||||
it "to Encoding::ASCII_8BIT with -Ka" do
|
||||
it "to Encoding::BINARY with -Ka" do
|
||||
ruby_exe(@test_string, options: '-Ka').should ==
|
||||
[Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect
|
||||
[Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::ASCII_8BIT with -KA" do
|
||||
it "to Encoding::BINARY with -KA" do
|
||||
ruby_exe(@test_string, options: '-KA').should ==
|
||||
[Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect
|
||||
[Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::ASCII_8BIT with -Kn" do
|
||||
it "to Encoding::BINARY with -Kn" do
|
||||
ruby_exe(@test_string, options: '-Kn').should ==
|
||||
[Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect
|
||||
[Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::ASCII_8BIT with -KN" do
|
||||
it "to Encoding::BINARY with -KN" do
|
||||
ruby_exe(@test_string, options: '-KN').should ==
|
||||
[Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect
|
||||
[Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect
|
||||
end
|
||||
|
||||
it "to Encoding::EUC_JP with -Ke" do
|
||||
|
|
|
@ -18,6 +18,4 @@ describe "The -x command line option" do
|
|||
result = ruby_exe(embedded_ruby)
|
||||
result.should == "success\n"
|
||||
end
|
||||
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -31,13 +31,13 @@ describe "ARGF.binmode" do
|
|||
end
|
||||
end
|
||||
|
||||
it "sets the file's encoding to ASCII-8BIT" do
|
||||
it "sets the file's encoding to BINARY" do
|
||||
argf [@bin_file, @file1] do
|
||||
@argf.binmode
|
||||
@argf.binmode?.should == true
|
||||
@argf.gets.encoding.should == Encoding::ASCII_8BIT
|
||||
@argf.gets.encoding.should == Encoding::BINARY
|
||||
@argf.skip
|
||||
@argf.read.encoding.should == Encoding::ASCII_8BIT
|
||||
@argf.read.encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,4 +43,9 @@ describe "Array#==" do
|
|||
obj.should_receive(:==).and_return(true)
|
||||
[obj].should == [5]
|
||||
end
|
||||
|
||||
# See https://bugs.ruby-lang.org/issues/1720
|
||||
it "returns true for [NaN] == [NaN] because Array#== first checks with #equal? and NaN.equal?(NaN) is true" do
|
||||
[Float::NAN].should == [Float::NAN]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,33 +37,33 @@ module ArraySpecs
|
|||
]
|
||||
end
|
||||
|
||||
def self.array_with_utf8_and_7bit_ascii8bit_strings
|
||||
def self.array_with_utf8_and_7bit_binary_strings
|
||||
[
|
||||
'bar',
|
||||
'báz',
|
||||
'foo'.force_encoding('ASCII-8BIT')
|
||||
'foo'.force_encoding('BINARY')
|
||||
]
|
||||
end
|
||||
|
||||
def self.array_with_utf8_and_ascii8bit_strings
|
||||
def self.array_with_utf8_and_binary_strings
|
||||
[
|
||||
'bar',
|
||||
'báz',
|
||||
[255].pack('C').force_encoding('ASCII-8BIT')
|
||||
[255].pack('C').force_encoding('BINARY')
|
||||
]
|
||||
end
|
||||
|
||||
def self.array_with_usascii_and_7bit_ascii8bit_strings
|
||||
def self.array_with_usascii_and_7bit_binary_strings
|
||||
[
|
||||
'bar'.force_encoding('US-ASCII'),
|
||||
'foo'.force_encoding('ASCII-8BIT')
|
||||
'foo'.force_encoding('BINARY')
|
||||
]
|
||||
end
|
||||
|
||||
def self.array_with_usascii_and_ascii8bit_strings
|
||||
def self.array_with_usascii_and_binary_strings
|
||||
[
|
||||
'bar'.force_encoding('US-ASCII'),
|
||||
[255].pack('C').force_encoding('ASCII-8BIT')
|
||||
[255].pack('C').force_encoding('BINARY')
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
require_relative 'shared/basic'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
require_relative 'shared/basic'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
require_relative 'shared/basic'
|
||||
|
@ -47,8 +47,8 @@ describe "Array#pack with format 'B'" do
|
|||
].should be_computed_by(:pack, "B*")
|
||||
end
|
||||
|
||||
it "returns an ASCII-8BIT string" do
|
||||
["1"].pack("B").encoding.should == Encoding::ASCII_8BIT
|
||||
it "returns an BINARY string" do
|
||||
["1"].pack("B").encoding.should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "encodes the string as a sequence of bytes" do
|
||||
|
@ -98,8 +98,8 @@ describe "Array#pack with format 'b'" do
|
|||
].should be_computed_by(:pack, "b*")
|
||||
end
|
||||
|
||||
it "returns an ASCII-8BIT string" do
|
||||
["1"].pack("b").encoding.should == Encoding::ASCII_8BIT
|
||||
it "returns an BINARY string" do
|
||||
["1"].pack("b").encoding.should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "encodes the string as a sequence of bytes" do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# encoding: ascii-8bit
|
||||
# encoding: binary
|
||||
|
||||
require_relative '../../../spec_helper'
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
require_relative 'shared/basic'
|
||||
|
@ -97,8 +97,8 @@ describe "Array#pack with format 'H'" do
|
|||
].should be_computed_by(:pack, "H")
|
||||
end
|
||||
|
||||
it "returns an ASCII-8BIT string" do
|
||||
["41"].pack("H").encoding.should == Encoding::ASCII_8BIT
|
||||
it "returns an BINARY string" do
|
||||
["41"].pack("H").encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -194,7 +194,7 @@ describe "Array#pack with format 'h'" do
|
|||
].should be_computed_by(:pack, "h")
|
||||
end
|
||||
|
||||
it "returns an ASCII-8BIT string" do
|
||||
["41"].pack("h").encoding.should == Encoding::ASCII_8BIT
|
||||
it "returns an BINARY string" do
|
||||
["41"].pack("h").encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
require_relative 'shared/basic'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
|
||||
describe :array_pack_float_le, shared: true do
|
||||
it "encodes a positive Float" do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
|
||||
describe :array_pack_16bit_le, shared: true do
|
||||
it "encodes the least significant 16 bits of a positive number" do
|
||||
|
|
|
@ -15,9 +15,9 @@ describe :array_pack_numeric_basic, shared: true do
|
|||
lambda { [false].pack(pack_format) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns an ASCII-8BIT string" do
|
||||
[0xFF].pack(pack_format).encoding.should == Encoding::ASCII_8BIT
|
||||
[0xE3, 0x81, 0x82].pack(pack_format(3)).encoding.should == Encoding::ASCII_8BIT
|
||||
it "returns an BINARY string" do
|
||||
[0xFF].pack(pack_format).encoding.should == Encoding::BINARY
|
||||
[0xE3, 0x81, 0x82].pack(pack_format(3)).encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -38,11 +38,11 @@ describe :array_pack_string, shared: true do
|
|||
|
||||
it "returns a string in encoding of common to the concatenated results" do
|
||||
f = pack_format("*")
|
||||
[ [["\u{3042 3044 3046 3048}", 0x2000B].pack(f+"U"), Encoding::ASCII_8BIT],
|
||||
[["abcde\xd1", "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::ASCII_8BIT],
|
||||
[["a".force_encoding("ascii"), "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::ASCII_8BIT],
|
||||
[ [["\u{3042 3044 3046 3048}", 0x2000B].pack(f+"U"), Encoding::BINARY],
|
||||
[["abcde\xd1", "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY],
|
||||
[["a".force_encoding("ascii"), "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY],
|
||||
# under discussion [ruby-dev:37294]
|
||||
[["\u{3042 3044 3046 3048}", 1].pack(f+"N"), Encoding::ASCII_8BIT]
|
||||
[["\u{3042 3044 3046 3048}", 1].pack(f+"N"), Encoding::BINARY]
|
||||
].should be_computed_by(:encoding)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
require_relative 'shared/basic'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
require_relative 'shared/basic'
|
||||
|
@ -36,7 +36,7 @@ describe "Array#pack with format 'w'" do
|
|||
lambda { [-1].pack("w") }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "returns an ASCII-8BIT string" do
|
||||
[1].pack('w').encoding.should == Encoding::ASCII_8BIT
|
||||
it "returns an BINARY string" do
|
||||
[1].pack('w').encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
require_relative 'shared/basic'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
require_relative 'shared/basic'
|
||||
|
|
|
@ -89,8 +89,8 @@ describe :array_join_with_default_separator, shared: true do
|
|||
it "uses the first encoding when other strings are compatible" do
|
||||
ary1 = ArraySpecs.array_with_7bit_utf8_and_usascii_strings
|
||||
ary2 = ArraySpecs.array_with_usascii_and_7bit_utf8_strings
|
||||
ary3 = ArraySpecs.array_with_utf8_and_7bit_ascii8bit_strings
|
||||
ary4 = ArraySpecs.array_with_usascii_and_7bit_ascii8bit_strings
|
||||
ary3 = ArraySpecs.array_with_utf8_and_7bit_binary_strings
|
||||
ary4 = ArraySpecs.array_with_usascii_and_7bit_binary_strings
|
||||
|
||||
ary1.send(@method).encoding.should == Encoding::UTF_8
|
||||
ary2.send(@method).encoding.should == Encoding::US_ASCII
|
||||
|
@ -107,9 +107,9 @@ describe :array_join_with_default_separator, shared: true do
|
|||
end
|
||||
|
||||
it "fails for arrays with incompatibly-encoded strings" do
|
||||
ary_utf8_bad_ascii8bit = ArraySpecs.array_with_utf8_and_ascii8bit_strings
|
||||
ary_utf8_bad_binary = ArraySpecs.array_with_utf8_and_binary_strings
|
||||
|
||||
lambda { ary_utf8_bad_ascii8bit.send(@method) }.should raise_error(EncodingError)
|
||||
lambda { ary_utf8_bad_binary.send(@method) }.should raise_error(EncodingError)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -35,6 +35,10 @@ describe "Array#to_h" do
|
|||
lambda { [].to_h(:a, :b) }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "produces a hash that returns nil for a missing element" do
|
||||
[[:a, 1], [:b, 2]].to_h[:c].should be_nil
|
||||
end
|
||||
|
||||
ruby_version_is "2.6" do
|
||||
context "with block" do
|
||||
it "converts [key, value] pairs returned by the block to a Hash" do
|
||||
|
|
|
@ -43,10 +43,10 @@ ruby_version_is "2.5" do
|
|||
|
||||
it "returns children encoded with the filesystem encoding by default" do
|
||||
# This spec depends on the locale not being US-ASCII because if it is, the
|
||||
# children that are not ascii_only? will be ASCII-8BIT encoded.
|
||||
# children that are not ascii_only? will be BINARY encoded.
|
||||
children = Dir.children(File.join(DirSpecs.mock_dir, 'special')).sort
|
||||
encoding = Encoding.find("filesystem")
|
||||
encoding = Encoding::ASCII_8BIT if encoding == Encoding::US_ASCII
|
||||
encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
|
||||
platform_is_not :windows do
|
||||
children.should include("こんにちは.txt".force_encoding(encoding))
|
||||
end
|
||||
|
@ -110,11 +110,11 @@ ruby_version_is "2.6" do
|
|||
|
||||
it "returns children encoded with the filesystem encoding by default" do
|
||||
# This spec depends on the locale not being US-ASCII because if it is, the
|
||||
# children that are not ascii_only? will be ASCII-8BIT encoded.
|
||||
# children that are not ascii_only? will be BINARY encoded.
|
||||
@dir = Dir.new(File.join(DirSpecs.mock_dir, 'special'))
|
||||
children = @dir.children.sort
|
||||
encoding = Encoding.find("filesystem")
|
||||
encoding = Encoding::ASCII_8BIT if encoding == Encoding::US_ASCII
|
||||
encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
|
||||
platform_is_not :windows do
|
||||
children.should include("こんにちは.txt".force_encoding(encoding))
|
||||
end
|
||||
|
|
|
@ -42,10 +42,10 @@ describe "Dir.entries" do
|
|||
|
||||
it "returns entries encoded with the filesystem encoding by default" do
|
||||
# This spec depends on the locale not being US-ASCII because if it is, the
|
||||
# entries that are not ascii_only? will be ASCII-8BIT encoded.
|
||||
# entries that are not ascii_only? will be BINARY encoded.
|
||||
entries = Dir.entries(File.join(DirSpecs.mock_dir, 'special')).sort
|
||||
encoding = Encoding.find("filesystem")
|
||||
encoding = Encoding::ASCII_8BIT if encoding == Encoding::US_ASCII
|
||||
encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
|
||||
platform_is_not :windows do
|
||||
entries.should include("こんにちは.txt".force_encoding(encoding))
|
||||
end
|
||||
|
|
|
@ -37,7 +37,7 @@ describe :dir_pwd, shared: true do
|
|||
it "returns a String with the filesystem encoding" do
|
||||
enc = Dir.send(@method).encoding
|
||||
if @fs_encoding == Encoding::US_ASCII
|
||||
[Encoding::US_ASCII, Encoding::ASCII_8BIT].should include(enc)
|
||||
[Encoding::US_ASCII, Encoding::BINARY].should include(enc)
|
||||
else
|
||||
enc.should equal(@fs_encoding)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
|
||||
require_relative '../../spec_helper'
|
||||
|
||||
|
@ -14,12 +14,12 @@ describe "Encoding.compatible? String, String" do
|
|||
Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::US_ASCII
|
||||
end
|
||||
|
||||
it "returns US-ASCII if the second String is ASCII-8BIT and ASCII only" do
|
||||
it "returns US-ASCII if the second String is BINARY and ASCII only" do
|
||||
Encoding.compatible?(@str, "\x7f").should == Encoding::US_ASCII
|
||||
end
|
||||
|
||||
it "returns ASCII-8BIT if the second String is ASCII-8BIT but not ASCII only" do
|
||||
Encoding.compatible?(@str, "\xff").should == Encoding::ASCII_8BIT
|
||||
it "returns BINARY if the second String is BINARY but not ASCII only" do
|
||||
Encoding.compatible?(@str, "\xff").should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "returns US-ASCII if the second String is UTF-8 and ASCII only" do
|
||||
|
@ -39,16 +39,16 @@ describe "Encoding.compatible? String, String" do
|
|||
end
|
||||
|
||||
it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
|
||||
[ [Encoding, "abc".force_encoding("ASCII-8BIT"), "123".force_encoding("US-ASCII"), Encoding::ASCII_8BIT],
|
||||
[Encoding, "123".force_encoding("US-ASCII"), "abc".force_encoding("ASCII-8BIT"), Encoding::US_ASCII]
|
||||
[ [Encoding, "abc".force_encoding("BINARY"), "123".force_encoding("US-ASCII"), Encoding::BINARY],
|
||||
[Encoding, "123".force_encoding("US-ASCII"), "abc".force_encoding("BINARY"), Encoding::US_ASCII]
|
||||
].should be_computed_by(:compatible?)
|
||||
end
|
||||
|
||||
it "returns the second's Encoding if the second is ASCII compatible but not ASCII only" do
|
||||
[ [Encoding, "abc".force_encoding("UTF-8"), "\xff".force_encoding("Shift_JIS"), Encoding::Shift_JIS],
|
||||
[Encoding, "123".force_encoding("Shift_JIS"), "\xff".force_encoding("UTF-8"), Encoding::UTF_8],
|
||||
[Encoding, "abc".force_encoding("ASCII-8BIT"), "\xff".force_encoding("US-ASCII"), Encoding::US_ASCII],
|
||||
[Encoding, "123".force_encoding("US-ASCII"), "\xff".force_encoding("ASCII-8BIT"), Encoding::ASCII_8BIT],
|
||||
[Encoding, "abc".force_encoding("BINARY"), "\xff".force_encoding("US-ASCII"), Encoding::US_ASCII],
|
||||
[Encoding, "123".force_encoding("US-ASCII"), "\xff".force_encoding("BINARY"), Encoding::BINARY],
|
||||
].should be_computed_by(:compatible?)
|
||||
end
|
||||
|
||||
|
@ -61,11 +61,11 @@ describe "Encoding.compatible? String, String" do
|
|||
|
||||
describe "when the first's Encoding is ASCII compatible but not ASCII only" do
|
||||
it "returns the first's Encoding if the second's is valid US-ASCII" do
|
||||
Encoding.compatible?("\xff", "def".encode("us-ascii")).should == Encoding::ASCII_8BIT
|
||||
Encoding.compatible?("\xff", "def".encode("us-ascii")).should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "returns the first's Encoding if the second's is UTF-8 and ASCII only" do
|
||||
Encoding.compatible?("\xff", "\u{7f}".encode("utf-8")).should == Encoding::ASCII_8BIT
|
||||
Encoding.compatible?("\xff", "\u{7f}".encode("utf-8")).should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "returns nil if the second encoding is ASCII compatible but neither String's encoding is ASCII only" do
|
||||
|
@ -82,11 +82,11 @@ describe "Encoding.compatible? String, String" do
|
|||
Encoding.compatible?(@str, "def".encode("us-ascii")).should be_nil
|
||||
end
|
||||
|
||||
it "returns nil when the second String is ASCII-8BIT and ASCII only" do
|
||||
it "returns nil when the second String is BINARY and ASCII only" do
|
||||
Encoding.compatible?(@str, "\x7f").should be_nil
|
||||
end
|
||||
|
||||
it "returns nil when the second String is ASCII-8BIT but not ASCII only" do
|
||||
it "returns nil when the second String is BINARY but not ASCII only" do
|
||||
Encoding.compatible?(@str, "\xff").should be_nil
|
||||
end
|
||||
|
||||
|
@ -109,7 +109,7 @@ describe "Encoding.compatible? String, String" do
|
|||
Encoding.compatible?(@str, "\x7f").should == Encoding::UTF_8
|
||||
end
|
||||
|
||||
it "returns nil when the second's Encoding is ASCII-8BIT but not ASCII only" do
|
||||
it "returns nil when the second's Encoding is BINARY but not ASCII only" do
|
||||
Encoding.compatible?(@str, "\xff").should be_nil
|
||||
end
|
||||
|
||||
|
@ -170,7 +170,7 @@ describe "Encoding.compatible? String, Regexp" do
|
|||
end
|
||||
|
||||
it "returns the String's Encoding if it is not US-ASCII but both are ASCII only" do
|
||||
[ [Encoding, "abc", Encoding::ASCII_8BIT],
|
||||
[ [Encoding, "abc", Encoding::BINARY],
|
||||
[Encoding, "abc".encode("utf-8"), Encoding::UTF_8],
|
||||
[Encoding, "abc".encode("euc-jp"), Encoding::EUC_JP],
|
||||
[Encoding, "abc".encode("shift_jis"), Encoding::Shift_JIS],
|
||||
|
@ -178,7 +178,7 @@ describe "Encoding.compatible? String, Regexp" do
|
|||
end
|
||||
|
||||
it "returns the String's Encoding if the String is not ASCII only" do
|
||||
[ [Encoding, "\xff", Encoding::ASCII_8BIT],
|
||||
[ [Encoding, "\xff", Encoding::BINARY],
|
||||
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
|
||||
[Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
|
||||
[Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
|
||||
|
@ -193,7 +193,7 @@ describe "Encoding.compatible? String, Symbol" do
|
|||
end
|
||||
|
||||
it "returns the String's Encoding if it is not US-ASCII but both are ASCII only" do
|
||||
[ [Encoding, "abc", Encoding::ASCII_8BIT],
|
||||
[ [Encoding, "abc", Encoding::BINARY],
|
||||
[Encoding, "abc".encode("utf-8"), Encoding::UTF_8],
|
||||
[Encoding, "abc".encode("euc-jp"), Encoding::EUC_JP],
|
||||
[Encoding, "abc".encode("shift_jis"), Encoding::Shift_JIS],
|
||||
|
@ -201,7 +201,7 @@ describe "Encoding.compatible? String, Symbol" do
|
|||
end
|
||||
|
||||
it "returns the String's Encoding if the String is not ASCII only" do
|
||||
[ [Encoding, "\xff", Encoding::ASCII_8BIT],
|
||||
[ [Encoding, "\xff", Encoding::BINARY],
|
||||
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
|
||||
[Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
|
||||
[Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
|
||||
|
@ -219,7 +219,7 @@ describe "Encoding.compatible? String, Encoding" do
|
|||
end
|
||||
|
||||
it "returns the String's encoding if the Encoding is US-ASCII" do
|
||||
[ [Encoding, "\xff", Encoding::ASCII_8BIT],
|
||||
[ [Encoding, "\xff", Encoding::BINARY],
|
||||
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
|
||||
[Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
|
||||
[Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
|
||||
|
@ -229,14 +229,14 @@ describe "Encoding.compatible? String, Encoding" do
|
|||
it "returns the Encoding if the String's encoding is ASCII compatible and the String is ASCII only" do
|
||||
str = "abc".encode("utf-8")
|
||||
|
||||
Encoding.compatible?(str, Encoding::ASCII_8BIT).should == Encoding::ASCII_8BIT
|
||||
Encoding.compatible?(str, Encoding::BINARY).should == Encoding::BINARY
|
||||
Encoding.compatible?(str, Encoding::UTF_8).should == Encoding::UTF_8
|
||||
Encoding.compatible?(str, Encoding::EUC_JP).should == Encoding::EUC_JP
|
||||
Encoding.compatible?(str, Encoding::Shift_JIS).should == Encoding::Shift_JIS
|
||||
end
|
||||
|
||||
it "returns nil if the String's encoding is ASCII compatible but the string is not ASCII only" do
|
||||
Encoding.compatible?("\u3042".encode("utf-8"), Encoding::ASCII_8BIT).should be_nil
|
||||
Encoding.compatible?("\u3042".encode("utf-8"), Encoding::BINARY).should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -254,7 +254,7 @@ describe "Encoding.compatible? Regexp, Regexp" do
|
|||
end
|
||||
|
||||
it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
|
||||
[ [Encoding, Regexp.new("\xff"), Encoding::ASCII_8BIT],
|
||||
[ [Encoding, Regexp.new("\xff"), Encoding::BINARY],
|
||||
[Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
|
||||
[Encoding, Regexp.new("\xa4\xa2".force_encoding("euc-jp")), Encoding::EUC_JP],
|
||||
[Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
|
||||
|
@ -268,7 +268,7 @@ describe "Encoding.compatible? Regexp, Symbol" do
|
|||
end
|
||||
|
||||
it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
|
||||
[ [Encoding, Regexp.new("\xff"), Encoding::ASCII_8BIT],
|
||||
[ [Encoding, Regexp.new("\xff"), Encoding::BINARY],
|
||||
[Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
|
||||
[Encoding, Regexp.new("\xa4\xa2".force_encoding("euc-jp")), Encoding::EUC_JP],
|
||||
[Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
|
||||
|
@ -294,7 +294,7 @@ describe "Encoding.compatible? Symbol, Regexp" do
|
|||
c = Regexp.new("\xa4\xa2".force_encoding("euc-jp"))
|
||||
d = Regexp.new("\x82\xa0".force_encoding("shift_jis"))
|
||||
|
||||
[ [Encoding, :abc, a, Encoding::ASCII_8BIT],
|
||||
[ [Encoding, :abc, a, Encoding::BINARY],
|
||||
[Encoding, :abc, b, Encoding::UTF_8],
|
||||
[Encoding, :abc, c, Encoding::EUC_JP],
|
||||
[Encoding, :abc, d, Encoding::Shift_JIS],
|
||||
|
@ -308,7 +308,7 @@ describe "Encoding.compatible? Symbol, Symbol" do
|
|||
end
|
||||
|
||||
it "returns the first's Encoding if it is not ASCII only" do
|
||||
[ [Encoding, "\xff".to_sym, Encoding::ASCII_8BIT],
|
||||
[ [Encoding, "\xff".to_sym, Encoding::BINARY],
|
||||
[Encoding, "\u3042".encode("utf-8").to_sym, Encoding::UTF_8],
|
||||
[Encoding, "\xa4\xa2".force_encoding("euc-jp").to_sym, Encoding::EUC_JP],
|
||||
[Encoding, "\x82\xa0".force_encoding("shift_jis").to_sym, Encoding::Shift_JIS],
|
||||
|
@ -322,15 +322,15 @@ describe "Encoding.compatible? Encoding, Encoding" do
|
|||
[Encoding, Encoding::US_ASCII, Encoding::UTF_7, nil],
|
||||
[Encoding, Encoding::EUC_JP, Encoding::UTF_7, nil],
|
||||
[Encoding, Encoding::UTF_7, Encoding::EUC_JP, nil],
|
||||
[Encoding, Encoding::UTF_7, Encoding::ASCII_8BIT, nil],
|
||||
[Encoding, Encoding::ASCII_8BIT, Encoding::UTF_7, nil],
|
||||
[Encoding, Encoding::UTF_7, Encoding::BINARY, nil],
|
||||
[Encoding, Encoding::BINARY, Encoding::UTF_7, nil],
|
||||
].should be_computed_by(:compatible?)
|
||||
end
|
||||
|
||||
it "returns nil if one of the encodings is not US-ASCII" do
|
||||
[ [Encoding, Encoding::UTF_8, Encoding::ASCII_8BIT, nil],
|
||||
[Encoding, Encoding::ASCII_8BIT, Encoding::UTF_8, nil],
|
||||
[Encoding, Encoding::ASCII_8BIT, Encoding::EUC_JP, nil],
|
||||
[ [Encoding, Encoding::UTF_8, Encoding::BINARY, nil],
|
||||
[Encoding, Encoding::BINARY, Encoding::UTF_8, nil],
|
||||
[Encoding, Encoding::BINARY, Encoding::EUC_JP, nil],
|
||||
[Encoding, Encoding::Shift_JIS, Encoding::EUC_JP, nil],
|
||||
].should be_computed_by(:compatible?)
|
||||
end
|
||||
|
@ -339,14 +339,14 @@ describe "Encoding.compatible? Encoding, Encoding" do
|
|||
[ [Encoding, Encoding::UTF_8, Encoding::US_ASCII, Encoding::UTF_8],
|
||||
[Encoding, Encoding::EUC_JP, Encoding::US_ASCII, Encoding::EUC_JP],
|
||||
[Encoding, Encoding::Shift_JIS, Encoding::US_ASCII, Encoding::Shift_JIS],
|
||||
[Encoding, Encoding::ASCII_8BIT, Encoding::US_ASCII, Encoding::ASCII_8BIT],
|
||||
[Encoding, Encoding::BINARY, Encoding::US_ASCII, Encoding::BINARY],
|
||||
].should be_computed_by(:compatible?)
|
||||
end
|
||||
|
||||
it "returns the Encoding if both are the same" do
|
||||
[ [Encoding, Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8],
|
||||
[Encoding, Encoding::US_ASCII, Encoding::US_ASCII, Encoding::US_ASCII],
|
||||
[Encoding, Encoding::ASCII_8BIT, Encoding::ASCII_8BIT, Encoding::ASCII_8BIT],
|
||||
[Encoding, Encoding::BINARY, Encoding::BINARY, Encoding::BINARY],
|
||||
[Encoding, Encoding::UTF_7, Encoding::UTF_7, Encoding::UTF_7],
|
||||
].should be_computed_by(:compatible?)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
|
||||
describe "Encoding::Converter.new" do
|
||||
|
@ -96,12 +96,12 @@ describe "Encoding::Converter.new" do
|
|||
describe "when passed nil for the replacement object" do
|
||||
describe "when the destination encoding is not UTF-8" do
|
||||
it "sets the replacement String to '?'" do
|
||||
conv = Encoding::Converter.new("us-ascii", "ascii-8bit", replace: nil)
|
||||
conv = Encoding::Converter.new("us-ascii", "binary", replace: nil)
|
||||
conv.replacement.should == "?"
|
||||
end
|
||||
|
||||
it "sets the replacement String encoding to US-ASCII" do
|
||||
conv = Encoding::Converter.new("us-ascii", "ascii-8bit", replace: nil)
|
||||
conv = Encoding::Converter.new("us-ascii", "binary", replace: nil)
|
||||
conv.replacement.encoding.should == Encoding::US_ASCII
|
||||
end
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ describe "Encoding::Converter.search_convpath" do
|
|||
|
||||
it "raises an Encoding::ConverterNotFoundError if no conversion path exists" do
|
||||
lambda do
|
||||
Encoding::Converter.search_convpath(Encoding::ASCII_8BIT, Encoding::Emacs_Mule)
|
||||
Encoding::Converter.search_convpath(Encoding::BINARY, Encoding::Emacs_Mule)
|
||||
end.should raise_error(Encoding::ConverterNotFoundError)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,8 +24,8 @@ describe "Encoding.default_internal" do
|
|||
end
|
||||
|
||||
it "returns the default internal encoding" do
|
||||
Encoding.default_internal = Encoding::ASCII_8BIT
|
||||
Encoding.default_internal.should == Encoding::ASCII_8BIT
|
||||
Encoding.default_internal = Encoding::BINARY
|
||||
Encoding.default_internal.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ describe "Encoding::InvalidByteSequenceError#error_bytes" do
|
|||
@exception2.error_bytes.should == @errinfo2[-2]
|
||||
end
|
||||
|
||||
it "uses ASCII-8BIT as the encoding" do
|
||||
@exception.error_bytes.encoding.should == Encoding::ASCII_8BIT
|
||||
it "uses BINARY as the encoding" do
|
||||
@exception.error_bytes.encoding.should == Encoding::BINARY
|
||||
|
||||
@exception2.error_bytes.encoding.should == Encoding::ASCII_8BIT
|
||||
@exception2.error_bytes.encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,9 +22,9 @@ describe "Encoding::InvalidByteSequenceError#readagain_bytes" do
|
|||
@exception2.readagain_bytes.should == @errinfo2[-1]
|
||||
end
|
||||
|
||||
it "uses ASCII-8BIT as the encoding" do
|
||||
@exception.readagain_bytes.encoding.should == Encoding::ASCII_8BIT
|
||||
it "uses BINARY as the encoding" do
|
||||
@exception.readagain_bytes.encoding.should == Encoding::BINARY
|
||||
|
||||
@exception2.readagain_bytes.encoding.should == Encoding::ASCII_8BIT
|
||||
@exception2.readagain_bytes.encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ describe "Enumerator#each_with_index" do
|
|||
enum1 = [1,2,3].select
|
||||
enum2 = enum1.each_with_index
|
||||
enum2.should be_an_instance_of(Enumerator)
|
||||
enum1.should_not === enum2
|
||||
enum1.should_not == enum2
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if passed extra arguments" do
|
||||
|
@ -28,9 +28,7 @@ describe "Enumerator#each_with_index" do
|
|||
it "returns the iterator's return value" do
|
||||
[1,2,3].select.with_index { |a,b| false }.should == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "Enumerator#each_with_index" do
|
||||
it "returns the correct value if chained with itself" do
|
||||
[:a].each_with_index.each_with_index.to_a.should == [[[:a,0],0]]
|
||||
[:a].each.with_index.with_index.to_a.should == [[[:a,0],0]]
|
||||
|
|
6
spec/ruby/core/env/element_reference_spec.rb
vendored
6
spec/ruby/core/env/element_reference_spec.rb
vendored
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../spec_helper'
|
||||
|
||||
describe "ENV.[]" do
|
||||
|
@ -34,7 +34,7 @@ describe "ENV.[]" do
|
|||
@external = Encoding.default_external
|
||||
@internal = Encoding.default_internal
|
||||
|
||||
Encoding.default_external = Encoding::ASCII_8BIT
|
||||
Encoding.default_external = Encoding::BINARY
|
||||
end
|
||||
|
||||
after :each do
|
||||
|
@ -48,7 +48,7 @@ describe "ENV.[]" do
|
|||
Encoding.default_internal = nil
|
||||
|
||||
locale = Encoding.find('locale')
|
||||
locale = Encoding::ASCII_8BIT if locale == Encoding::US_ASCII
|
||||
locale = Encoding::BINARY if locale == Encoding::US_ASCII
|
||||
ENV[@variable] = "\xC3\xB8"
|
||||
ENV[@variable].encoding.should == locale
|
||||
end
|
||||
|
|
2
spec/ruby/core/env/shared/each.rb
vendored
2
spec/ruby/core/env/shared/each.rb
vendored
|
@ -30,7 +30,7 @@ describe :env_each, shared: true do
|
|||
@external = Encoding.default_external
|
||||
@internal = Encoding.default_internal
|
||||
|
||||
Encoding.default_external = Encoding::ASCII_8BIT
|
||||
Encoding.default_external = Encoding::BINARY
|
||||
|
||||
@locale_encoding = Encoding.find "locale"
|
||||
end
|
||||
|
|
2
spec/ruby/core/env/shared/key.rb
vendored
2
spec/ruby/core/env/shared/key.rb
vendored
|
@ -1,6 +1,4 @@
|
|||
describe :env_key, shared: true do
|
||||
it "needs to be reviewed for completeness"
|
||||
|
||||
it "returns the index associated with the passed value" do
|
||||
ENV["foo"] = "bar"
|
||||
ENV.send(@method, "bar").should == "foo"
|
||||
|
|
2
spec/ruby/core/env/shift_spec.rb
vendored
2
spec/ruby/core/env/shift_spec.rb
vendored
|
@ -30,7 +30,7 @@ describe "ENV.shift" do
|
|||
@external = Encoding.default_external
|
||||
@internal = Encoding.default_internal
|
||||
|
||||
Encoding.default_external = Encoding::ASCII_8BIT
|
||||
Encoding.default_external = Encoding::BINARY
|
||||
end
|
||||
|
||||
after :each do
|
||||
|
|
|
@ -142,11 +142,3 @@ describe "File#chown" do
|
|||
@file.chown(nil, nil).should == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe "File.chown" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
||||
describe "File#chown" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -141,12 +141,12 @@ describe "File.expand_path" do
|
|||
File.expand_path(path).encoding.should equal(Encoding::CP1251)
|
||||
|
||||
weird_path = [222, 173, 190, 175].pack('C*')
|
||||
File.expand_path(weird_path).encoding.should equal(Encoding::ASCII_8BIT)
|
||||
File.expand_path(weird_path).encoding.should equal(Encoding::BINARY)
|
||||
end
|
||||
|
||||
platform_is_not :windows do
|
||||
it "expands a path when the default external encoding is ASCII-8BIT" do
|
||||
Encoding.default_external = Encoding::ASCII_8BIT
|
||||
it "expands a path when the default external encoding is BINARY" do
|
||||
Encoding.default_external = Encoding::BINARY
|
||||
path_8bit = [222, 173, 190, 175].pack('C*')
|
||||
File.expand_path( path_8bit, @rootdir).should == "#{@rootdir}" + path_8bit
|
||||
end
|
||||
|
|
|
@ -52,15 +52,10 @@ module FileSpecs
|
|||
end
|
||||
|
||||
def self.socket
|
||||
require 'socket'
|
||||
name = tmp("ftype_socket.socket")
|
||||
rm_r name
|
||||
begin
|
||||
socket = UNIXServer.new name
|
||||
rescue ArgumentError => error
|
||||
error.message.should =~ /too long/
|
||||
return
|
||||
end
|
||||
require_relative '../../../library/socket/fixtures/classes.rb'
|
||||
|
||||
name = SocketSpecs.socket_path
|
||||
socket = UNIXServer.new name
|
||||
begin
|
||||
yield name
|
||||
ensure
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "File#initialize" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
||||
describe "File#initialize" do
|
||||
after :each do
|
||||
@io.close if @io
|
||||
|
|
|
@ -57,7 +57,3 @@ as_superuser do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "File.lchown" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -552,9 +552,9 @@ describe "File.open" do
|
|||
lambda { File.open(@file, 'fake') }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "defaults external_encoding to ASCII-8BIT for binary modes" do
|
||||
File.open(@file, 'rb') {|f| f.external_encoding.should == Encoding::ASCII_8BIT}
|
||||
File.open(@file, 'wb+') {|f| f.external_encoding.should == Encoding::ASCII_8BIT}
|
||||
it "defaults external_encoding to BINARY for binary modes" do
|
||||
File.open(@file, 'rb') {|f| f.external_encoding.should == Encoding::BINARY}
|
||||
File.open(@file, 'wb+') {|f| f.external_encoding.should == Encoding::BINARY}
|
||||
end
|
||||
|
||||
it "uses the second argument as an options Hash" do
|
||||
|
|
|
@ -55,10 +55,6 @@ describe "File::Stat#ftype" do
|
|||
end
|
||||
end
|
||||
|
||||
# This will silently not execute the block if no socket
|
||||
# can be found. However, if you are running X, there is
|
||||
# a good chance that if nothing else, at least the X
|
||||
# Server socket exists.
|
||||
it "returns 'socket' when the file is a socket" do
|
||||
FileSpecs.socket do |socket|
|
||||
File.lstat(socket).ftype.should == 'socket'
|
||||
|
|
|
@ -5,7 +5,3 @@ require_relative 'fixtures/classes'
|
|||
describe "File::Stat#setgid?" do
|
||||
it_behaves_like :file_setgid, :setgid?, FileStat
|
||||
end
|
||||
|
||||
describe "File::Stat#setgid?" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -5,7 +5,3 @@ require_relative 'fixtures/classes'
|
|||
describe "File::Stat#setuid?" do
|
||||
it_behaves_like :file_setuid, :setuid?, FileStat
|
||||
end
|
||||
|
||||
describe "File::Stat#setuid?" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -5,7 +5,3 @@ require_relative 'fixtures/classes'
|
|||
describe "File::Stat#socket?" do
|
||||
it_behaves_like :file_socket, :socket?, FileStat
|
||||
end
|
||||
|
||||
describe "File::Stat#socket?" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -5,7 +5,3 @@ require_relative 'fixtures/classes'
|
|||
describe "File::Stat#sticky?" do
|
||||
it_behaves_like :file_sticky, :sticky?, FileStat
|
||||
end
|
||||
|
||||
describe "File::Stat#sticky?" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -4,7 +4,3 @@ require_relative '../../shared/file/owned'
|
|||
describe "FileTest.owned?" do
|
||||
it_behaves_like :file_owned, :owned?, FileTest
|
||||
end
|
||||
|
||||
describe "FileTest.owned?" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -4,7 +4,3 @@ require_relative '../../shared/file/pipe'
|
|||
describe "FileTest.pipe?" do
|
||||
it_behaves_like :file_pipe, :pipe?, FileTest
|
||||
end
|
||||
|
||||
describe "FileTest.pipe?" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -4,7 +4,3 @@ require_relative '../../shared/file/setgid'
|
|||
describe "FileTest.setgid?" do
|
||||
it_behaves_like :file_setgid, :setgid?, FileTest
|
||||
end
|
||||
|
||||
describe "FileTest.setgid?" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -4,7 +4,3 @@ require_relative '../../shared/file/setuid'
|
|||
describe "FileTest.setuid?" do
|
||||
it_behaves_like :file_setuid, :setuid?, FileTest
|
||||
end
|
||||
|
||||
describe "FileTest.setuid?" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -4,7 +4,3 @@ require_relative '../../shared/file/socket'
|
|||
describe "FileTest.socket?" do
|
||||
it_behaves_like :file_socket, :socket?, FileTest
|
||||
end
|
||||
|
||||
describe "FileTest.socket?" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -99,11 +99,4 @@ end
|
|||
|
||||
describe "Hash#merge!" do
|
||||
it_behaves_like :hash_update, :merge!
|
||||
|
||||
it "does not raise an exception if changing the value of an existing key during iteration" do
|
||||
hash = {1 => 2, 3 => 4, 5 => 6}
|
||||
hash2 = {1 => :foo, 3 => :bar}
|
||||
hash.each { hash.merge!(hash2) }
|
||||
hash.should == {1 => :foo, 3 => :bar, 5 => 6}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,6 +57,13 @@ describe :hash_update, shared: true do
|
|||
end.should raise_error(frozen_error_class)
|
||||
end
|
||||
|
||||
it "does not raise an exception if changing the value of an existing key during iteration" do
|
||||
hash = {1 => 2, 3 => 4, 5 => 6}
|
||||
hash2 = {1 => :foo, 3 => :bar}
|
||||
hash.each { hash.send(@method, hash2) }
|
||||
hash.should == {1 => :foo, 3 => :bar, 5 => 6}
|
||||
end
|
||||
|
||||
ruby_version_is "2.6" do
|
||||
it "accepts multiple hashes" do
|
||||
result = { a: 1 }.send(@method, { b: 2 }, { c: 3 }, { d: 4 })
|
||||
|
|
|
@ -30,9 +30,9 @@ describe "Integer#chr without argument" do
|
|||
end
|
||||
|
||||
describe "and self is between 128 and 255 (inclusive)" do
|
||||
it "returns an ASCII-8BIT String" do
|
||||
it "returns an BINARY String" do
|
||||
(128..255).each do |c|
|
||||
c.chr.encoding.should == Encoding::ASCII_8BIT
|
||||
c.chr.encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -81,13 +81,13 @@ describe "Integer#chr without argument" do
|
|||
end
|
||||
|
||||
describe "and self is between 128 and 255 (inclusive)" do
|
||||
it "returns an ASCII-8BIT String" do
|
||||
it "returns an BINARY String" do
|
||||
(128..255).each do |c|
|
||||
Encoding.default_internal = Encoding::UTF_8
|
||||
c.chr.encoding.should == Encoding::ASCII_8BIT
|
||||
c.chr.encoding.should == Encoding::BINARY
|
||||
|
||||
Encoding.default_internal = Encoding::SHIFT_JIS
|
||||
c.chr.encoding.should == Encoding::ASCII_8BIT
|
||||
c.chr.encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -126,7 +126,7 @@ describe "Integer#chr without argument" do
|
|||
# #5864
|
||||
it "raises RangeError if self is invalid as a codepoint in the default internal encoding" do
|
||||
[ [0x0100, "US-ASCII"],
|
||||
[0x0100, "ASCII-8BIT"],
|
||||
[0x0100, "BINARY"],
|
||||
[0x0100, "EUC-JP"],
|
||||
[0xA1A0, "EUC-JP"],
|
||||
[0x0100, "ISO-8859-9"],
|
||||
|
@ -173,10 +173,10 @@ describe "Integer#chr with an encoding argument" do
|
|||
0x0000.chr(Encoding::US_ASCII).encoding.should == Encoding::US_ASCII
|
||||
0x007F.chr(Encoding::US_ASCII).encoding.should == Encoding::US_ASCII
|
||||
|
||||
0x0000.chr(Encoding::ASCII_8BIT).encoding.should == Encoding::ASCII_8BIT
|
||||
0x007F.chr(Encoding::ASCII_8BIT).encoding.should == Encoding::ASCII_8BIT
|
||||
0x0080.chr(Encoding::ASCII_8BIT).encoding.should == Encoding::ASCII_8BIT
|
||||
0x00FF.chr(Encoding::ASCII_8BIT).encoding.should == Encoding::ASCII_8BIT
|
||||
0x0000.chr(Encoding::BINARY).encoding.should == Encoding::BINARY
|
||||
0x007F.chr(Encoding::BINARY).encoding.should == Encoding::BINARY
|
||||
0x0080.chr(Encoding::BINARY).encoding.should == Encoding::BINARY
|
||||
0x00FF.chr(Encoding::BINARY).encoding.should == Encoding::BINARY
|
||||
|
||||
0x0000.chr(Encoding::UTF_8).encoding.should == Encoding::UTF_8
|
||||
0x007F.chr(Encoding::UTF_8).encoding.should == Encoding::UTF_8
|
||||
|
@ -197,10 +197,10 @@ describe "Integer#chr with an encoding argument" do
|
|||
0x0000.chr(Encoding::US_ASCII).bytes.to_a.should == [0x00]
|
||||
0x007F.chr(Encoding::US_ASCII).bytes.to_a.should == [0x7F]
|
||||
|
||||
0x0000.chr(Encoding::ASCII_8BIT).bytes.to_a.should == [0x00]
|
||||
0x007F.chr(Encoding::ASCII_8BIT).bytes.to_a.should == [0x7F]
|
||||
0x0080.chr(Encoding::ASCII_8BIT).bytes.to_a.should == [0x80]
|
||||
0x00FF.chr(Encoding::ASCII_8BIT).bytes.to_a.should == [0xFF]
|
||||
0x0000.chr(Encoding::BINARY).bytes.to_a.should == [0x00]
|
||||
0x007F.chr(Encoding::BINARY).bytes.to_a.should == [0x7F]
|
||||
0x0080.chr(Encoding::BINARY).bytes.to_a.should == [0x80]
|
||||
0x00FF.chr(Encoding::BINARY).bytes.to_a.should == [0xFF]
|
||||
|
||||
0x0000.chr(Encoding::UTF_8).bytes.to_a.should == [0x00]
|
||||
0x007F.chr(Encoding::UTF_8).bytes.to_a.should == [0x7F]
|
||||
|
@ -220,7 +220,7 @@ describe "Integer#chr with an encoding argument" do
|
|||
# #5864
|
||||
it "raises RangeError if self is invalid as a codepoint in the specified encoding" do
|
||||
[ [0x80, "US-ASCII"],
|
||||
[0x0100, "ASCII-8BIT"],
|
||||
[0x0100, "BINARY"],
|
||||
[0x0100, "EUC-JP"],
|
||||
[0xA1A0, "EUC-JP"],
|
||||
[0xA1, "EUC-JP"],
|
||||
|
|
|
@ -67,12 +67,15 @@ describe "Integer#round" do
|
|||
25.round(-1, half: :up).should eql(30)
|
||||
25.round(-1, half: :down).should eql(20)
|
||||
25.round(-1, half: :even).should eql(20)
|
||||
25.round(-1, half: nil).should eql(30)
|
||||
35.round(-1, half: :up).should eql(40)
|
||||
35.round(-1, half: :down).should eql(30)
|
||||
35.round(-1, half: :even).should eql(40)
|
||||
35.round(-1, half: nil).should eql(40)
|
||||
(-25).round(-1, half: :up).should eql(-30)
|
||||
(-25).round(-1, half: :down).should eql(-20)
|
||||
(-25).round(-1, half: :even).should eql(-20)
|
||||
(-25).round(-1, half: nil).should eql(-30)
|
||||
end
|
||||
|
||||
ruby_version_is "2.4"..."2.5" do
|
||||
|
@ -90,4 +93,9 @@ describe "Integer#round" do
|
|||
35.round(1, half: :even).should eql(35)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises ArgumentError for an unknown rounding mode" do
|
||||
lambda { 42.round(-1, half: :foo) }.should raise_error(ArgumentError, /invalid rounding mode: foo/)
|
||||
lambda { 42.round(1, half: :foo) }.should raise_error(ArgumentError, /invalid rounding mode: foo/)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,13 +28,13 @@ describe "IO.binread" do
|
|||
IO.binread(@fname, 5, 3).should == @contents.slice(3, 5)
|
||||
end
|
||||
|
||||
it "returns a String in ASCII-8BIT encoding" do
|
||||
IO.binread(@fname).encoding.should == Encoding::ASCII_8BIT
|
||||
it "returns a String in BINARY encoding" do
|
||||
IO.binread(@fname).encoding.should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "returns a String in ASCII-8BIT encoding regardless of Encoding.default_internal" do
|
||||
it "returns a String in BINARY encoding regardless of Encoding.default_internal" do
|
||||
Encoding.default_internal = Encoding::EUC_JP
|
||||
IO.binread(@fname).encoding.should == Encoding::ASCII_8BIT
|
||||
IO.binread(@fname).encoding.should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "raises an ArgumentError when not passed a valid length" do
|
||||
|
|
|
@ -3,6 +3,4 @@ require_relative 'shared/binwrite'
|
|||
|
||||
describe "IO.binwrite" do
|
||||
it_behaves_like :io_binwrite, :binwrite
|
||||
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -171,9 +171,9 @@ describe "IO#external_encoding" do
|
|||
end
|
||||
|
||||
describe "with 'rb' mode" do
|
||||
it "returns Encoding::ASCII_8BIT" do
|
||||
it "returns Encoding::BINARY" do
|
||||
@io = new_io @name, "rb"
|
||||
@io.external_encoding.should equal(Encoding::ASCII_8BIT)
|
||||
@io.external_encoding.should equal(Encoding::BINARY)
|
||||
end
|
||||
|
||||
it "returns the external encoding specified by the mode argument" do
|
||||
|
@ -191,9 +191,9 @@ describe "IO#external_encoding" do
|
|||
end
|
||||
|
||||
describe "with 'wb' mode" do
|
||||
it "returns Encoding::ASCII_8BIT" do
|
||||
it "returns Encoding::BINARY" do
|
||||
@io = new_io @name, "wb"
|
||||
@io.external_encoding.should equal(Encoding::ASCII_8BIT)
|
||||
@io.external_encoding.should equal(Encoding::BINARY)
|
||||
end
|
||||
|
||||
it "returns the external encoding specified by the mode argument" do
|
||||
|
|
|
@ -295,25 +295,25 @@ describe "IO#gets" do
|
|||
end
|
||||
|
||||
it "overwrites the default external encoding with the IO object's own external encoding" do
|
||||
Encoding.default_external = Encoding::ASCII_8BIT
|
||||
Encoding.default_external = Encoding::BINARY
|
||||
Encoding.default_internal = Encoding::UTF_8
|
||||
@io = new_io @name, 'r'
|
||||
@io.set_encoding Encoding::IBM866
|
||||
@io.gets.encoding.should == Encoding::UTF_8
|
||||
end
|
||||
|
||||
it "ignores the internal encoding if the default external encoding is ASCII-8BIT" do
|
||||
Encoding.default_external = Encoding::ASCII_8BIT
|
||||
it "ignores the internal encoding if the default external encoding is BINARY" do
|
||||
Encoding.default_external = Encoding::BINARY
|
||||
Encoding.default_internal = Encoding::UTF_8
|
||||
@io = new_io @name, 'r'
|
||||
@io.gets.encoding.should == Encoding::ASCII_8BIT
|
||||
@io.gets.encoding.should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "transcodes to internal encoding if the IO object's external encoding is ASCII-8BIT" do
|
||||
Encoding.default_external = Encoding::ASCII_8BIT
|
||||
it "transcodes to internal encoding if the IO object's external encoding is BINARY" do
|
||||
Encoding.default_external = Encoding::BINARY
|
||||
Encoding.default_internal = Encoding::UTF_8
|
||||
@io = new_io @name, 'r'
|
||||
@io.set_encoding Encoding::ASCII_8BIT, Encoding::UTF_8
|
||||
@io.set_encoding Encoding::BINARY, Encoding::UTF_8
|
||||
@io.gets.encoding.should == Encoding::UTF_8
|
||||
end
|
||||
end
|
||||
|
|
|
@ -82,14 +82,14 @@ describe :io_internal_encoding, shared: true do
|
|||
@io.internal_encoding.should equal(Encoding::IBM437)
|
||||
end
|
||||
|
||||
it "returns nil when Encoding.default_external is ASCII-8BIT and the internal encoding is not set" do
|
||||
Encoding.default_external = Encoding::ASCII_8BIT
|
||||
it "returns nil when Encoding.default_external is BINARY and the internal encoding is not set" do
|
||||
Encoding.default_external = Encoding::BINARY
|
||||
@io = new_io @name, @object
|
||||
@io.internal_encoding.should be_nil
|
||||
end
|
||||
|
||||
it "returns nil when the external encoding is ASCII-8BIT and the internal encoding is not set" do
|
||||
@io = new_io @name, "#{@object}:ascii-8bit"
|
||||
it "returns nil when the external encoding is BINARY and the internal encoding is not set" do
|
||||
@io = new_io @name, "#{@object}:binary"
|
||||
@io.internal_encoding.should be_nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -380,16 +380,16 @@ describe "IO#read in binary mode" do
|
|||
|
||||
result = File.open(@name, "rb") { |f| f.read }.chomp
|
||||
|
||||
result.encoding.should == Encoding::ASCII_8BIT
|
||||
result.encoding.should == Encoding::BINARY
|
||||
xE2 = [226].pack('C*')
|
||||
result.should == ("abc" + xE2 + "def").force_encoding(Encoding::ASCII_8BIT)
|
||||
result.should == ("abc" + xE2 + "def").force_encoding(Encoding::BINARY)
|
||||
end
|
||||
|
||||
it "does not transcode file contents when an internal encoding is specified" do
|
||||
result = File.open(@name, "r:binary:utf-8") { |f| f.read }.chomp
|
||||
result.encoding.should == Encoding::ASCII_8BIT
|
||||
result.encoding.should == Encoding::BINARY
|
||||
xE2 = [226].pack('C*')
|
||||
result.should == ("abc" + xE2 + "def").force_encoding(Encoding::ASCII_8BIT)
|
||||
result.should == ("abc" + xE2 + "def").force_encoding(Encoding::BINARY)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -420,37 +420,37 @@ describe "IO.read with BOM" do
|
|||
it "reads a file without a bom" do
|
||||
name = fixture __FILE__, "no_bom_UTF-8.txt"
|
||||
result = File.read(name, mode: "rb:BOM|utf-8")
|
||||
result.force_encoding("ascii-8bit").should == "UTF-8\n"
|
||||
result.force_encoding("binary").should == "UTF-8\n"
|
||||
end
|
||||
|
||||
it "reads a file with a utf-8 bom" do
|
||||
name = fixture __FILE__, "bom_UTF-8.txt"
|
||||
result = File.read(name, mode: "rb:BOM|utf-16le")
|
||||
result.force_encoding("ascii-8bit").should == "UTF-8\n"
|
||||
result.force_encoding("binary").should == "UTF-8\n"
|
||||
end
|
||||
|
||||
it "reads a file with a utf-16le bom" do
|
||||
name = fixture __FILE__, "bom_UTF-16LE.txt"
|
||||
result = File.read(name, mode: "rb:BOM|utf-8")
|
||||
result.force_encoding("ascii-8bit").should == "U\x00T\x00F\x00-\x001\x006\x00L\x00E\x00\n\x00"
|
||||
result.force_encoding("binary").should == "U\x00T\x00F\x00-\x001\x006\x00L\x00E\x00\n\x00"
|
||||
end
|
||||
|
||||
it "reads a file with a utf-16be bom" do
|
||||
name = fixture __FILE__, "bom_UTF-16BE.txt"
|
||||
result = File.read(name, mode: "rb:BOM|utf-8")
|
||||
result.force_encoding("ascii-8bit").should == "\x00U\x00T\x00F\x00-\x001\x006\x00B\x00E\x00\n"
|
||||
result.force_encoding("binary").should == "\x00U\x00T\x00F\x00-\x001\x006\x00B\x00E\x00\n"
|
||||
end
|
||||
|
||||
it "reads a file with a utf-32le bom" do
|
||||
name = fixture __FILE__, "bom_UTF-32LE.txt"
|
||||
result = File.read(name, mode: "rb:BOM|utf-8")
|
||||
result.force_encoding("ascii-8bit").should == "U\x00\x00\x00T\x00\x00\x00F\x00\x00\x00-\x00\x00\x003\x00\x00\x002\x00\x00\x00L\x00\x00\x00E\x00\x00\x00\n\x00\x00\x00"
|
||||
result.force_encoding("binary").should == "U\x00\x00\x00T\x00\x00\x00F\x00\x00\x00-\x00\x00\x003\x00\x00\x002\x00\x00\x00L\x00\x00\x00E\x00\x00\x00\n\x00\x00\x00"
|
||||
end
|
||||
|
||||
it "reads a file with a utf-32be bom" do
|
||||
name = fixture __FILE__, "bom_UTF-32BE.txt"
|
||||
result = File.read(name, mode: "rb:BOM|utf-8")
|
||||
result.force_encoding("ascii-8bit").should == "\x00\x00\x00U\x00\x00\x00T\x00\x00\x00F\x00\x00\x00-\x00\x00\x003\x00\x00\x002\x00\x00\x00B\x00\x00\x00E\x00\x00\x00\n"
|
||||
result.force_encoding("binary").should == "\x00\x00\x00U\x00\x00\x00T\x00\x00\x00F\x00\x00\x00-\x00\x00\x003\x00\x00\x002\x00\x00\x00B\x00\x00\x00E\x00\x00\x00\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -480,11 +480,11 @@ end
|
|||
|
||||
describe :io_read_size_internal_encoding, shared: true do
|
||||
it "reads bytes when passed a size" do
|
||||
@io.read(2).should == [164, 162].pack('C*').force_encoding(Encoding::ASCII_8BIT)
|
||||
@io.read(2).should == [164, 162].pack('C*').force_encoding(Encoding::BINARY)
|
||||
end
|
||||
|
||||
it "returns a String in ASCII-8BIT when passed a size" do
|
||||
@io.read(4).encoding.should equal(Encoding::ASCII_8BIT)
|
||||
it "returns a String in BINARY when passed a size" do
|
||||
@io.read(4).encoding.should equal(Encoding::BINARY)
|
||||
end
|
||||
|
||||
it "does not change the buffer's encoding when passed a limit" do
|
||||
|
|
|
@ -21,6 +21,4 @@ describe "IO#readbyte" do
|
|||
@io.readbyte
|
||||
end.should raise_error EOFError
|
||||
end
|
||||
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -201,10 +201,10 @@ describe "IO.readlines" do
|
|||
lines.all? { |s| s.encoding == Encoding::UTF_16 }.should be_true
|
||||
end
|
||||
|
||||
it "ignores the default internal encoding if the external encoding is ASCII-8BIT" do
|
||||
Encoding.default_external = Encoding::ASCII_8BIT
|
||||
it "ignores the default internal encoding if the external encoding is BINARY" do
|
||||
Encoding.default_external = Encoding::BINARY
|
||||
Encoding.default_internal = Encoding::UTF_8
|
||||
lines = IO.readlines(@name)
|
||||
lines.all? { |s| s.encoding == Encoding::ASCII_8BIT }.should be_true
|
||||
lines.all? { |s| s.encoding == Encoding::BINARY }.should be_true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../spec_helper'
|
||||
require_relative 'fixtures/classes'
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ describe "IO#set_encoding when passed nil, nil" do
|
|||
describe "with 'rb' mode" do
|
||||
it "returns Encoding.default_external" do
|
||||
@io = new_io @name, "rb"
|
||||
@io.external_encoding.should equal(Encoding::ASCII_8BIT)
|
||||
@io.external_encoding.should equal(Encoding::BINARY)
|
||||
|
||||
@io.set_encoding nil, nil
|
||||
@io.external_encoding.should equal(Encoding.default_external)
|
||||
|
|
|
@ -168,13 +168,13 @@ describe :io_new, shared: true do
|
|||
|
||||
it "sets external encoding to binary with binmode in mode string" do
|
||||
@io = IO.send(@method, @fd, 'wb')
|
||||
@io.external_encoding.to_s.should == 'ASCII-8BIT'
|
||||
@io.external_encoding.should == Encoding::BINARY
|
||||
end
|
||||
|
||||
# #5917
|
||||
it "sets external encoding to binary with :binmode option" do
|
||||
@io = IO.send(@method, @fd, 'w', {binmode: true})
|
||||
@io.external_encoding.to_s.should == 'ASCII-8BIT'
|
||||
@io.external_encoding.should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "does not use binary encoding when mode encoding is specified" do
|
||||
|
|
|
@ -70,7 +70,7 @@ describe "IO#write on a file" do
|
|||
ë = ([235].pack('U')).encode('ISO-8859-1')
|
||||
ö = ([246].pack('U')).encode('ISO-8859-1')
|
||||
res = "H#{ë}ll#{ö}"
|
||||
File.binread(@filename).should == res.force_encoding(Encoding::ASCII_8BIT)
|
||||
File.binread(@filename).should == res.force_encoding(Encoding::BINARY)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -94,7 +94,7 @@ describe "IO.write" do
|
|||
IO.write(@filename, 'Hëllö'.encode('ISO-8859-1'))
|
||||
xEB = [235].pack('C*')
|
||||
xF6 = [246].pack('C*')
|
||||
File.binread(@filename).should == ("H" + xEB + "ll" + xF6).force_encoding(Encoding::ASCII_8BIT)
|
||||
File.binread(@filename).should == ("H" + xEB + "ll" + xF6).force_encoding(Encoding::BINARY)
|
||||
end
|
||||
|
||||
platform_is_not :windows do
|
||||
|
|
|
@ -45,8 +45,10 @@ describe "Kernel#open" do
|
|||
end
|
||||
|
||||
it "opens an io for writing" do
|
||||
bytes = open("|cat", "w") { |io| io.write(".") }
|
||||
bytes.should == 1
|
||||
-> do
|
||||
bytes = open("|cat", "w") { |io| io.write(".") }
|
||||
bytes.should == 1
|
||||
end.should output_to_fd(".")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -59,6 +59,4 @@ describe "Kernel#proc" do
|
|||
}.should complain(/Capturing the given block using Proc.new is deprecated/)
|
||||
end
|
||||
end
|
||||
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -2,8 +2,6 @@ require_relative '../../spec_helper'
|
|||
require_relative '../../fixtures/code_loading'
|
||||
|
||||
describe "Kernel#require_relative with a relative path" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
|
||||
before :each do
|
||||
CodeLoadingSpecs.spec_setup
|
||||
@dir = "../../fixtures/code"
|
||||
|
@ -267,8 +265,6 @@ describe "Kernel#require_relative with a relative path" do
|
|||
end
|
||||
|
||||
describe "Kernel#require_relative with an absolute path" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
|
||||
before :each do
|
||||
CodeLoadingSpecs.spec_setup
|
||||
@dir = File.expand_path "../../fixtures/code", File.dirname(__FILE__)
|
||||
|
|
|
@ -8,8 +8,6 @@ describe "Kernel#select" do
|
|||
end
|
||||
|
||||
describe "Kernel.select" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
|
||||
it 'does not block when timeout is 0' do
|
||||
IO.pipe do |read, write|
|
||||
IO.select([read], [], [], 0).should == nil
|
||||
|
|
|
@ -446,11 +446,11 @@ describe :marshal_load, shared: true do
|
|||
result.encoding.should equal(Encoding::UTF_16LE)
|
||||
end
|
||||
|
||||
it "loads a String as ASCII-8BIT if no encoding is specified at the end" do
|
||||
str = "\xC3\xB8".force_encoding("ASCII-8BIT")
|
||||
it "loads a String as BINARY if no encoding is specified at the end" do
|
||||
str = "\xC3\xB8".force_encoding("BINARY")
|
||||
data = "\x04\b\"\a\xC3\xB8".force_encoding("UTF-8")
|
||||
result = Marshal.send(@method, data)
|
||||
result.encoding.should == Encoding::ASCII_8BIT
|
||||
result.encoding.should == Encoding::BINARY
|
||||
result.should == str
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,6 @@ require_relative '../../spec_helper'
|
|||
require_relative 'fixtures/classes'
|
||||
|
||||
describe "Method#hash" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
|
||||
it "returns the same value for user methods that are eql?" do
|
||||
obj = MethodSpecs::Methods.new
|
||||
obj.method(:foo).hash.should == obj.method(:bar).hash
|
||||
|
|
|
@ -12,6 +12,4 @@ describe "Module#define_singleton_method" do
|
|||
klass.a.should == 42
|
||||
klass.b(10).should == 20
|
||||
end
|
||||
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
|
|
@ -4,8 +4,8 @@ describe :proc_to_s, shared: true do
|
|||
Proc.new { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:4)?>$/
|
||||
end
|
||||
|
||||
it "has an ASCII-8BIT encoding" do
|
||||
Proc.new { "hello" }.send(@method).encoding.should == Encoding::ASCII_8BIT
|
||||
it "has an BINARY encoding" do
|
||||
Proc.new { "hello" }.send(@method).encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -14,8 +14,8 @@ describe :proc_to_s, shared: true do
|
|||
lambda { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:10)? \(lambda\)>$/
|
||||
end
|
||||
|
||||
it "has an ASCII-8BIT encoding" do
|
||||
lambda { "hello" }.send(@method).encoding.should == Encoding::ASCII_8BIT
|
||||
it "has an BINARY encoding" do
|
||||
lambda { "hello" }.send(@method).encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -24,8 +24,8 @@ describe :proc_to_s, shared: true do
|
|||
proc { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:16)?>$/
|
||||
end
|
||||
|
||||
it "has an ASCII-8BIT encoding" do
|
||||
proc { "hello" }.send(@method).encoding.should == Encoding::ASCII_8BIT
|
||||
it "has an BINARY encoding" do
|
||||
proc { "hello" }.send(@method).encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -35,9 +35,9 @@ describe :proc_to_s, shared: true do
|
|||
method("hello").to_proc.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:22)? \(lambda\)>$/
|
||||
end
|
||||
|
||||
it "has an ASCII-8BIT encoding" do
|
||||
it "has an BINARY encoding" do
|
||||
def hello; end
|
||||
method("hello").to_proc.send(@method).encoding.should == Encoding::ASCII_8BIT
|
||||
method("hello").to_proc.send(@method).encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,9 +47,9 @@ describe :proc_to_s, shared: true do
|
|||
proc.send(@method).should =~ /^#<Proc:0x\h+\(&:foobar\)>$/
|
||||
end
|
||||
|
||||
it "has an ASCII-8BIT encoding" do
|
||||
it "has an BINARY encoding" do
|
||||
proc = :foobar.to_proc
|
||||
proc.send(@method).encoding.should == Encoding::ASCII_8BIT
|
||||
proc.send(@method).encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module ProcessSpecs
|
|||
clocks -= [:CLOCK_BOOTTIME_ALARM, :CLOCK_REALTIME_ALARM]
|
||||
end
|
||||
|
||||
clocks.map { |c|
|
||||
clocks.sort.map { |c|
|
||||
[c, Process.const_get(c)]
|
||||
}
|
||||
end
|
||||
|
|
|
@ -41,9 +41,9 @@ platform_is_not :windows do
|
|||
end
|
||||
|
||||
context "when passed a Symbol" do
|
||||
Process.constants.grep(/\ARLIMIT_/) do |fullname|
|
||||
short = $'
|
||||
it "coerces :#{short} into #{fullname}" do
|
||||
it "coerces the short name into the full RLIMIT_ prefixed name" do
|
||||
Process.constants.grep(/\ARLIMIT_/) do |fullname|
|
||||
short = fullname[/\ARLIMIT_(.+)/, 1]
|
||||
Process.getrlimit(short.to_sym).should == Process.getrlimit(Process.const_get(fullname))
|
||||
end
|
||||
end
|
||||
|
@ -54,9 +54,9 @@ platform_is_not :windows do
|
|||
end
|
||||
|
||||
context "when passed a String" do
|
||||
Process.constants.grep(/\ARLIMIT_/) do |fullname|
|
||||
short = $'
|
||||
it "coerces '#{short}' into #{fullname}" do
|
||||
it "coerces the short name into the full RLIMIT_ prefixed name" do
|
||||
Process.constants.grep(/\ARLIMIT_/) do |fullname|
|
||||
short = fullname[/\ARLIMIT_(.+)/, 1]
|
||||
Process.getrlimit(short).should == Process.getrlimit(Process.const_get(fullname))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "Process.waitpid" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
|
||||
it "returns nil when the process has not yet completed and WNOHANG is specified" do
|
||||
pid = spawn("sleep 5")
|
||||
begin
|
||||
|
|
|
@ -7,8 +7,8 @@ describe :random_bytes, shared: true do
|
|||
@object.bytes(15).length.should == 15
|
||||
end
|
||||
|
||||
it "returns an ASCII-8BIT String" do
|
||||
@object.bytes(15).encoding.should == Encoding::ASCII_8BIT
|
||||
it "returns an BINARY String" do
|
||||
@object.bytes(15).encoding.should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "returns a random binary String" do
|
||||
|
|
|
@ -13,8 +13,8 @@ describe :random_urandom, shared: true do
|
|||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "returns an ASCII-8BIT String" do
|
||||
Random.send(@method, 15).encoding.should == Encoding::ASCII_8BIT
|
||||
it "returns an BINARY String" do
|
||||
Random.send(@method, 15).encoding.should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "returns a random binary String" do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../spec_helper'
|
||||
require_relative 'shared/cover_and_include'
|
||||
require_relative 'shared/cover'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../spec_helper'
|
||||
require_relative 'shared/cover_and_include'
|
||||
require_relative 'shared/include'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../spec_helper'
|
||||
require_relative 'shared/cover_and_include'
|
||||
require_relative 'shared/include'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
|
||||
describe :range_cover_and_include, shared: true do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
require_relative '../../../spec_helper'
|
||||
require_relative '../fixtures/classes'
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ describe "Regexp#encoding" do
|
|||
/ASCII/n.encoding.should == Encoding::US_ASCII
|
||||
end
|
||||
|
||||
it "returns ASCII-8BIT if the 'n' modifier is supplied and non-US-ASCII characters are present" do
|
||||
/\xc2\xa1/n.encoding.should == Encoding::ASCII_8BIT
|
||||
it "returns BINARY if the 'n' modifier is supplied and non-US-ASCII characters are present" do
|
||||
/\xc2\xa1/n.encoding.should == Encoding::BINARY
|
||||
end
|
||||
|
||||
it "defaults to UTF-8 if \\u escapes appear" do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
|
||||
describe :regexp_new, shared: true do
|
||||
it "requires one argument and creates a new regular expression object" do
|
||||
|
@ -135,10 +135,10 @@ describe :regexp_new_string, shared: true do
|
|||
a = "(?:[\x8E\xA1-\xFE])"
|
||||
str = "\A(?:#{a}|x*)\z"
|
||||
|
||||
Regexp.send(@method, str, nil, 'N').encoding.should == Encoding::ASCII_8BIT
|
||||
Regexp.send(@method, str, nil, 'n').encoding.should == Encoding::ASCII_8BIT
|
||||
Regexp.send(@method, str, nil, 'none').encoding.should == Encoding::ASCII_8BIT
|
||||
Regexp.send(@method, str, nil, 'NONE').encoding.should == Encoding::ASCII_8BIT
|
||||
Regexp.send(@method, str, nil, 'N').encoding.should == Encoding::BINARY
|
||||
Regexp.send(@method, str, nil, 'n').encoding.should == Encoding::BINARY
|
||||
Regexp.send(@method, str, nil, 'none').encoding.should == Encoding::BINARY
|
||||
Regexp.send(@method, str, nil, 'NONE').encoding.should == Encoding::BINARY
|
||||
end
|
||||
|
||||
describe "with escaped characters" do
|
||||
|
@ -499,7 +499,7 @@ describe :regexp_new_regexp, shared: true do
|
|||
end
|
||||
|
||||
it "sets the encoding to source String's encoding if the Regexp literal has the 'n' option and the source String is not ASCII only" do
|
||||
Regexp.send(@method, Regexp.new("\\xff", nil, 'n')).encoding.should == Encoding::ASCII_8BIT
|
||||
Regexp.send(@method, Regexp.new("\\xff", nil, 'n')).encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- encoding: ascii-8bit -*-
|
||||
# -*- encoding: binary -*-
|
||||
|
||||
describe :regexp_quote, shared: true do
|
||||
it "escapes any characters with special meaning in a regular expression" do
|
||||
|
@ -23,9 +23,9 @@ describe :regexp_quote, shared: true do
|
|||
Regexp.send(@method, str).encoding.should == Encoding::UTF_8
|
||||
end
|
||||
|
||||
it "sets the encoding of the result to ASCII-8BIT if any non-US-ASCII characters are present in an input String with invalid encoding" do
|
||||
it "sets the encoding of the result to BINARY if any non-US-ASCII characters are present in an input String with invalid encoding" do
|
||||
str = "\xff".force_encoding "us-ascii"
|
||||
str.valid_encoding?.should be_false
|
||||
Regexp.send(@method, "\xff").encoding.should == Encoding::ASCII_8BIT
|
||||
Regexp.send(@method, "\xff").encoding.should == Encoding::BINARY
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
reserved_signals = ARGV
|
||||
cannot_be_trapped = %w[KILL STOP] # See man 2 signal
|
||||
|
||||
(Signal.list.keys - reserved_signals).each do |signal|
|
||||
Signal.trap(signal, -> {})
|
||||
Signal.trap(signal, "DEFAULT")
|
||||
(Signal.list.keys - cannot_be_trapped).each do |signal|
|
||||
begin
|
||||
Signal.trap(signal, -> {})
|
||||
rescue ArgumentError => e
|
||||
unless /can't trap reserved signal|Signal already used by VM or OS/ =~ e.message
|
||||
raise e
|
||||
end
|
||||
else
|
||||
Signal.trap(signal, "DEFAULT")
|
||||
end
|
||||
end
|
||||
|
||||
puts "OK"
|
||||
|
|
|
@ -4,8 +4,7 @@ platform_is_not :windows do
|
|||
describe "Signal.trap" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
|
||||
@proc = lambda { ScratchPad.record :proc_trap }
|
||||
@proc = -> {}
|
||||
@saved_trap = Signal.trap(:HUP, @proc)
|
||||
end
|
||||
|
||||
|
@ -48,29 +47,54 @@ platform_is_not :windows do
|
|||
ScratchPad.recorded.should be_true
|
||||
end
|
||||
|
||||
it "registers an handler doing nothing with :IGNORE" do
|
||||
Signal.trap :HUP, :IGNORE
|
||||
Process.kill(:HUP, Process.pid).should == 1
|
||||
end
|
||||
|
||||
it "ignores the signal when passed nil" do
|
||||
Signal.trap :HUP, nil
|
||||
Signal.trap(:HUP, @saved_trap).should be_nil
|
||||
end
|
||||
|
||||
it "accepts 'DEFAULT' as a symbol in place of a proc" do
|
||||
it "accepts :DEFAULT in place of a proc" do
|
||||
Signal.trap :HUP, :DEFAULT
|
||||
Signal.trap(:HUP, :DEFAULT).should == "DEFAULT"
|
||||
Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
|
||||
end
|
||||
|
||||
it "accepts 'SIG_DFL' as a symbol in place of a proc" do
|
||||
it "accepts :SIG_DFL in place of a proc" do
|
||||
Signal.trap :HUP, :SIG_DFL
|
||||
Signal.trap(:HUP, :SIG_DFL).should == "DEFAULT"
|
||||
Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
|
||||
end
|
||||
|
||||
it "accepts 'SIG_IGN' as a symbol in place of a proc" do
|
||||
it "accepts :SIG_IGN in place of a proc" do
|
||||
Signal.trap :HUP, :SIG_IGN
|
||||
Signal.trap(:HUP, :SIG_IGN).should == "IGNORE"
|
||||
Signal.trap(:HUP, @saved_trap).should == "IGNORE"
|
||||
end
|
||||
|
||||
it "accepts 'IGNORE' as a symbol in place of a proc" do
|
||||
it "accepts :IGNORE in place of a proc" do
|
||||
Signal.trap :HUP, :IGNORE
|
||||
Signal.trap(:HUP, :IGNORE).should == "IGNORE"
|
||||
Signal.trap(:HUP, @saved_trap).should == "IGNORE"
|
||||
end
|
||||
|
||||
it "accepts 'SIG_DFL' in place of a proc" do
|
||||
Signal.trap :HUP, "SIG_DFL"
|
||||
Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
|
||||
end
|
||||
|
||||
it "accepts 'DEFAULT' in place of a proc" do
|
||||
Signal.trap :HUP, "DEFAULT"
|
||||
Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
|
||||
end
|
||||
|
||||
it "accepts 'SIG_IGN' in place of a proc" do
|
||||
Signal.trap :HUP, "SIG_IGN"
|
||||
Signal.trap(:HUP, @saved_trap).should == "IGNORE"
|
||||
end
|
||||
|
||||
it "accepts 'IGNORE' in place of a proc" do
|
||||
Signal.trap :HUP, "IGNORE"
|
||||
Signal.trap(:HUP, @saved_trap).should == "IGNORE"
|
||||
end
|
||||
|
||||
it "accepts long names as Strings" do
|
||||
|
@ -92,47 +116,11 @@ platform_is_not :windows do
|
|||
Signal.trap :HUP, @proc
|
||||
Signal.trap(:HUP, @saved_trap).should equal(@proc)
|
||||
end
|
||||
|
||||
it "accepts 'SIG_DFL' in place of a proc" do
|
||||
Signal.trap :HUP, "SIG_DFL"
|
||||
Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
|
||||
end
|
||||
|
||||
it "accepts 'DEFAULT' in place of a proc" do
|
||||
Signal.trap :HUP, "DEFAULT"
|
||||
Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
|
||||
end
|
||||
|
||||
it "accepts 'SIG_IGN' in place of a proc" do
|
||||
Signal.trap :HUP, "SIG_IGN"
|
||||
Signal.trap(:HUP, "SIG_IGN").should == "IGNORE"
|
||||
end
|
||||
|
||||
it "accepts 'IGNORE' in place of a proc" do
|
||||
Signal.trap :HUP, "IGNORE"
|
||||
Signal.trap(:HUP, "IGNORE").should == "IGNORE"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Signal.trap" do
|
||||
cannot_be_trapped = %w[KILL STOP] # See man 2 signal
|
||||
reserved_signals = %w[VTALRM]
|
||||
|
||||
if PlatformGuard.implementation?(:ruby)
|
||||
reserved_signals += %w[SEGV ILL FPE BUS]
|
||||
end
|
||||
|
||||
if PlatformGuard.implementation?(:truffleruby)
|
||||
if !TruffleRuby.native?
|
||||
reserved_signals += %w[SEGV ILL FPE USR1 QUIT]
|
||||
end
|
||||
end
|
||||
|
||||
if PlatformGuard.implementation?(:jruby)
|
||||
reserved_signals += %w[SEGV ILL FPE BUS USR1 QUIT]
|
||||
end
|
||||
|
||||
cannot_be_trapped.each do |signal|
|
||||
# See man 2 signal
|
||||
%w[KILL STOP].each do |signal|
|
||||
it "raises ArgumentError or Errno::EINVAL for SIG#{signal}" do
|
||||
-> {
|
||||
trap(signal, -> {})
|
||||
|
@ -143,17 +131,8 @@ platform_is_not :windows do
|
|||
end
|
||||
end
|
||||
|
||||
reserved_signals.each do |signal|
|
||||
it "raises ArgumentError for reserved signal: SIG#{signal}" do
|
||||
-> {
|
||||
trap(signal, -> {})
|
||||
}.should raise_error(ArgumentError, /can't trap reserved signal|Signal already used by VM or OS/)
|
||||
end
|
||||
end
|
||||
|
||||
it "allows to register a handler for all known signals, except reserved signals" do
|
||||
excluded = cannot_be_trapped + reserved_signals
|
||||
out = ruby_exe(fixture(__FILE__, "trap_all.rb"), args: [*excluded, "2>&1"])
|
||||
it "allows to register a handler for all known signals, except reserved signals for which it raises ArgumentError" do
|
||||
out = ruby_exe(fixture(__FILE__, "trap_all.rb"), args: "2>&1")
|
||||
out.should == "OK\n"
|
||||
$?.exitstatus.should == 0
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue