зеркало из https://github.com/github/ruby.git
Update to ruby/spec@89175b2
This commit is contained in:
Родитель
1d9f99144b
Коммит
ed2f685253
|
@ -29,7 +29,7 @@ describe "ARGF.readpartial" do
|
||||||
|
|
||||||
it "clears output buffer even if EOFError is raised because @argf is at end" do
|
it "clears output buffer even if EOFError is raised because @argf is at end" do
|
||||||
begin
|
begin
|
||||||
output = "to be cleared"
|
output = +"to be cleared"
|
||||||
|
|
||||||
argf [@file1_name] do
|
argf [@file1_name] do
|
||||||
@argf.read
|
@argf.read
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe :argf_getc, shared: true do
|
||||||
|
|
||||||
it "reads each char of files" do
|
it "reads each char of files" do
|
||||||
argf [@file1, @file2] do
|
argf [@file1, @file2] do
|
||||||
chars = ""
|
chars = +""
|
||||||
@chars.size.times { chars << @argf.send(@method) }
|
@chars.size.times { chars << @argf.send(@method) }
|
||||||
chars.should == @chars
|
chars.should == @chars
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ describe :argf_read, shared: true do
|
||||||
|
|
||||||
it "treats second argument as an output buffer" do
|
it "treats second argument as an output buffer" do
|
||||||
argf [@file1_name] do
|
argf [@file1_name] do
|
||||||
buffer = ""
|
buffer = +""
|
||||||
@argf.send(@method, @file1.size, buffer)
|
@argf.send(@method, @file1.size, buffer)
|
||||||
buffer.should == @file1
|
buffer.should == @file1
|
||||||
end
|
end
|
||||||
|
@ -23,7 +23,7 @@ describe :argf_read, shared: true do
|
||||||
|
|
||||||
it "clears output buffer before appending to it" do
|
it "clears output buffer before appending to it" do
|
||||||
argf [@file1_name] do
|
argf [@file1_name] do
|
||||||
buffer = "to be cleared"
|
buffer = +"to be cleared"
|
||||||
@argf.send(@method, @file1.size, buffer)
|
@argf.send(@method, @file1.size, buffer)
|
||||||
buffer.should == @file1
|
buffer.should == @file1
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ describe "Array#fill" do
|
||||||
|
|
||||||
it "does not replicate the filler" do
|
it "does not replicate the filler" do
|
||||||
ary = [1, 2, 3, 4]
|
ary = [1, 2, 3, 4]
|
||||||
str = "x"
|
str = +"x"
|
||||||
ary.fill(str).should == [str, str, str, str]
|
ary.fill(str).should == [str, str, str, str]
|
||||||
str << "y"
|
str << "y"
|
||||||
ary.should == [str, str, str, str]
|
ary.should == [str, str, str, str]
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
module ArraySpecs
|
module ArraySpecs
|
||||||
def self.array_with_usascii_and_7bit_utf8_strings
|
def self.array_with_usascii_and_7bit_utf8_strings
|
||||||
[
|
[
|
||||||
'foo'.force_encoding('US-ASCII'),
|
'foo'.dup.force_encoding('US-ASCII'),
|
||||||
'bar'
|
'bar'
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.array_with_usascii_and_utf8_strings
|
def self.array_with_usascii_and_utf8_strings
|
||||||
[
|
[
|
||||||
'foo'.force_encoding('US-ASCII'),
|
'foo'.dup.force_encoding('US-ASCII'),
|
||||||
'báz'
|
'báz'
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ module ArraySpecs
|
||||||
def self.array_with_7bit_utf8_and_usascii_strings
|
def self.array_with_7bit_utf8_and_usascii_strings
|
||||||
[
|
[
|
||||||
'bar',
|
'bar',
|
||||||
'foo'.force_encoding('US-ASCII')
|
'foo'.dup.force_encoding('US-ASCII')
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -25,13 +25,13 @@ module ArraySpecs
|
||||||
[
|
[
|
||||||
'báz',
|
'báz',
|
||||||
'bar',
|
'bar',
|
||||||
'foo'.force_encoding('US-ASCII')
|
'foo'.dup.force_encoding('US-ASCII')
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.array_with_usascii_and_utf8_strings
|
def self.array_with_usascii_and_utf8_strings
|
||||||
[
|
[
|
||||||
'foo'.force_encoding('US-ASCII'),
|
'foo'.dup.force_encoding('US-ASCII'),
|
||||||
'bar',
|
'bar',
|
||||||
'báz'
|
'báz'
|
||||||
]
|
]
|
||||||
|
@ -41,7 +41,7 @@ module ArraySpecs
|
||||||
[
|
[
|
||||||
'bar',
|
'bar',
|
||||||
'báz',
|
'báz',
|
||||||
'foo'.force_encoding('BINARY')
|
'foo'.dup.force_encoding('BINARY')
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,14 +55,14 @@ module ArraySpecs
|
||||||
|
|
||||||
def self.array_with_usascii_and_7bit_binary_strings
|
def self.array_with_usascii_and_7bit_binary_strings
|
||||||
[
|
[
|
||||||
'bar'.force_encoding('US-ASCII'),
|
'bar'.dup.force_encoding('US-ASCII'),
|
||||||
'foo'.force_encoding('BINARY')
|
'foo'.dup.force_encoding('BINARY')
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.array_with_usascii_and_binary_strings
|
def self.array_with_usascii_and_binary_strings
|
||||||
[
|
[
|
||||||
'bar'.force_encoding('US-ASCII'),
|
'bar'.dup.force_encoding('US-ASCII'),
|
||||||
[255].pack('C').force_encoding('BINARY')
|
[255].pack('C').force_encoding('BINARY')
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,13 +13,13 @@ describe "Array#pack with :buffer option" do
|
||||||
it "adds result at the end of buffer content" do
|
it "adds result at the end of buffer content" do
|
||||||
n = [ 65, 66, 67 ] # result without buffer is "ABC"
|
n = [ 65, 66, 67 ] # result without buffer is "ABC"
|
||||||
|
|
||||||
buffer = ""
|
buffer = +""
|
||||||
n.pack("ccc", buffer: buffer).should == "ABC"
|
n.pack("ccc", buffer: buffer).should == "ABC"
|
||||||
|
|
||||||
buffer = "123"
|
buffer = +"123"
|
||||||
n.pack("ccc", buffer: buffer).should == "123ABC"
|
n.pack("ccc", buffer: buffer).should == "123ABC"
|
||||||
|
|
||||||
buffer = "12345"
|
buffer = +"12345"
|
||||||
n.pack("ccc", buffer: buffer).should == "12345ABC"
|
n.pack("ccc", buffer: buffer).should == "12345ABC"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -31,19 +31,19 @@ describe "Array#pack with :buffer option" do
|
||||||
context "offset (@) is specified" do
|
context "offset (@) is specified" do
|
||||||
it 'keeps buffer content if it is longer than offset' do
|
it 'keeps buffer content if it is longer than offset' do
|
||||||
n = [ 65, 66, 67 ]
|
n = [ 65, 66, 67 ]
|
||||||
buffer = "123456"
|
buffer = +"123456"
|
||||||
n.pack("@3ccc", buffer: buffer).should == "123ABC"
|
n.pack("@3ccc", buffer: buffer).should == "123ABC"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fills the gap with \\0 if buffer content is shorter than offset" do
|
it "fills the gap with \\0 if buffer content is shorter than offset" do
|
||||||
n = [ 65, 66, 67 ]
|
n = [ 65, 66, 67 ]
|
||||||
buffer = "123"
|
buffer = +"123"
|
||||||
n.pack("@6ccc", buffer: buffer).should == "123\0\0\0ABC"
|
n.pack("@6ccc", buffer: buffer).should == "123\0\0\0ABC"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not keep buffer content if it is longer than offset + result' do
|
it 'does not keep buffer content if it is longer than offset + result' do
|
||||||
n = [ 65, 66, 67 ]
|
n = [ 65, 66, 67 ]
|
||||||
buffer = "1234567890"
|
buffer = +"1234567890"
|
||||||
n.pack("@3ccc", buffer: buffer).should == "123ABC"
|
n.pack("@3ccc", buffer: buffer).should == "123ABC"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,7 +40,7 @@ describe :array_pack_string, shared: true do
|
||||||
f = pack_format("*")
|
f = pack_format("*")
|
||||||
[ [["\u{3042 3044 3046 3048}", 0x2000B].pack(f+"U"), Encoding::BINARY],
|
[ [["\u{3042 3044 3046 3048}", 0x2000B].pack(f+"U"), Encoding::BINARY],
|
||||||
[["abcde\xd1", "\xFF\xFe\x81\x82"].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],
|
[["a".dup.force_encoding("ascii"), "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY],
|
||||||
# under discussion [ruby-dev:37294]
|
# under discussion [ruby-dev:37294]
|
||||||
[["\u{3042 3044 3046 3048}", 1].pack(f+"N"), Encoding::BINARY]
|
[["\u{3042 3044 3046 3048}", 1].pack(f+"N"), Encoding::BINARY]
|
||||||
].should be_computed_by(:encoding)
|
].should be_computed_by(:encoding)
|
||||||
|
|
|
@ -19,7 +19,7 @@ describe :array_inspect, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not call #to_s on a String returned from #inspect" do
|
it "does not call #to_s on a String returned from #inspect" do
|
||||||
str = "abc"
|
str = +"abc"
|
||||||
str.should_not_receive(:to_s)
|
str.should_not_receive(:to_s)
|
||||||
|
|
||||||
[str].send(@method).should == '["abc"]'
|
[str].send(@method).should == '["abc"]'
|
||||||
|
@ -98,8 +98,8 @@ describe :array_inspect, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not raise if inspected result is not default external encoding" do
|
it "does not raise if inspected result is not default external encoding" do
|
||||||
utf_16be = mock("utf_16be")
|
utf_16be = mock(+"utf_16be")
|
||||||
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
|
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode(Encoding::UTF_16BE))
|
||||||
|
|
||||||
[utf_16be].send(@method).should == '["utf_16be \u3042"]'
|
[utf_16be].send(@method).should == '["utf_16be \u3042"]'
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,8 @@ describe "Complex#inspect" do
|
||||||
|
|
||||||
it "calls #inspect on real and imaginary" do
|
it "calls #inspect on real and imaginary" do
|
||||||
real = NumericSpecs::Subclass.new
|
real = NumericSpecs::Subclass.new
|
||||||
real.should_receive(:inspect).and_return("1")
|
# + because of https://bugs.ruby-lang.org/issues/20337
|
||||||
|
real.should_receive(:inspect).and_return(+"1")
|
||||||
imaginary = NumericSpecs::Subclass.new
|
imaginary = NumericSpecs::Subclass.new
|
||||||
imaginary.should_receive(:inspect).and_return("2")
|
imaginary.should_receive(:inspect).and_return("2")
|
||||||
imaginary.should_receive(:<).any_number_of_times.and_return(false)
|
imaginary.should_receive(:<).any_number_of_times.and_return(false)
|
||||||
|
@ -26,7 +27,8 @@ describe "Complex#inspect" do
|
||||||
|
|
||||||
it "adds an `*' before the `i' if the last character of the imaginary part is not numeric" do
|
it "adds an `*' before the `i' if the last character of the imaginary part is not numeric" do
|
||||||
real = NumericSpecs::Subclass.new
|
real = NumericSpecs::Subclass.new
|
||||||
real.should_receive(:inspect).and_return("(1)")
|
# + because of https://bugs.ruby-lang.org/issues/20337
|
||||||
|
real.should_receive(:inspect).and_return(+"(1)")
|
||||||
imaginary = NumericSpecs::Subclass.new
|
imaginary = NumericSpecs::Subclass.new
|
||||||
imaginary.should_receive(:inspect).and_return("(2)")
|
imaginary.should_receive(:inspect).and_return("(2)")
|
||||||
imaginary.should_receive(:<).any_number_of_times.and_return(false)
|
imaginary.should_receive(:<).any_number_of_times.and_return(false)
|
||||||
|
|
|
@ -45,7 +45,8 @@ describe "Complex#to_s" do
|
||||||
|
|
||||||
it "treats real and imaginary parts as strings" do
|
it "treats real and imaginary parts as strings" do
|
||||||
real = NumericSpecs::Subclass.new
|
real = NumericSpecs::Subclass.new
|
||||||
real.should_receive(:to_s).and_return("1")
|
# + because of https://bugs.ruby-lang.org/issues/20337
|
||||||
|
real.should_receive(:to_s).and_return(+"1")
|
||||||
imaginary = NumericSpecs::Subclass.new
|
imaginary = NumericSpecs::Subclass.new
|
||||||
imaginary.should_receive(:to_s).and_return("2")
|
imaginary.should_receive(:to_s).and_return("2")
|
||||||
imaginary.should_receive(:<).any_number_of_times.and_return(false)
|
imaginary.should_receive(:<).any_number_of_times.and_return(false)
|
||||||
|
|
|
@ -47,7 +47,7 @@ describe "Dir.children" do
|
||||||
encoding = Encoding.find("filesystem")
|
encoding = Encoding.find("filesystem")
|
||||||
encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
|
encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
|
||||||
platform_is_not :windows do
|
platform_is_not :windows do
|
||||||
children.should include("こんにちは.txt".force_encoding(encoding))
|
children.should include("こんにちは.txt".dup.force_encoding(encoding))
|
||||||
end
|
end
|
||||||
children.first.encoding.should equal(Encoding.find("filesystem"))
|
children.first.encoding.should equal(Encoding.find("filesystem"))
|
||||||
end
|
end
|
||||||
|
@ -113,7 +113,7 @@ describe "Dir#children" do
|
||||||
encoding = Encoding.find("filesystem")
|
encoding = Encoding.find("filesystem")
|
||||||
encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
|
encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
|
||||||
platform_is_not :windows do
|
platform_is_not :windows do
|
||||||
children.should include("こんにちは.txt".force_encoding(encoding))
|
children.should include("こんにちは.txt".dup.force_encoding(encoding))
|
||||||
end
|
end
|
||||||
children.first.encoding.should equal(Encoding.find("filesystem"))
|
children.first.encoding.should equal(Encoding.find("filesystem"))
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,7 +47,7 @@ describe "Dir.entries" do
|
||||||
encoding = Encoding.find("filesystem")
|
encoding = Encoding.find("filesystem")
|
||||||
encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
|
encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
|
||||||
platform_is_not :windows do
|
platform_is_not :windows do
|
||||||
entries.should include("こんにちは.txt".force_encoding(encoding))
|
entries.should include("こんにちは.txt".dup.force_encoding(encoding))
|
||||||
end
|
end
|
||||||
entries.first.encoding.should equal(Encoding.find("filesystem"))
|
entries.first.encoding.should equal(Encoding.find("filesystem"))
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,7 @@ describe :dir_glob, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an Encoding::CompatibilityError if the argument encoding is not compatible with US-ASCII" do
|
it "raises an Encoding::CompatibilityError if the argument encoding is not compatible with US-ASCII" do
|
||||||
pattern = "file*".force_encoding Encoding::UTF_16BE
|
pattern = "file*".dup.force_encoding Encoding::UTF_16BE
|
||||||
-> { Dir.send(@method, pattern) }.should raise_error(Encoding::CompatibilityError)
|
-> { Dir.send(@method, pattern) }.should raise_error(Encoding::CompatibilityError)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ require_relative '../../spec_helper'
|
||||||
describe "Encoding.compatible? String, String" do
|
describe "Encoding.compatible? String, String" do
|
||||||
describe "when the first's Encoding is valid US-ASCII" do
|
describe "when the first's Encoding is valid US-ASCII" do
|
||||||
before :each do
|
before :each do
|
||||||
@str = "abc".force_encoding Encoding::US_ASCII
|
@str = "abc".dup.force_encoding Encoding::US_ASCII
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns US-ASCII when the second's is US-ASCII" do
|
it "returns US-ASCII when the second's is US-ASCII" do
|
||||||
|
@ -33,28 +33,28 @@ describe "Encoding.compatible? String, String" do
|
||||||
|
|
||||||
describe "when the first's Encoding is ASCII compatible and ASCII only" do
|
describe "when the first's Encoding is ASCII compatible and ASCII only" do
|
||||||
it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
|
it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
|
||||||
[ [Encoding, "abc".force_encoding("UTF-8"), "123".force_encoding("Shift_JIS"), Encoding::UTF_8],
|
[ [Encoding, "abc".dup.force_encoding("UTF-8"), "123".dup.force_encoding("Shift_JIS"), Encoding::UTF_8],
|
||||||
[Encoding, "123".force_encoding("Shift_JIS"), "abc".force_encoding("UTF-8"), Encoding::Shift_JIS]
|
[Encoding, "123".dup.force_encoding("Shift_JIS"), "abc".dup.force_encoding("UTF-8"), Encoding::Shift_JIS]
|
||||||
].should be_computed_by(:compatible?)
|
].should be_computed_by(:compatible?)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
|
it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
|
||||||
[ [Encoding, "abc".force_encoding("BINARY"), "123".force_encoding("US-ASCII"), Encoding::BINARY],
|
[ [Encoding, "abc".dup.force_encoding("BINARY"), "123".dup.force_encoding("US-ASCII"), Encoding::BINARY],
|
||||||
[Encoding, "123".force_encoding("US-ASCII"), "abc".force_encoding("BINARY"), Encoding::US_ASCII]
|
[Encoding, "123".dup.force_encoding("US-ASCII"), "abc".dup.force_encoding("BINARY"), Encoding::US_ASCII]
|
||||||
].should be_computed_by(:compatible?)
|
].should be_computed_by(:compatible?)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the second's Encoding if the second is ASCII compatible but not ASCII only" do
|
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, "abc".dup.force_encoding("UTF-8"), "\xff".dup.force_encoding("Shift_JIS"), Encoding::Shift_JIS],
|
||||||
[Encoding, "123".force_encoding("Shift_JIS"), "\xff".force_encoding("UTF-8"), Encoding::UTF_8],
|
[Encoding, "123".dup.force_encoding("Shift_JIS"), "\xff".dup.force_encoding("UTF-8"), Encoding::UTF_8],
|
||||||
[Encoding, "abc".force_encoding("BINARY"), "\xff".force_encoding("US-ASCII"), Encoding::US_ASCII],
|
[Encoding, "abc".dup.force_encoding("BINARY"), "\xff".dup.force_encoding("US-ASCII"), Encoding::US_ASCII],
|
||||||
[Encoding, "123".force_encoding("US-ASCII"), "\xff".force_encoding("BINARY"), Encoding::BINARY],
|
[Encoding, "123".dup.force_encoding("US-ASCII"), "\xff".dup.force_encoding("BINARY"), Encoding::BINARY],
|
||||||
].should be_computed_by(:compatible?)
|
].should be_computed_by(:compatible?)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil if the second's Encoding is not ASCII compatible" do
|
it "returns nil if the second's Encoding is not ASCII compatible" do
|
||||||
a = "abc".force_encoding("UTF-8")
|
a = "abc".dup.force_encoding("UTF-8")
|
||||||
b = "1234".force_encoding("UTF-16LE")
|
b = "1234".dup.force_encoding("UTF-16LE")
|
||||||
Encoding.compatible?(a, b).should be_nil
|
Encoding.compatible?(a, b).should be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -75,7 +75,7 @@ describe "Encoding.compatible? String, String" do
|
||||||
|
|
||||||
describe "when the first's Encoding is not ASCII compatible" do
|
describe "when the first's Encoding is not ASCII compatible" do
|
||||||
before :each do
|
before :each do
|
||||||
@str = "abc".force_encoding Encoding::UTF_7
|
@str = "abc".dup.force_encoding Encoding::UTF_7
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil when the second String is US-ASCII" do
|
it "returns nil when the second String is US-ASCII" do
|
||||||
|
@ -91,14 +91,14 @@ describe "Encoding.compatible? String, String" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the Encoding when the second's Encoding is not ASCII compatible but the same as the first's Encoding" do
|
it "returns the Encoding when the second's Encoding is not ASCII compatible but the same as the first's Encoding" do
|
||||||
encoding = Encoding.compatible?(@str, "def".force_encoding("utf-7"))
|
encoding = Encoding.compatible?(@str, "def".dup.force_encoding("utf-7"))
|
||||||
encoding.should == Encoding::UTF_7
|
encoding.should == Encoding::UTF_7
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when the first's Encoding is invalid" do
|
describe "when the first's Encoding is invalid" do
|
||||||
before :each do
|
before :each do
|
||||||
@str = "\xff".force_encoding Encoding::UTF_8
|
@str = "\xff".dup.force_encoding Encoding::UTF_8
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the first's Encoding when the second's Encoding is US-ASCII" do
|
it "returns the first's Encoding when the second's Encoding is US-ASCII" do
|
||||||
|
@ -114,11 +114,11 @@ describe "Encoding.compatible? String, String" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil when the second's Encoding is invalid and ASCII only" do
|
it "returns nil when the second's Encoding is invalid and ASCII only" do
|
||||||
Encoding.compatible?(@str, "\x7f".force_encoding("utf-16be")).should be_nil
|
Encoding.compatible?(@str, "\x7f".dup.force_encoding("utf-16be")).should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil when the second's Encoding is invalid and not ASCII only" do
|
it "returns nil when the second's Encoding is invalid and not ASCII only" do
|
||||||
Encoding.compatible?(@str, "\xff".force_encoding("utf-16be")).should be_nil
|
Encoding.compatible?(@str, "\xff".dup.force_encoding("utf-16be")).should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the Encoding when the second's Encoding is invalid but the same as the first" do
|
it "returns the Encoding when the second's Encoding is invalid but the same as the first" do
|
||||||
|
@ -129,7 +129,7 @@ describe "Encoding.compatible? String, String" do
|
||||||
describe "when the first String is empty and the second is not" do
|
describe "when the first String is empty and the second is not" do
|
||||||
describe "and the first's Encoding is ASCII compatible" do
|
describe "and the first's Encoding is ASCII compatible" do
|
||||||
before :each do
|
before :each do
|
||||||
@str = "".force_encoding("utf-8")
|
@str = "".dup.force_encoding("utf-8")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the first's encoding when the second String is ASCII only" do
|
it "returns the first's encoding when the second String is ASCII only" do
|
||||||
|
@ -143,7 +143,7 @@ describe "Encoding.compatible? String, String" do
|
||||||
|
|
||||||
describe "when the first's Encoding is not ASCII compatible" do
|
describe "when the first's Encoding is not ASCII compatible" do
|
||||||
before :each do
|
before :each do
|
||||||
@str = "".force_encoding Encoding::UTF_7
|
@str = "".dup.force_encoding Encoding::UTF_7
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the second string's encoding" do
|
it "returns the second string's encoding" do
|
||||||
|
@ -154,7 +154,7 @@ describe "Encoding.compatible? String, String" do
|
||||||
|
|
||||||
describe "when the second String is empty" do
|
describe "when the second String is empty" do
|
||||||
before :each do
|
before :each do
|
||||||
@str = "abc".force_encoding("utf-7")
|
@str = "abc".dup.force_encoding("utf-7")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the first Encoding" do
|
it "returns the first Encoding" do
|
||||||
|
@ -165,7 +165,7 @@ end
|
||||||
|
|
||||||
describe "Encoding.compatible? String, Regexp" do
|
describe "Encoding.compatible? String, Regexp" do
|
||||||
it "returns US-ASCII if both are US-ASCII" do
|
it "returns US-ASCII if both are US-ASCII" do
|
||||||
str = "abc".force_encoding("us-ascii")
|
str = "abc".dup.force_encoding("us-ascii")
|
||||||
Encoding.compatible?(str, /abc/).should == Encoding::US_ASCII
|
Encoding.compatible?(str, /abc/).should == Encoding::US_ASCII
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -180,15 +180,15 @@ describe "Encoding.compatible? String, Regexp" do
|
||||||
it "returns the String's Encoding if the String is not ASCII only" do
|
it "returns the String's Encoding if the String is not ASCII only" do
|
||||||
[ [Encoding, "\xff", Encoding::BINARY],
|
[ [Encoding, "\xff", Encoding::BINARY],
|
||||||
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
|
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
|
||||||
[Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
|
[Encoding, "\xa4\xa2".dup.force_encoding("euc-jp"), Encoding::EUC_JP],
|
||||||
[Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
|
[Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS],
|
||||||
].should be_computed_by(:compatible?, /abc/)
|
].should be_computed_by(:compatible?, /abc/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Encoding.compatible? String, Symbol" do
|
describe "Encoding.compatible? String, Symbol" do
|
||||||
it "returns US-ASCII if both are ASCII only" do
|
it "returns US-ASCII if both are ASCII only" do
|
||||||
str = "abc".force_encoding("us-ascii")
|
str = "abc".dup.force_encoding("us-ascii")
|
||||||
Encoding.compatible?(str, :abc).should == Encoding::US_ASCII
|
Encoding.compatible?(str, :abc).should == Encoding::US_ASCII
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -203,8 +203,8 @@ describe "Encoding.compatible? String, Symbol" do
|
||||||
it "returns the String's Encoding if the String is not ASCII only" do
|
it "returns the String's Encoding if the String is not ASCII only" do
|
||||||
[ [Encoding, "\xff", Encoding::BINARY],
|
[ [Encoding, "\xff", Encoding::BINARY],
|
||||||
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
|
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
|
||||||
[Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
|
[Encoding, "\xa4\xa2".dup.force_encoding("euc-jp"), Encoding::EUC_JP],
|
||||||
[Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
|
[Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS],
|
||||||
].should be_computed_by(:compatible?, :abc)
|
].should be_computed_by(:compatible?, :abc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -221,8 +221,8 @@ describe "Encoding.compatible? String, Encoding" do
|
||||||
it "returns the String's encoding if the Encoding is US-ASCII" do
|
it "returns the String's encoding if the Encoding is US-ASCII" do
|
||||||
[ [Encoding, "\xff", Encoding::BINARY],
|
[ [Encoding, "\xff", Encoding::BINARY],
|
||||||
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
|
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
|
||||||
[Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
|
[Encoding, "\xa4\xa2".dup.force_encoding("euc-jp"), Encoding::EUC_JP],
|
||||||
[Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
|
[Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS],
|
||||||
].should be_computed_by(:compatible?, Encoding::US_ASCII)
|
].should be_computed_by(:compatible?, Encoding::US_ASCII)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ end
|
||||||
|
|
||||||
describe "Encoding.compatible? Regexp, String" do
|
describe "Encoding.compatible? Regexp, String" do
|
||||||
it "returns US-ASCII if both are US-ASCII" do
|
it "returns US-ASCII if both are US-ASCII" do
|
||||||
str = "abc".force_encoding("us-ascii")
|
str = "abc".dup.force_encoding("us-ascii")
|
||||||
Encoding.compatible?(/abc/, str).should == Encoding::US_ASCII
|
Encoding.compatible?(/abc/, str).should == Encoding::US_ASCII
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -256,8 +256,8 @@ describe "Encoding.compatible? Regexp, Regexp" do
|
||||||
it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
|
it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
|
||||||
[ [Encoding, Regexp.new("\xff"), Encoding::BINARY],
|
[ [Encoding, Regexp.new("\xff"), Encoding::BINARY],
|
||||||
[Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
|
[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("\xa4\xa2".dup.force_encoding("euc-jp")), Encoding::EUC_JP],
|
||||||
[Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
|
[Encoding, Regexp.new("\x82\xa0".dup.force_encoding("shift_jis")), Encoding::Shift_JIS],
|
||||||
].should be_computed_by(:compatible?, /abc/)
|
].should be_computed_by(:compatible?, /abc/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -270,15 +270,15 @@ describe "Encoding.compatible? Regexp, Symbol" do
|
||||||
it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
|
it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
|
||||||
[ [Encoding, Regexp.new("\xff"), Encoding::BINARY],
|
[ [Encoding, Regexp.new("\xff"), Encoding::BINARY],
|
||||||
[Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
|
[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("\xa4\xa2".dup.force_encoding("euc-jp")), Encoding::EUC_JP],
|
||||||
[Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
|
[Encoding, Regexp.new("\x82\xa0".dup.force_encoding("shift_jis")), Encoding::Shift_JIS],
|
||||||
].should be_computed_by(:compatible?, /abc/)
|
].should be_computed_by(:compatible?, /abc/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Encoding.compatible? Symbol, String" do
|
describe "Encoding.compatible? Symbol, String" do
|
||||||
it "returns US-ASCII if both are ASCII only" do
|
it "returns US-ASCII if both are ASCII only" do
|
||||||
str = "abc".force_encoding("us-ascii")
|
str = "abc".dup.force_encoding("us-ascii")
|
||||||
Encoding.compatible?(str, :abc).should == Encoding::US_ASCII
|
Encoding.compatible?(str, :abc).should == Encoding::US_ASCII
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -291,8 +291,8 @@ describe "Encoding.compatible? Symbol, Regexp" do
|
||||||
it "returns the Regexp's Encoding if it is not US-ASCII and not ASCII only" do
|
it "returns the Regexp's Encoding if it is not US-ASCII and not ASCII only" do
|
||||||
a = Regexp.new("\xff")
|
a = Regexp.new("\xff")
|
||||||
b = Regexp.new("\u3042".encode("utf-8"))
|
b = Regexp.new("\u3042".encode("utf-8"))
|
||||||
c = Regexp.new("\xa4\xa2".force_encoding("euc-jp"))
|
c = Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp"))
|
||||||
d = Regexp.new("\x82\xa0".force_encoding("shift_jis"))
|
d = Regexp.new("\x82\xa0".dup.force_encoding("shift_jis"))
|
||||||
|
|
||||||
[ [Encoding, :abc, a, Encoding::BINARY],
|
[ [Encoding, :abc, a, Encoding::BINARY],
|
||||||
[Encoding, :abc, b, Encoding::UTF_8],
|
[Encoding, :abc, b, Encoding::UTF_8],
|
||||||
|
@ -310,8 +310,8 @@ describe "Encoding.compatible? Symbol, Symbol" do
|
||||||
it "returns the first's Encoding if it is not ASCII only" do
|
it "returns the first's Encoding if it is not ASCII only" do
|
||||||
[ [Encoding, "\xff".to_sym, Encoding::BINARY],
|
[ [Encoding, "\xff".to_sym, Encoding::BINARY],
|
||||||
[Encoding, "\u3042".encode("utf-8").to_sym, Encoding::UTF_8],
|
[Encoding, "\u3042".encode("utf-8").to_sym, Encoding::UTF_8],
|
||||||
[Encoding, "\xa4\xa2".force_encoding("euc-jp").to_sym, Encoding::EUC_JP],
|
[Encoding, "\xa4\xa2".dup.force_encoding("euc-jp").to_sym, Encoding::EUC_JP],
|
||||||
[Encoding, "\x82\xa0".force_encoding("shift_jis").to_sym, Encoding::Shift_JIS],
|
[Encoding, "\x82\xa0".dup.force_encoding("shift_jis").to_sym, Encoding::Shift_JIS],
|
||||||
].should be_computed_by(:compatible?, :abc)
|
].should be_computed_by(:compatible?, :abc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: binary -*-
|
# -*- encoding: binary -*-
|
||||||
|
# frozen_string_literal: true
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "Encoding::Converter#convert" do
|
describe "Encoding::Converter#convert" do
|
||||||
|
@ -9,31 +10,31 @@ describe "Encoding::Converter#convert" do
|
||||||
|
|
||||||
it "sets the encoding of the result to the target encoding" do
|
it "sets the encoding of the result to the target encoding" do
|
||||||
ec = Encoding::Converter.new('ascii', 'utf-8')
|
ec = Encoding::Converter.new('ascii', 'utf-8')
|
||||||
str = 'glark'.force_encoding('ascii')
|
str = 'glark'.dup.force_encoding('ascii')
|
||||||
ec.convert(str).encoding.should == Encoding::UTF_8
|
ec.convert(str).encoding.should == Encoding::UTF_8
|
||||||
end
|
end
|
||||||
|
|
||||||
it "transcodes the given String to the target encoding" do
|
it "transcodes the given String to the target encoding" do
|
||||||
ec = Encoding::Converter.new("utf-8", "euc-jp")
|
ec = Encoding::Converter.new("utf-8", "euc-jp")
|
||||||
ec.convert("\u3042".force_encoding('UTF-8')).should == \
|
ec.convert("\u3042".dup.force_encoding('UTF-8')).should == \
|
||||||
"\xA4\xA2".force_encoding('EUC-JP')
|
"\xA4\xA2".dup.force_encoding('EUC-JP')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows Strings of different encodings to the source encoding" do
|
it "allows Strings of different encodings to the source encoding" do
|
||||||
ec = Encoding::Converter.new('ascii', 'utf-8')
|
ec = Encoding::Converter.new('ascii', 'utf-8')
|
||||||
str = 'glark'.force_encoding('SJIS')
|
str = 'glark'.dup.force_encoding('SJIS')
|
||||||
ec.convert(str).encoding.should == Encoding::UTF_8
|
ec.convert(str).encoding.should == Encoding::UTF_8
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reuses the given encoding pair if called multiple times" do
|
it "reuses the given encoding pair if called multiple times" do
|
||||||
ec = Encoding::Converter.new('ascii', 'SJIS')
|
ec = Encoding::Converter.new('ascii', 'SJIS')
|
||||||
ec.convert('a'.force_encoding('ASCII')).should == 'a'.force_encoding('SJIS')
|
ec.convert('a'.dup.force_encoding('ASCII')).should == 'a'.dup.force_encoding('SJIS')
|
||||||
ec.convert('b'.force_encoding('ASCII')).should == 'b'.force_encoding('SJIS')
|
ec.convert('b'.dup.force_encoding('ASCII')).should == 'b'.dup.force_encoding('SJIS')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises UndefinedConversionError if the String contains characters invalid for the target encoding" do
|
it "raises UndefinedConversionError if the String contains characters invalid for the target encoding" do
|
||||||
ec = Encoding::Converter.new('UTF-8', Encoding.find('macCyrillic'))
|
ec = Encoding::Converter.new('UTF-8', Encoding.find('macCyrillic'))
|
||||||
-> { ec.convert("\u{6543}".force_encoding('UTF-8')) }.should \
|
-> { ec.convert("\u{6543}".dup.force_encoding('UTF-8')) }.should \
|
||||||
raise_error(Encoding::UndefinedConversionError)
|
raise_error(Encoding::UndefinedConversionError)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ describe "Encoding::Converter#finish" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the last part of the converted String if it hasn't already" do
|
it "returns the last part of the converted String if it hasn't already" do
|
||||||
@ec.convert("\u{9999}").should == "\e$B9a".force_encoding('iso-2022-jp')
|
@ec.convert("\u{9999}").should == "\e$B9a".dup.force_encoding('iso-2022-jp')
|
||||||
@ec.finish.should == "\e(B".force_encoding('iso-2022-jp')
|
@ec.finish.should == "\e(B".dup.force_encoding('iso-2022-jp')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a String in the destination encoding" do
|
it "returns a String in the destination encoding" do
|
||||||
|
|
|
@ -9,45 +9,45 @@ describe "Encoding::Converter#last_error" do
|
||||||
|
|
||||||
it "returns nil when the last conversion did not produce an error" do
|
it "returns nil when the last conversion did not produce an error" do
|
||||||
ec = Encoding::Converter.new('ascii','utf-8')
|
ec = Encoding::Converter.new('ascii','utf-8')
|
||||||
ec.convert('a'.force_encoding('ascii'))
|
ec.convert('a'.dup.force_encoding('ascii'))
|
||||||
ec.last_error.should be_nil
|
ec.last_error.should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil when #primitive_convert last returned :destination_buffer_full" do
|
it "returns nil when #primitive_convert last returned :destination_buffer_full" do
|
||||||
ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
|
ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
|
||||||
ec.primitive_convert("\u{9999}", "", 0, 0, partial_input: false) \
|
ec.primitive_convert(+"\u{9999}", +"", 0, 0, partial_input: false) \
|
||||||
.should == :destination_buffer_full
|
.should == :destination_buffer_full
|
||||||
ec.last_error.should be_nil
|
ec.last_error.should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil when #primitive_convert last returned :finished" do
|
it "returns nil when #primitive_convert last returned :finished" do
|
||||||
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
|
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
|
||||||
ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
|
ec.primitive_convert("glark".dup.force_encoding('utf-8'), +"").should == :finished
|
||||||
ec.last_error.should be_nil
|
ec.last_error.should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil if the last conversion succeeded but the penultimate failed" do
|
it "returns nil if the last conversion succeeded but the penultimate failed" do
|
||||||
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
|
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
|
||||||
ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
|
ec.primitive_convert(+"\xf1abcd", +"").should == :invalid_byte_sequence
|
||||||
ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
|
ec.primitive_convert("glark".dup.force_encoding('utf-8'), +"").should == :finished
|
||||||
ec.last_error.should be_nil
|
ec.last_error.should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :invalid_byte_sequence" do
|
it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :invalid_byte_sequence" do
|
||||||
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
|
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
|
||||||
ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
|
ec.primitive_convert(+"\xf1abcd", +"").should == :invalid_byte_sequence
|
||||||
ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
|
ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns an Encoding::UndefinedConversionError when #primitive_convert last returned :undefined_conversion" do
|
it "returns an Encoding::UndefinedConversionError when #primitive_convert last returned :undefined_conversion" do
|
||||||
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
|
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
|
||||||
ec.primitive_convert("\u{9876}","").should == :undefined_conversion
|
ec.primitive_convert(+"\u{9876}", +"").should == :undefined_conversion
|
||||||
ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
|
ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :incomplete_input" do
|
it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :incomplete_input" do
|
||||||
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
|
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
|
||||||
ec.primitive_convert("\xa4", "", nil, 10).should == :incomplete_input
|
ec.primitive_convert(+"\xa4", +"", nil, 10).should == :incomplete_input
|
||||||
ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
|
ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ describe "Encoding::Converter.new" do
|
||||||
|
|
||||||
it "sets the replacement String to '\\uFFFD'" do
|
it "sets the replacement String to '\\uFFFD'" do
|
||||||
conv = Encoding::Converter.new("us-ascii", "utf-8", replace: nil)
|
conv = Encoding::Converter.new("us-ascii", "utf-8", replace: nil)
|
||||||
conv.replacement.should == "\u{fffd}".force_encoding("utf-8")
|
conv.replacement.should == "\u{fffd}".dup.force_encoding("utf-8")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets the replacement String encoding to UTF-8" do
|
it "sets the replacement String encoding to UTF-8" do
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: binary -*-
|
# -*- encoding: binary -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "Encoding::Converter#primitive_convert" do
|
describe "Encoding::Converter#primitive_convert" do
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: binary -*-
|
# -*- encoding: binary -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../../spec_helper'
|
require_relative '../../../spec_helper'
|
||||||
|
|
||||||
describe "Encoding::Converter#primitive_errinfo" do
|
describe "Encoding::Converter#primitive_errinfo" do
|
||||||
|
|
|
@ -4,7 +4,7 @@ require_relative '../../../spec_helper'
|
||||||
describe "Encoding::Converter#putback" do
|
describe "Encoding::Converter#putback" do
|
||||||
before :each do
|
before :each do
|
||||||
@ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
|
@ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
|
||||||
@ret = @ec.primitive_convert(@src="abc\xa1def", @dst="", nil, 10)
|
@ret = @ec.primitive_convert(@src=+"abc\xa1def", @dst=+"", nil, 10)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a String" do
|
it "returns a String" do
|
||||||
|
@ -36,21 +36,21 @@ describe "Encoding::Converter#putback" do
|
||||||
|
|
||||||
it "returns the problematic bytes for UTF-16LE" do
|
it "returns the problematic bytes for UTF-16LE" do
|
||||||
ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
|
ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
|
||||||
src = "\x00\xd8\x61\x00"
|
src = +"\x00\xd8\x61\x00"
|
||||||
dst = ""
|
dst = +""
|
||||||
ec.primitive_convert(src, dst).should == :invalid_byte_sequence
|
ec.primitive_convert(src, dst).should == :invalid_byte_sequence
|
||||||
ec.primitive_errinfo.should == [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"]
|
ec.primitive_errinfo.should == [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"]
|
||||||
ec.putback.should == "a\x00".force_encoding("utf-16le")
|
ec.putback.should == "a\x00".dup.force_encoding("utf-16le")
|
||||||
ec.putback.should == ""
|
ec.putback.should == ""
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts an integer argument corresponding to the number of bytes to be put back" do
|
it "accepts an integer argument corresponding to the number of bytes to be put back" do
|
||||||
ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
|
ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
|
||||||
src = "\x00\xd8\x61\x00"
|
src = +"\x00\xd8\x61\x00"
|
||||||
dst = ""
|
dst = +""
|
||||||
ec.primitive_convert(src, dst).should == :invalid_byte_sequence
|
ec.primitive_convert(src, dst).should == :invalid_byte_sequence
|
||||||
ec.primitive_errinfo.should == [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"]
|
ec.primitive_errinfo.should == [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"]
|
||||||
ec.putback(2).should == "a\x00".force_encoding("utf-16le")
|
ec.putback(2).should == "a\x00".dup.force_encoding("utf-16le")
|
||||||
ec.putback.should == ""
|
ec.putback.should == ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,7 @@ describe "Encoding::Converter#replacement" do
|
||||||
|
|
||||||
it "returns \\uFFFD when the destination encoding is UTF-8" do
|
it "returns \\uFFFD when the destination encoding is UTF-8" do
|
||||||
ec = Encoding::Converter.new("us-ascii", "utf-8")
|
ec = Encoding::Converter.new("us-ascii", "utf-8")
|
||||||
ec.replacement.should == "\u{fffd}".force_encoding('utf-8')
|
ec.replacement.should == "\u{fffd}".dup.force_encoding('utf-8')
|
||||||
ec.replacement.encoding.should == Encoding::UTF_8
|
ec.replacement.encoding.should == Encoding::UTF_8
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -38,33 +38,33 @@ describe "Encoding::Converter#replacement=" do
|
||||||
|
|
||||||
it "sets #replacement" do
|
it "sets #replacement" do
|
||||||
ec = Encoding::Converter.new("us-ascii", "utf-8")
|
ec = Encoding::Converter.new("us-ascii", "utf-8")
|
||||||
ec.replacement.should == "\u{fffd}".force_encoding('utf-8')
|
ec.replacement.should == "\u{fffd}".dup.force_encoding('utf-8')
|
||||||
ec.replacement = '?'.encode('utf-8')
|
ec.replacement = '?'.encode('utf-8')
|
||||||
ec.replacement.should == '?'.force_encoding('utf-8')
|
ec.replacement.should == '?'.dup.force_encoding('utf-8')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an UndefinedConversionError is the argument cannot be converted into the destination encoding" do
|
it "raises an UndefinedConversionError is the argument cannot be converted into the destination encoding" do
|
||||||
ec = Encoding::Converter.new("sjis", "ascii")
|
ec = Encoding::Converter.new("sjis", "ascii")
|
||||||
utf8_q = "\u{986}".force_encoding('utf-8')
|
utf8_q = "\u{986}".dup.force_encoding('utf-8')
|
||||||
ec.primitive_convert(utf8_q.dup, "").should == :undefined_conversion
|
ec.primitive_convert(utf8_q.dup, +"").should == :undefined_conversion
|
||||||
-> { ec.replacement = utf8_q }.should \
|
-> { ec.replacement = utf8_q }.should \
|
||||||
raise_error(Encoding::UndefinedConversionError)
|
raise_error(Encoding::UndefinedConversionError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not change the replacement character if the argument cannot be converted into the destination encoding" do
|
it "does not change the replacement character if the argument cannot be converted into the destination encoding" do
|
||||||
ec = Encoding::Converter.new("sjis", "ascii")
|
ec = Encoding::Converter.new("sjis", "ascii")
|
||||||
utf8_q = "\u{986}".force_encoding('utf-8')
|
utf8_q = "\u{986}".dup.force_encoding('utf-8')
|
||||||
ec.primitive_convert(utf8_q.dup, "").should == :undefined_conversion
|
ec.primitive_convert(utf8_q.dup, +"").should == :undefined_conversion
|
||||||
-> { ec.replacement = utf8_q }.should \
|
-> { ec.replacement = utf8_q }.should \
|
||||||
raise_error(Encoding::UndefinedConversionError)
|
raise_error(Encoding::UndefinedConversionError)
|
||||||
ec.replacement.should == "?".force_encoding('us-ascii')
|
ec.replacement.should == "?".dup.force_encoding('us-ascii')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "uses the replacement character" do
|
it "uses the replacement character" do
|
||||||
ec = Encoding::Converter.new("utf-8", "us-ascii", :invalid => :replace, :undef => :replace)
|
ec = Encoding::Converter.new("utf-8", "us-ascii", :invalid => :replace, :undef => :replace)
|
||||||
ec.replacement = "!"
|
ec.replacement = "!"
|
||||||
dest = ""
|
dest = +""
|
||||||
status = ec.primitive_convert "中文123", dest
|
status = ec.primitive_convert(+"中文123", dest)
|
||||||
|
|
||||||
status.should == :finished
|
status.should == :finished
|
||||||
dest.should == "!!123"
|
dest.should == "!!123"
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe "Encoding::InvalidByteSequenceError#incomplete_input?" do
|
||||||
|
|
||||||
it "returns true if #primitive_convert returned :incomplete_input for the same data" do
|
it "returns true if #primitive_convert returned :incomplete_input for the same data" do
|
||||||
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
|
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
|
||||||
ec.primitive_convert("\xA1",'').should == :incomplete_input
|
ec.primitive_convert(+"\xA1", +'').should == :incomplete_input
|
||||||
begin
|
begin
|
||||||
ec.convert("\xA1")
|
ec.convert("\xA1")
|
||||||
rescue Encoding::InvalidByteSequenceError => e
|
rescue Encoding::InvalidByteSequenceError => e
|
||||||
|
@ -18,7 +18,7 @@ describe "Encoding::InvalidByteSequenceError#incomplete_input?" do
|
||||||
|
|
||||||
it "returns false if #primitive_convert returned :invalid_byte_sequence for the same data" do
|
it "returns false if #primitive_convert returned :invalid_byte_sequence for the same data" do
|
||||||
ec = Encoding::Converter.new("ascii", "utf-8")
|
ec = Encoding::Converter.new("ascii", "utf-8")
|
||||||
ec.primitive_convert("\xfffffffff",'').should == :invalid_byte_sequence
|
ec.primitive_convert(+"\xfffffffff", +'').should == :invalid_byte_sequence
|
||||||
begin
|
begin
|
||||||
ec.convert("\xfffffffff")
|
ec.convert("\xfffffffff")
|
||||||
rescue Encoding::InvalidByteSequenceError => e
|
rescue Encoding::InvalidByteSequenceError => e
|
||||||
|
|
|
@ -15,11 +15,11 @@ describe "Encoding::InvalidByteSequenceError#readagain_bytes" do
|
||||||
|
|
||||||
it "returns the bytes to be read again" do
|
it "returns the bytes to be read again" do
|
||||||
@exception.readagain_bytes.size.should == 1
|
@exception.readagain_bytes.size.should == 1
|
||||||
@exception.readagain_bytes.should == "a".force_encoding('binary')
|
@exception.readagain_bytes.should == "a".dup.force_encoding('binary')
|
||||||
@exception.readagain_bytes.should == @errinfo[-1]
|
@exception.readagain_bytes.should == @errinfo[-1]
|
||||||
|
|
||||||
@exception2.readagain_bytes.size.should == 1
|
@exception2.readagain_bytes.size.should == 1
|
||||||
@exception2.readagain_bytes.should == "\xFF".force_encoding('binary')
|
@exception2.readagain_bytes.should == "\xFF".dup.force_encoding('binary')
|
||||||
@exception2.readagain_bytes.should == @errinfo2[-1]
|
@exception2.readagain_bytes.should == @errinfo2[-1]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,8 @@ describe "Encoding#replicate" do
|
||||||
e.name.should == name
|
e.name.should == name
|
||||||
Encoding.find(name).should == e
|
Encoding.find(name).should == e
|
||||||
|
|
||||||
"a".force_encoding(e).valid_encoding?.should be_true
|
"a".dup.force_encoding(e).valid_encoding?.should be_true
|
||||||
"\x80".force_encoding(e).valid_encoding?.should be_false
|
"\x80".dup.force_encoding(e).valid_encoding?.should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a replica of UTF-8" do
|
it "returns a replica of UTF-8" do
|
||||||
|
@ -28,9 +28,9 @@ describe "Encoding#replicate" do
|
||||||
e.name.should == name
|
e.name.should == name
|
||||||
Encoding.find(name).should == e
|
Encoding.find(name).should == e
|
||||||
|
|
||||||
"a".force_encoding(e).valid_encoding?.should be_true
|
"a".dup.force_encoding(e).valid_encoding?.should be_true
|
||||||
"\u3042".force_encoding(e).valid_encoding?.should be_true
|
"\u3042".dup.force_encoding(e).valid_encoding?.should be_true
|
||||||
"\x80".force_encoding(e).valid_encoding?.should be_false
|
"\x80".dup.force_encoding(e).valid_encoding?.should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a replica of UTF-16BE" do
|
it "returns a replica of UTF-16BE" do
|
||||||
|
@ -39,9 +39,9 @@ describe "Encoding#replicate" do
|
||||||
e.name.should == name
|
e.name.should == name
|
||||||
Encoding.find(name).should == e
|
Encoding.find(name).should == e
|
||||||
|
|
||||||
"a".force_encoding(e).valid_encoding?.should be_false
|
"a".dup.force_encoding(e).valid_encoding?.should be_false
|
||||||
"\x30\x42".force_encoding(e).valid_encoding?.should be_true
|
"\x30\x42".dup.force_encoding(e).valid_encoding?.should be_true
|
||||||
"\x80".force_encoding(e).valid_encoding?.should be_false
|
"\x80".dup.force_encoding(e).valid_encoding?.should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a replica of ISO-2022-JP" do
|
it "returns a replica of ISO-2022-JP" do
|
||||||
|
@ -61,7 +61,7 @@ describe "Encoding#replicate" do
|
||||||
e.name.should == name
|
e.name.should == name
|
||||||
Encoding.find(name).should == e
|
Encoding.find(name).should == e
|
||||||
|
|
||||||
s = "abc".force_encoding(e)
|
s = "abc".dup.force_encoding(e)
|
||||||
s.encoding.should == e
|
s.encoding.should == e
|
||||||
s.encoding.name.should == name
|
s.encoding.name.should == name
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,14 +23,6 @@ ruby_version_is "3.2" do
|
||||||
product.size.should == Float::INFINITY
|
product.size.should == Float::INFINITY
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns -Float::INFINITY if any enumerable reports its size as -Float::INFINITY" do
|
|
||||||
enum = Object.new
|
|
||||||
def enum.size; -Float::INFINITY; end
|
|
||||||
|
|
||||||
product = Enumerator::Product.new(1..2, enum)
|
|
||||||
product.size.should == -Float::INFINITY
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns nil if any enumerable reports its size as Float::NAN" do
|
it "returns nil if any enumerable reports its size as Float::NAN" do
|
||||||
enum = Object.new
|
enum = Object.new
|
||||||
def enum.size; Float::NAN; end
|
def enum.size; Float::NAN; end
|
||||||
|
|
|
@ -137,7 +137,7 @@ describe "File.expand_path" do
|
||||||
it "returns a String in the same encoding as the argument" do
|
it "returns a String in the same encoding as the argument" do
|
||||||
Encoding.default_external = Encoding::SHIFT_JIS
|
Encoding.default_external = Encoding::SHIFT_JIS
|
||||||
|
|
||||||
path = "./a".force_encoding Encoding::CP1251
|
path = "./a".dup.force_encoding Encoding::CP1251
|
||||||
File.expand_path(path).encoding.should equal(Encoding::CP1251)
|
File.expand_path(path).encoding.should equal(Encoding::CP1251)
|
||||||
|
|
||||||
weird_path = [222, 173, 190, 175].pack('C*')
|
weird_path = [222, 173, 190, 175].pack('C*')
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
describe :file_path, shared: true do
|
describe :file_path, shared: true do
|
||||||
before :each do
|
before :each do
|
||||||
@name = "file_to_path"
|
@path = tmp("file_to_path")
|
||||||
@path = tmp(@name)
|
@name = File.basename(@path)
|
||||||
touch @path
|
touch @path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,11 @@ describe "Hash#assoc" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "only returns the first matching key-value pair for identity hashes" do
|
it "only returns the first matching key-value pair for identity hashes" do
|
||||||
# Avoid literal String keys in Hash#[]= due to https://bugs.ruby-lang.org/issues/12855
|
# Avoid literal String keys since string literals can be frozen and interned e.g. with --enable-frozen-string-literal
|
||||||
h = {}.compare_by_identity
|
h = {}.compare_by_identity
|
||||||
k1 = 'pear'
|
k1 = 'pear'.dup
|
||||||
h[k1] = :red
|
h[k1] = :red
|
||||||
k2 = 'pear'
|
k2 = 'pear'.dup
|
||||||
h[k2] = :green
|
h[k2] = :green
|
||||||
h.size.should == 2
|
h.size.should == 2
|
||||||
h.keys.grep(/pear/).size.should == 2
|
h.keys.grep(/pear/).size.should == 2
|
||||||
|
|
|
@ -85,19 +85,21 @@ describe "Hash#compare_by_identity" do
|
||||||
-> { @h.compare_by_identity }.should raise_error(FrozenError)
|
-> { @h.compare_by_identity }.should raise_error(FrozenError)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Behaviour confirmed in bug #1871
|
# Behaviour confirmed in https://bugs.ruby-lang.org/issues/1871
|
||||||
it "persists over #dups" do
|
it "persists over #dups" do
|
||||||
@idh['foo'] = :bar
|
@idh['foo'.dup] = :bar
|
||||||
@idh['foo'] = :glark
|
@idh['foo'.dup] = :glark
|
||||||
@idh.dup.should == @idh
|
@idh.dup.should == @idh
|
||||||
@idh.dup.size.should == @idh.size
|
@idh.dup.size.should == @idh.size
|
||||||
|
@idh.dup.should.compare_by_identity?
|
||||||
end
|
end
|
||||||
|
|
||||||
it "persists over #clones" do
|
it "persists over #clones" do
|
||||||
@idh['foo'] = :bar
|
@idh['foo'.dup] = :bar
|
||||||
@idh['foo'] = :glark
|
@idh['foo'.dup] = :glark
|
||||||
@idh.clone.should == @idh
|
@idh.clone.should == @idh
|
||||||
@idh.clone.size.should == @idh.size
|
@idh.clone.size.should == @idh.size
|
||||||
|
@idh.dup.should.compare_by_identity?
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not copy string keys" do
|
it "does not copy string keys" do
|
||||||
|
@ -109,8 +111,11 @@ describe "Hash#compare_by_identity" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "gives different identity for string literals" do
|
it "gives different identity for string literals" do
|
||||||
|
eval <<~RUBY
|
||||||
|
# frozen_string_literal: false
|
||||||
@idh['foo'] = 1
|
@idh['foo'] = 1
|
||||||
@idh['foo'] = 2
|
@idh['foo'] = 2
|
||||||
|
RUBY
|
||||||
@idh.values.should == [1, 2]
|
@idh.values.should == [1, 2]
|
||||||
@idh.size.should == 2
|
@idh.size.should == 2
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,7 +30,7 @@ describe "Hash#[]" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not create copies of the immediate default value" do
|
it "does not create copies of the immediate default value" do
|
||||||
str = "foo"
|
str = +"foo"
|
||||||
h = Hash.new(str)
|
h = Hash.new(str)
|
||||||
a = h[:a]
|
a = h[:a]
|
||||||
b = h[:b]
|
b = h[:b]
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe :hash_store, shared: true do
|
||||||
|
|
||||||
it "duplicates string keys using dup semantics" do
|
it "duplicates string keys using dup semantics" do
|
||||||
# dup doesn't copy singleton methods
|
# dup doesn't copy singleton methods
|
||||||
key = "foo"
|
key = +"foo"
|
||||||
def key.reverse() "bar" end
|
def key.reverse() "bar" end
|
||||||
h = {}
|
h = {}
|
||||||
h.send(@method, key, 0)
|
h.send(@method, key, 0)
|
||||||
|
@ -44,7 +44,7 @@ describe :hash_store, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "duplicates and freezes string keys" do
|
it "duplicates and freezes string keys" do
|
||||||
key = "foo"
|
key = +"foo"
|
||||||
h = {}
|
h = {}
|
||||||
h.send(@method, key, 0)
|
h.send(@method, key, 0)
|
||||||
key << "bar"
|
key << "bar"
|
||||||
|
@ -75,8 +75,8 @@ describe :hash_store, shared: true do
|
||||||
|
|
||||||
it "keeps the existing String key in the hash if there is a matching one" do
|
it "keeps the existing String key in the hash if there is a matching one" do
|
||||||
h = { "a" => 1, "b" => 2, "c" => 3, "d" => 4 }
|
h = { "a" => 1, "b" => 2, "c" => 3, "d" => 4 }
|
||||||
key1 = "foo"
|
key1 = "foo".dup
|
||||||
key2 = "foo"
|
key2 = "foo".dup
|
||||||
key1.should_not equal(key2)
|
key1.should_not equal(key2)
|
||||||
h[key1] = 41
|
h[key1] = 41
|
||||||
frozen_key = h.keys.last
|
frozen_key = h.keys.last
|
||||||
|
|
|
@ -24,7 +24,7 @@ describe :hash_to_s, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not call #to_s on a String returned from #inspect" do
|
it "does not call #to_s on a String returned from #inspect" do
|
||||||
str = "abc"
|
str = +"abc"
|
||||||
str.should_not_receive(:to_s)
|
str.should_not_receive(:to_s)
|
||||||
|
|
||||||
{ a: str }.send(@method).should == '{:a=>"abc"}'
|
{ a: str }.send(@method).should == '{:a=>"abc"}'
|
||||||
|
@ -78,7 +78,7 @@ describe :hash_to_s, shared: true do
|
||||||
|
|
||||||
it "does not raise if inspected result is not default external encoding" do
|
it "does not raise if inspected result is not default external encoding" do
|
||||||
utf_16be = mock("utf_16be")
|
utf_16be = mock("utf_16be")
|
||||||
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
|
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode(Encoding::UTF_16BE))
|
||||||
|
|
||||||
{a: utf_16be}.send(@method).should == '{:a=>"utf_16be \u3042"}'
|
{a: utf_16be}.send(@method).should == '{:a=>"utf_16be \u3042"}'
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,7 @@ describe "IO#ioctl" do
|
||||||
guard -> { RUBY_PLATFORM.include?("86") } do # x86 / x86_64
|
guard -> { RUBY_PLATFORM.include?("86") } do # x86 / x86_64
|
||||||
it "resizes an empty String to match the output size" do
|
it "resizes an empty String to match the output size" do
|
||||||
File.open(__FILE__, 'r') do |f|
|
File.open(__FILE__, 'r') do |f|
|
||||||
buffer = ''
|
buffer = +''
|
||||||
# FIONREAD in /usr/include/asm-generic/ioctls.h
|
# FIONREAD in /usr/include/asm-generic/ioctls.h
|
||||||
f.ioctl 0x541B, buffer
|
f.ioctl 0x541B, buffer
|
||||||
buffer.unpack('I').first.should be_kind_of(Integer)
|
buffer.unpack('I').first.should be_kind_of(Integer)
|
||||||
|
|
|
@ -21,19 +21,19 @@ guard -> { platform_is_not :windows or ruby_version_is "3.3" } do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts a length, an offset, and an output buffer" do
|
it "accepts a length, an offset, and an output buffer" do
|
||||||
buffer = "foo"
|
buffer = +"foo"
|
||||||
@file.pread(3, 4, buffer)
|
@file.pread(3, 4, buffer)
|
||||||
buffer.should == "567"
|
buffer.should == "567"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shrinks the buffer in case of less bytes read" do
|
it "shrinks the buffer in case of less bytes read" do
|
||||||
buffer = "foo"
|
buffer = +"foo"
|
||||||
@file.pread(1, 0, buffer)
|
@file.pread(1, 0, buffer)
|
||||||
buffer.should == "1"
|
buffer.should == "1"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "grows the buffer in case of more bytes read" do
|
it "grows the buffer in case of more bytes read" do
|
||||||
buffer = "foo"
|
buffer = +"foo"
|
||||||
@file.pread(5, 0, buffer)
|
@file.pread(5, 0, buffer)
|
||||||
buffer.should == "12345"
|
buffer.should == "12345"
|
||||||
end
|
end
|
||||||
|
@ -57,7 +57,7 @@ guard -> { platform_is_not :windows or ruby_version_is "3.3" } do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not reset the buffer when reading with maxlen = 0" do
|
it "does not reset the buffer when reading with maxlen = 0" do
|
||||||
buffer = "foo"
|
buffer = +"foo"
|
||||||
@file.pread(0, 4, buffer)
|
@file.pread(0, 4, buffer)
|
||||||
buffer.should == "foo"
|
buffer.should == "foo"
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ guard -> { platform_is_not :windows or ruby_version_is "3.3" } do
|
||||||
|
|
||||||
it "converts a buffer to String using to_str" do
|
it "converts a buffer to String using to_str" do
|
||||||
buffer = mock('buffer')
|
buffer = mock('buffer')
|
||||||
buffer.should_receive(:to_str).at_least(1).and_return("foo")
|
buffer.should_receive(:to_str).at_least(1).and_return(+"foo")
|
||||||
@file.pread(4, 0, buffer)
|
@file.pread(4, 0, buffer)
|
||||||
buffer.should_not.is_a?(String)
|
buffer.should_not.is_a?(String)
|
||||||
buffer.to_str.should == "1234"
|
buffer.to_str.should == "1234"
|
||||||
|
|
|
@ -6,7 +6,7 @@ describe "IO#puts" do
|
||||||
@before_separator = $/
|
@before_separator = $/
|
||||||
@name = tmp("io_puts.txt")
|
@name = tmp("io_puts.txt")
|
||||||
@io = new_io @name
|
@io = new_io @name
|
||||||
ScratchPad.record ""
|
ScratchPad.record(+"")
|
||||||
def @io.write(str)
|
def @io.write(str)
|
||||||
ScratchPad << str
|
ScratchPad << str
|
||||||
end
|
end
|
||||||
|
|
|
@ -96,21 +96,21 @@ describe "IO#read_nonblock" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reads into the passed buffer" do
|
it "reads into the passed buffer" do
|
||||||
buffer = ""
|
buffer = +""
|
||||||
@write.write("1")
|
@write.write("1")
|
||||||
@read.read_nonblock(1, buffer)
|
@read.read_nonblock(1, buffer)
|
||||||
buffer.should == "1"
|
buffer.should == "1"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the passed buffer" do
|
it "returns the passed buffer" do
|
||||||
buffer = ""
|
buffer = +""
|
||||||
@write.write("1")
|
@write.write("1")
|
||||||
output = @read.read_nonblock(1, buffer)
|
output = @read.read_nonblock(1, buffer)
|
||||||
output.should equal(buffer)
|
output.should equal(buffer)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "discards the existing buffer content upon successful read" do
|
it "discards the existing buffer content upon successful read" do
|
||||||
buffer = "existing content"
|
buffer = +"existing content"
|
||||||
@write.write("hello world")
|
@write.write("hello world")
|
||||||
@write.close
|
@write.close
|
||||||
@read.read_nonblock(11, buffer)
|
@read.read_nonblock(11, buffer)
|
||||||
|
@ -118,7 +118,7 @@ describe "IO#read_nonblock" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "discards the existing buffer content upon error" do
|
it "discards the existing buffer content upon error" do
|
||||||
buffer = "existing content"
|
buffer = +"existing content"
|
||||||
@write.close
|
@write.close
|
||||||
-> { @read.read_nonblock(1, buffer) }.should raise_error(EOFError)
|
-> { @read.read_nonblock(1, buffer) }.should raise_error(EOFError)
|
||||||
buffer.should be_empty
|
buffer.should be_empty
|
||||||
|
|
|
@ -294,19 +294,19 @@ describe "IO#read" do
|
||||||
it "clears the output buffer if there is nothing to read" do
|
it "clears the output buffer if there is nothing to read" do
|
||||||
@io.pos = 10
|
@io.pos = 10
|
||||||
|
|
||||||
buf = 'non-empty string'
|
buf = +'non-empty string'
|
||||||
|
|
||||||
@io.read(10, buf).should == nil
|
@io.read(10, buf).should == nil
|
||||||
|
|
||||||
buf.should == ''
|
buf.should == ''
|
||||||
|
|
||||||
buf = 'non-empty string'
|
buf = +'non-empty string'
|
||||||
|
|
||||||
@io.read(nil, buf).should == ""
|
@io.read(nil, buf).should == ""
|
||||||
|
|
||||||
buf.should == ''
|
buf.should == ''
|
||||||
|
|
||||||
buf = 'non-empty string'
|
buf = +'non-empty string'
|
||||||
|
|
||||||
@io.read(0, buf).should == ""
|
@io.read(0, buf).should == ""
|
||||||
|
|
||||||
|
@ -344,53 +344,53 @@ describe "IO#read" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "places the specified number of bytes in the buffer" do
|
it "places the specified number of bytes in the buffer" do
|
||||||
buf = ""
|
buf = +""
|
||||||
@io.read 5, buf
|
@io.read 5, buf
|
||||||
|
|
||||||
buf.should == "12345"
|
buf.should == "12345"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "expands the buffer when too small" do
|
it "expands the buffer when too small" do
|
||||||
buf = "ABCDE"
|
buf = +"ABCDE"
|
||||||
@io.read nil, buf
|
@io.read nil, buf
|
||||||
|
|
||||||
buf.should == @contents
|
buf.should == @contents
|
||||||
end
|
end
|
||||||
|
|
||||||
it "overwrites the buffer" do
|
it "overwrites the buffer" do
|
||||||
buf = "ABCDEFGHIJ"
|
buf = +"ABCDEFGHIJ"
|
||||||
@io.read nil, buf
|
@io.read nil, buf
|
||||||
|
|
||||||
buf.should == @contents
|
buf.should == @contents
|
||||||
end
|
end
|
||||||
|
|
||||||
it "truncates the buffer when too big" do
|
it "truncates the buffer when too big" do
|
||||||
buf = "ABCDEFGHIJKLMNO"
|
buf = +"ABCDEFGHIJKLMNO"
|
||||||
@io.read nil, buf
|
@io.read nil, buf
|
||||||
buf.should == @contents
|
buf.should == @contents
|
||||||
|
|
||||||
@io.rewind
|
@io.rewind
|
||||||
|
|
||||||
buf = "ABCDEFGHIJKLMNO"
|
buf = +"ABCDEFGHIJKLMNO"
|
||||||
@io.read 5, buf
|
@io.read 5, buf
|
||||||
buf.should == @contents[0..4]
|
buf.should == @contents[0..4]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the given buffer" do
|
it "returns the given buffer" do
|
||||||
buf = ""
|
buf = +""
|
||||||
|
|
||||||
@io.read(nil, buf).should equal buf
|
@io.read(nil, buf).should equal buf
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the given buffer when there is nothing to read" do
|
it "returns the given buffer when there is nothing to read" do
|
||||||
buf = ""
|
buf = +""
|
||||||
|
|
||||||
@io.read
|
@io.read
|
||||||
@io.read(nil, buf).should equal buf
|
@io.read(nil, buf).should equal buf
|
||||||
end
|
end
|
||||||
|
|
||||||
it "coerces the second argument to string and uses it as a buffer" do
|
it "coerces the second argument to string and uses it as a buffer" do
|
||||||
buf = "ABCDE"
|
buf = +"ABCDE"
|
||||||
obj = mock("buff")
|
obj = mock("buff")
|
||||||
obj.should_receive(:to_str).any_number_of_times.and_return(buf)
|
obj.should_receive(:to_str).any_number_of_times.and_return(buf)
|
||||||
|
|
||||||
|
@ -588,13 +588,13 @@ describe :io_read_internal_encoding, shared: true do
|
||||||
|
|
||||||
describe "when passed nil for limit" do
|
describe "when passed nil for limit" do
|
||||||
it "sets the buffer to a transcoded String" do
|
it "sets the buffer to a transcoded String" do
|
||||||
result = @io.read(nil, buf = "")
|
result = @io.read(nil, buf = +"")
|
||||||
buf.should equal(result)
|
buf.should equal(result)
|
||||||
buf.should == "ありがとう\n"
|
buf.should == "ありがとう\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets the buffer's encoding to the internal encoding" do
|
it "sets the buffer's encoding to the internal encoding" do
|
||||||
buf = "".force_encoding Encoding::ISO_8859_1
|
buf = "".dup.force_encoding Encoding::ISO_8859_1
|
||||||
@io.read(nil, buf)
|
@io.read(nil, buf)
|
||||||
buf.encoding.should equal(Encoding::UTF_8)
|
buf.encoding.should equal(Encoding::UTF_8)
|
||||||
end
|
end
|
||||||
|
@ -612,14 +612,14 @@ describe :io_read_size_internal_encoding, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not change the buffer's encoding when passed a limit" do
|
it "does not change the buffer's encoding when passed a limit" do
|
||||||
buf = "".force_encoding Encoding::ISO_8859_1
|
buf = "".dup.force_encoding Encoding::ISO_8859_1
|
||||||
@io.read(4, buf)
|
@io.read(4, buf)
|
||||||
buf.should == [164, 162, 164, 234].pack('C*').force_encoding(Encoding::ISO_8859_1)
|
buf.should == [164, 162, 164, 234].pack('C*').force_encoding(Encoding::ISO_8859_1)
|
||||||
buf.encoding.should equal(Encoding::ISO_8859_1)
|
buf.encoding.should equal(Encoding::ISO_8859_1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "truncates the buffer but does not change the buffer's encoding when no data remains" do
|
it "truncates the buffer but does not change the buffer's encoding when no data remains" do
|
||||||
buf = "abc".force_encoding Encoding::ISO_8859_1
|
buf = "abc".dup.force_encoding Encoding::ISO_8859_1
|
||||||
@io.read
|
@io.read
|
||||||
|
|
||||||
@io.read(1, buf).should be_nil
|
@io.read(1, buf).should be_nil
|
||||||
|
|
|
@ -59,7 +59,7 @@ describe "IO#readpartial" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "discards the existing buffer content upon successful read" do
|
it "discards the existing buffer content upon successful read" do
|
||||||
buffer = "existing content"
|
buffer = +"existing content"
|
||||||
@wr.write("hello world")
|
@wr.write("hello world")
|
||||||
@wr.close
|
@wr.close
|
||||||
@rd.readpartial(11, buffer)
|
@rd.readpartial(11, buffer)
|
||||||
|
@ -74,7 +74,7 @@ describe "IO#readpartial" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "discards the existing buffer content upon error" do
|
it "discards the existing buffer content upon error" do
|
||||||
buffer = 'hello'
|
buffer = +'hello'
|
||||||
@wr.close
|
@wr.close
|
||||||
-> { @rd.readpartial(1, buffer) }.should raise_error(EOFError)
|
-> { @rd.readpartial(1, buffer) }.should raise_error(EOFError)
|
||||||
buffer.should be_empty
|
buffer.should be_empty
|
||||||
|
@ -95,7 +95,7 @@ describe "IO#readpartial" do
|
||||||
|
|
||||||
ruby_bug "#18421", ""..."3.0.4" do
|
ruby_bug "#18421", ""..."3.0.4" do
|
||||||
it "clears and returns the given buffer if the length argument is 0" do
|
it "clears and returns the given buffer if the length argument is 0" do
|
||||||
buffer = "existing content"
|
buffer = +"existing content"
|
||||||
@rd.readpartial(0, buffer).should == buffer
|
@rd.readpartial(0, buffer).should == buffer
|
||||||
buffer.should == ""
|
buffer.should == ""
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,7 +99,7 @@ describe :io_readlines_options_19, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts non-ASCII data as separator" do
|
it "accepts non-ASCII data as separator" do
|
||||||
result = IO.send(@method, @name, "\303\250".force_encoding("utf-8"), &@object)
|
result = IO.send(@method, @name, "\303\250".dup.force_encoding("utf-8"), &@object)
|
||||||
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_arbitrary_separator
|
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_arbitrary_separator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,25 +21,25 @@ describe "IO#sysread on a file" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reads the specified number of bytes from the file to the buffer" do
|
it "reads the specified number of bytes from the file to the buffer" do
|
||||||
buf = "" # empty buffer
|
buf = +"" # empty buffer
|
||||||
@file.sysread(15, buf).should == buf
|
@file.sysread(15, buf).should == buf
|
||||||
buf.should == "012345678901234"
|
buf.should == "012345678901234"
|
||||||
|
|
||||||
@file.rewind
|
@file.rewind
|
||||||
|
|
||||||
buf = "ABCDE" # small buffer
|
buf = +"ABCDE" # small buffer
|
||||||
@file.sysread(15, buf).should == buf
|
@file.sysread(15, buf).should == buf
|
||||||
buf.should == "012345678901234"
|
buf.should == "012345678901234"
|
||||||
|
|
||||||
@file.rewind
|
@file.rewind
|
||||||
|
|
||||||
buf = "ABCDE" * 5 # large buffer
|
buf = +"ABCDE" * 5 # large buffer
|
||||||
@file.sysread(15, buf).should == buf
|
@file.sysread(15, buf).should == buf
|
||||||
buf.should == "012345678901234"
|
buf.should == "012345678901234"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "coerces the second argument to string and uses it as a buffer" do
|
it "coerces the second argument to string and uses it as a buffer" do
|
||||||
buf = "ABCDE"
|
buf = +"ABCDE"
|
||||||
(obj = mock("buff")).should_receive(:to_str).any_number_of_times.and_return(buf)
|
(obj = mock("buff")).should_receive(:to_str).any_number_of_times.and_return(buf)
|
||||||
@file.sysread(15, obj).should == buf
|
@file.sysread(15, obj).should == buf
|
||||||
buf.should == "012345678901234"
|
buf.should == "012345678901234"
|
||||||
|
@ -90,19 +90,19 @@ describe "IO#sysread on a file" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "immediately returns the given buffer if the length argument is 0" do
|
it "immediately returns the given buffer if the length argument is 0" do
|
||||||
buffer = "existing content"
|
buffer = +"existing content"
|
||||||
@file.sysread(0, buffer).should == buffer
|
@file.sysread(0, buffer).should == buffer
|
||||||
buffer.should == "existing content"
|
buffer.should == "existing content"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "discards the existing buffer content upon successful read" do
|
it "discards the existing buffer content upon successful read" do
|
||||||
buffer = "existing content"
|
buffer = +"existing content"
|
||||||
@file.sysread(11, buffer)
|
@file.sysread(11, buffer)
|
||||||
buffer.should == "01234567890"
|
buffer.should == "01234567890"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "discards the existing buffer content upon error" do
|
it "discards the existing buffer content upon error" do
|
||||||
buffer = "existing content"
|
buffer = +"existing content"
|
||||||
@file.seek(0, :END)
|
@file.seek(0, :END)
|
||||||
-> { @file.sysread(1, buffer) }.should raise_error(EOFError)
|
-> { @file.sysread(1, buffer) }.should raise_error(EOFError)
|
||||||
buffer.should be_empty
|
buffer.should be_empty
|
||||||
|
|
|
@ -41,7 +41,7 @@ describe :kernel_float, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "converts Strings to floats without calling #to_f" do
|
it "converts Strings to floats without calling #to_f" do
|
||||||
string = "10"
|
string = +"10"
|
||||||
string.should_not_receive(:to_f)
|
string.should_not_receive(:to_f)
|
||||||
@object.send(:Float, string).should == 10.0
|
@object.send(:Float, string).should == 10.0
|
||||||
end
|
end
|
||||||
|
|
|
@ -78,7 +78,7 @@ describe :kernel_String, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the same object if it is already a String" do
|
it "returns the same object if it is already a String" do
|
||||||
string = "Hello"
|
string = +"Hello"
|
||||||
string.should_not_receive(:to_s)
|
string.should_not_receive(:to_s)
|
||||||
string2 = @object.send(@method, string)
|
string2 = @object.send(@method, string)
|
||||||
string.should equal(string2)
|
string.should equal(string2)
|
||||||
|
|
|
@ -35,7 +35,7 @@ describe "Kernel.catch" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an ArgumentError if a String with different identity is thrown" do
|
it "raises an ArgumentError if a String with different identity is thrown" do
|
||||||
-> { catch("exit") { throw "exit" } }.should raise_error(ArgumentError)
|
-> { catch("exit".dup) { throw "exit".dup } }.should raise_error(ArgumentError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "catches a Symbol when thrown a matching Symbol" do
|
it "catches a Symbol when thrown a matching Symbol" do
|
||||||
|
|
|
@ -19,7 +19,7 @@ describe "Kernel#class" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the first non-singleton class" do
|
it "returns the first non-singleton class" do
|
||||||
a = "hello"
|
a = +"hello"
|
||||||
def a.my_singleton_method; end
|
def a.my_singleton_method; end
|
||||||
a.class.should equal(String)
|
a.class.should equal(String)
|
||||||
end
|
end
|
||||||
|
|
|
@ -350,9 +350,6 @@ CODE
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows a magic encoding comment and a subsequent frozen_string_literal magic comment" do
|
it "allows a magic encoding comment and a subsequent frozen_string_literal magic comment" do
|
||||||
# Make sure frozen_string_literal is not default true
|
|
||||||
eval("'foo'".b).frozen?.should be_false
|
|
||||||
|
|
||||||
code = <<CODE.b
|
code = <<CODE.b
|
||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
@ -403,6 +400,7 @@ CODE
|
||||||
end
|
end
|
||||||
|
|
||||||
it "ignores the frozen_string_literal magic comment if it appears after a token and warns if $VERBOSE is true" do
|
it "ignores the frozen_string_literal magic comment if it appears after a token and warns if $VERBOSE is true" do
|
||||||
|
default_frozen_string_literal = "test".frozen?
|
||||||
code = <<CODE
|
code = <<CODE
|
||||||
some_token_before_magic_comment = :anything
|
some_token_before_magic_comment = :anything
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
@ -411,11 +409,11 @@ class EvalSpecs
|
||||||
end
|
end
|
||||||
CODE
|
CODE
|
||||||
-> { eval(code) }.should complain(/warning: [`']frozen_string_literal' is ignored after any tokens/, verbose: true)
|
-> { eval(code) }.should complain(/warning: [`']frozen_string_literal' is ignored after any tokens/, verbose: true)
|
||||||
EvalSpecs::Vπstring_not_frozen.frozen?.should be_false
|
EvalSpecs::Vπstring_not_frozen.frozen?.should == default_frozen_string_literal
|
||||||
EvalSpecs.send :remove_const, :Vπstring_not_frozen
|
EvalSpecs.send :remove_const, :Vπstring_not_frozen
|
||||||
|
|
||||||
-> { eval(code) }.should_not complain(verbose: false)
|
-> { eval(code) }.should_not complain(verbose: false)
|
||||||
EvalSpecs::Vπstring_not_frozen.frozen?.should be_false
|
EvalSpecs::Vπstring_not_frozen.frozen?.should == default_frozen_string_literal
|
||||||
EvalSpecs.send :remove_const, :Vπstring_not_frozen
|
EvalSpecs.send :remove_const, :Vπstring_not_frozen
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,14 +14,14 @@ describe :kernel_sprintf_encoding, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a String in the same encoding as the format String if compatible" do
|
it "returns a String in the same encoding as the format String if compatible" do
|
||||||
string = "%s".force_encoding(Encoding::KOI8_U)
|
string = "%s".dup.force_encoding(Encoding::KOI8_U)
|
||||||
result = @method.call(string, "dogs")
|
result = @method.call(string, "dogs")
|
||||||
result.encoding.should equal(Encoding::KOI8_U)
|
result.encoding.should equal(Encoding::KOI8_U)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a String in the argument's encoding if format encoding is more restrictive" do
|
it "returns a String in the argument's encoding if format encoding is more restrictive" do
|
||||||
string = "foo %s".force_encoding(Encoding::US_ASCII)
|
string = "foo %s".dup.force_encoding(Encoding::US_ASCII)
|
||||||
argument = "b\303\274r".force_encoding(Encoding::UTF_8)
|
argument = "b\303\274r".dup.force_encoding(Encoding::UTF_8)
|
||||||
|
|
||||||
result = @method.call(string, argument)
|
result = @method.call(string, argument)
|
||||||
result.encoding.should equal(Encoding::UTF_8)
|
result.encoding.should equal(Encoding::UTF_8)
|
||||||
|
@ -56,7 +56,7 @@ describe :kernel_sprintf_encoding, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "uses the encoding of the format string to interpret codepoints" do
|
it "uses the encoding of the format string to interpret codepoints" do
|
||||||
format = "%c".force_encoding("euc-jp")
|
format = "%c".dup.force_encoding("euc-jp")
|
||||||
result = @method.call(format, 9415601)
|
result = @method.call(format, 9415601)
|
||||||
|
|
||||||
result.encoding.should == Encoding::EUC_JP
|
result.encoding.should == Encoding::EUC_JP
|
||||||
|
|
|
@ -76,7 +76,7 @@ describe "Marshal.dump" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a binary encoded Symbol" do
|
it "dumps a binary encoded Symbol" do
|
||||||
s = "\u2192".force_encoding("binary").to_sym
|
s = "\u2192".dup.force_encoding("binary").to_sym
|
||||||
Marshal.dump(s).should == "\x04\b:\b\xE2\x86\x92"
|
Marshal.dump(s).should == "\x04\b:\b\xE2\x86\x92"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -85,8 +85,8 @@ describe "Marshal.dump" do
|
||||||
symbol1 = "I:\t\xE2\x82\xACa\x06:\x06ET"
|
symbol1 = "I:\t\xE2\x82\xACa\x06:\x06ET"
|
||||||
symbol2 = "I:\t\xE2\x82\xACb\x06;\x06T"
|
symbol2 = "I:\t\xE2\x82\xACb\x06;\x06T"
|
||||||
value = [
|
value = [
|
||||||
"€a".force_encoding(Encoding::UTF_8).to_sym,
|
"€a".dup.force_encoding(Encoding::UTF_8).to_sym,
|
||||||
"€b".force_encoding(Encoding::UTF_8).to_sym
|
"€b".dup.force_encoding(Encoding::UTF_8).to_sym
|
||||||
]
|
]
|
||||||
Marshal.dump(value).should == "\x04\b[\a#{symbol1}#{symbol2}"
|
Marshal.dump(value).should == "\x04\b[\a#{symbol1}#{symbol2}"
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ describe "Marshal.dump" do
|
||||||
it "indexes instance variables of a String returned by #_dump at first and then indexes the object itself" do
|
it "indexes instance variables of a String returned by #_dump at first and then indexes the object itself" do
|
||||||
class MarshalSpec::M1::A
|
class MarshalSpec::M1::A
|
||||||
def _dump(level)
|
def _dump(level)
|
||||||
s = "<dump>"
|
s = +"<dump>"
|
||||||
s.instance_variable_set(:@foo, "bar")
|
s.instance_variable_set(:@foo, "bar")
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
@ -194,7 +194,7 @@ describe "Marshal.dump" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a class with multibyte characters in name" do
|
it "dumps a class with multibyte characters in name" do
|
||||||
source_object = eval("MarshalSpec::MultibyteぁあぃいClass".force_encoding(Encoding::UTF_8))
|
source_object = eval("MarshalSpec::MultibyteぁあぃいClass".dup.force_encoding(Encoding::UTF_8))
|
||||||
Marshal.dump(source_object).should == "\x04\bc,MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Class"
|
Marshal.dump(source_object).should == "\x04\bc,MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Class"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ describe "Marshal.dump" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a module with multibyte characters in name" do
|
it "dumps a module with multibyte characters in name" do
|
||||||
source_object = eval("MarshalSpec::MultibyteけげこごModule".force_encoding(Encoding::UTF_8))
|
source_object = eval("MarshalSpec::MultibyteけげこごModule".dup.force_encoding(Encoding::UTF_8))
|
||||||
Marshal.dump(source_object).should == "\x04\bm-MarshalSpec::Multibyte\xE3\x81\x91\xE3\x81\x92\xE3\x81\x93\xE3\x81\x94Module"
|
Marshal.dump(source_object).should == "\x04\bm-MarshalSpec::Multibyte\xE3\x81\x91\xE3\x81\x92\xE3\x81\x93\xE3\x81\x94Module"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -285,11 +285,11 @@ describe "Marshal.dump" do
|
||||||
|
|
||||||
describe "with a String" do
|
describe "with a String" do
|
||||||
it "dumps a blank String" do
|
it "dumps a blank String" do
|
||||||
Marshal.dump("".force_encoding("binary")).should == "\004\b\"\000"
|
Marshal.dump("".dup.force_encoding("binary")).should == "\004\b\"\000"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a short String" do
|
it "dumps a short String" do
|
||||||
Marshal.dump("short".force_encoding("binary")).should == "\004\b\"\012short"
|
Marshal.dump("short".dup.force_encoding("binary")).should == "\004\b\"\012short"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a long String" do
|
it "dumps a long String" do
|
||||||
|
@ -297,7 +297,7 @@ describe "Marshal.dump" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a String extended with a Module" do
|
it "dumps a String extended with a Module" do
|
||||||
Marshal.dump("".extend(Meths).force_encoding("binary")).should == "\004\be:\nMeths\"\000"
|
Marshal.dump("".dup.extend(Meths).force_encoding("binary")).should == "\004\be:\nMeths\"\000"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a String subclass" do
|
it "dumps a String subclass" do
|
||||||
|
@ -314,23 +314,23 @@ describe "Marshal.dump" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a String with instance variables" do
|
it "dumps a String with instance variables" do
|
||||||
str = ""
|
str = +""
|
||||||
str.instance_variable_set("@foo", "bar")
|
str.instance_variable_set("@foo", "bar")
|
||||||
Marshal.dump(str.force_encoding("binary")).should == "\x04\bI\"\x00\x06:\t@foo\"\bbar"
|
Marshal.dump(str.force_encoding("binary")).should == "\x04\bI\"\x00\x06:\t@foo\"\bbar"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a US-ASCII String" do
|
it "dumps a US-ASCII String" do
|
||||||
str = "abc".force_encoding("us-ascii")
|
str = "abc".dup.force_encoding("us-ascii")
|
||||||
Marshal.dump(str).should == "\x04\bI\"\babc\x06:\x06EF"
|
Marshal.dump(str).should == "\x04\bI\"\babc\x06:\x06EF"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a UTF-8 String" do
|
it "dumps a UTF-8 String" do
|
||||||
str = "\x6d\xc3\xb6\x68\x72\x65".force_encoding("utf-8")
|
str = "\x6d\xc3\xb6\x68\x72\x65".dup.force_encoding("utf-8")
|
||||||
Marshal.dump(str).should == "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
|
Marshal.dump(str).should == "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a String in another encoding" do
|
it "dumps a String in another encoding" do
|
||||||
str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".force_encoding("utf-16le")
|
str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".dup.force_encoding("utf-16le")
|
||||||
result = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE"
|
result = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE"
|
||||||
Marshal.dump(str).should == result
|
Marshal.dump(str).should == result
|
||||||
end
|
end
|
||||||
|
@ -364,7 +364,7 @@ describe "Marshal.dump" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a binary Regexp" do
|
it "dumps a binary Regexp" do
|
||||||
o = Regexp.new("".force_encoding("binary"), Regexp::FIXEDENCODING)
|
o = Regexp.new("".dup.force_encoding("binary"), Regexp::FIXEDENCODING)
|
||||||
Marshal.dump(o).should == "\x04\b/\x00\x10"
|
Marshal.dump(o).should == "\x04\b/\x00\x10"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -383,18 +383,18 @@ describe "Marshal.dump" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a UTF-8 Regexp" do
|
it "dumps a UTF-8 Regexp" do
|
||||||
o = Regexp.new("".force_encoding("utf-8"), Regexp::FIXEDENCODING)
|
o = Regexp.new("".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING)
|
||||||
Marshal.dump(o).should == "\x04\bI/\x00\x10\x06:\x06ET"
|
Marshal.dump(o).should == "\x04\bI/\x00\x10\x06:\x06ET"
|
||||||
|
|
||||||
o = Regexp.new("a".force_encoding("utf-8"), Regexp::FIXEDENCODING)
|
o = Regexp.new("a".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING)
|
||||||
Marshal.dump(o).should == "\x04\bI/\x06a\x10\x06:\x06ET"
|
Marshal.dump(o).should == "\x04\bI/\x06a\x10\x06:\x06ET"
|
||||||
|
|
||||||
o = Regexp.new("\u3042".force_encoding("utf-8"), Regexp::FIXEDENCODING)
|
o = Regexp.new("\u3042".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING)
|
||||||
Marshal.dump(o).should == "\x04\bI/\b\xE3\x81\x82\x10\x06:\x06ET"
|
Marshal.dump(o).should == "\x04\bI/\b\xE3\x81\x82\x10\x06:\x06ET"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a Regexp in another encoding" do
|
it "dumps a Regexp in another encoding" do
|
||||||
o = Regexp.new("".force_encoding("utf-16le"), Regexp::FIXEDENCODING)
|
o = Regexp.new("".dup.force_encoding("utf-16le"), Regexp::FIXEDENCODING)
|
||||||
Marshal.dump(o).should == "\x04\bI/\x00\x10\x06:\rencoding\"\rUTF-16LE"
|
Marshal.dump(o).should == "\x04\bI/\x00\x10\x06:\rencoding\"\rUTF-16LE"
|
||||||
|
|
||||||
o = Regexp.new("a".encode("utf-16le"), Regexp::FIXEDENCODING)
|
o = Regexp.new("a".encode("utf-16le"), Regexp::FIXEDENCODING)
|
||||||
|
@ -553,7 +553,7 @@ describe "Marshal.dump" do
|
||||||
|
|
||||||
it "dumps an Object with a non-US-ASCII instance variable" do
|
it "dumps an Object with a non-US-ASCII instance variable" do
|
||||||
obj = Object.new
|
obj = Object.new
|
||||||
ivar = "@é".force_encoding(Encoding::UTF_8).to_sym
|
ivar = "@é".dup.force_encoding(Encoding::UTF_8).to_sym
|
||||||
obj.instance_variable_set(ivar, 1)
|
obj.instance_variable_set(ivar, 1)
|
||||||
Marshal.dump(obj).should == "\x04\bo:\vObject\x06I:\b@\xC3\xA9\x06:\x06ETi\x06"
|
Marshal.dump(obj).should == "\x04\bo:\vObject\x06I:\b@\xC3\xA9\x06:\x06ETi\x06"
|
||||||
end
|
end
|
||||||
|
@ -685,7 +685,7 @@ describe "Marshal.dump" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "dumps a Time subclass with multibyte characters in name" do
|
it "dumps a Time subclass with multibyte characters in name" do
|
||||||
source_object = eval("MarshalSpec::MultibyteぁあぃいTime".force_encoding(Encoding::UTF_8))
|
source_object = eval("MarshalSpec::MultibyteぁあぃいTime".dup.force_encoding(Encoding::UTF_8))
|
||||||
Marshal.dump(source_object).should == "\x04\bc+MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Time"
|
Marshal.dump(source_object).should == "\x04\bc+MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Time"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ class UserDefinedWithIvar
|
||||||
attr_reader :a, :b, :c
|
attr_reader :a, :b, :c
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@a = 'stuff'
|
@a = +'stuff'
|
||||||
@a.instance_variable_set :@foo, :UserDefinedWithIvar
|
@a.instance_variable_set :@foo, :UserDefinedWithIvar
|
||||||
@b = 'more'
|
@b = 'more'
|
||||||
@c = @b
|
@c = @b
|
||||||
|
@ -267,7 +267,7 @@ module MarshalSpec
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module_eval(<<~ruby.force_encoding(Encoding::UTF_8))
|
module_eval(<<~ruby.dup.force_encoding(Encoding::UTF_8))
|
||||||
class MultibyteぁあぃいClass
|
class MultibyteぁあぃいClass
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -313,7 +313,7 @@ module MarshalSpec
|
||||||
"\004\b\"\012small"],
|
"\004\b\"\012small"],
|
||||||
"String big" => ['big' * 100,
|
"String big" => ['big' * 100,
|
||||||
"\004\b\"\002,\001#{'big' * 100}"],
|
"\004\b\"\002,\001#{'big' * 100}"],
|
||||||
"String extended" => [''.extend(Meths), # TODO: check for module on load
|
"String extended" => [''.dup.extend(Meths), # TODO: check for module on load
|
||||||
"\004\be:\nMeths\"\000"],
|
"\004\be:\nMeths\"\000"],
|
||||||
"String subclass" => [UserString.new,
|
"String subclass" => [UserString.new,
|
||||||
"\004\bC:\017UserString\"\000"],
|
"\004\bC:\017UserString\"\000"],
|
||||||
|
@ -420,7 +420,7 @@ module MarshalSpec
|
||||||
"\x04\bI\"\nsmall\x06:\x06EF"],
|
"\x04\bI\"\nsmall\x06:\x06EF"],
|
||||||
"String big" => ['big' * 100,
|
"String big" => ['big' * 100,
|
||||||
"\x04\bI\"\x02,\x01bigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbig\x06:\x06EF"],
|
"\x04\bI\"\x02,\x01bigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbig\x06:\x06EF"],
|
||||||
"String extended" => [''.extend(Meths), # TODO: check for module on load
|
"String extended" => [''.dup.extend(Meths), # TODO: check for module on load
|
||||||
"\x04\bIe:\nMeths\"\x00\x06:\x06EF"],
|
"\x04\bIe:\nMeths\"\x00\x06:\x06EF"],
|
||||||
"String subclass" => [UserString.new,
|
"String subclass" => [UserString.new,
|
||||||
"\004\bC:\017UserString\"\000"],
|
"\004\bC:\017UserString\"\000"],
|
||||||
|
|
|
@ -183,7 +183,7 @@ describe :marshal_load, shared: true do
|
||||||
describe "when called with a proc" do
|
describe "when called with a proc" do
|
||||||
it "call the proc with frozen objects" do
|
it "call the proc with frozen objects" do
|
||||||
arr = []
|
arr = []
|
||||||
s = 'hi'
|
s = +'hi'
|
||||||
s.instance_variable_set(:@foo, 5)
|
s.instance_variable_set(:@foo, 5)
|
||||||
st = Struct.new("Brittle", :a).new
|
st = Struct.new("Brittle", :a).new
|
||||||
st.instance_variable_set(:@clue, 'none')
|
st.instance_variable_set(:@clue, 'none')
|
||||||
|
@ -268,7 +268,7 @@ describe :marshal_load, shared: true do
|
||||||
|
|
||||||
it "loads an Array with proc" do
|
it "loads an Array with proc" do
|
||||||
arr = []
|
arr = []
|
||||||
s = 'hi'
|
s = +'hi'
|
||||||
s.instance_variable_set(:@foo, 5)
|
s.instance_variable_set(:@foo, 5)
|
||||||
st = Struct.new("Brittle", :a).new
|
st = Struct.new("Brittle", :a).new
|
||||||
st.instance_variable_set(:@clue, 'none')
|
st.instance_variable_set(:@clue, 'none')
|
||||||
|
@ -413,13 +413,13 @@ describe :marshal_load, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises a TypeError with bad Marshal version" do
|
it "raises a TypeError with bad Marshal version" do
|
||||||
marshal_data = '\xff\xff'
|
marshal_data = +'\xff\xff'
|
||||||
marshal_data[0] = (Marshal::MAJOR_VERSION).chr
|
marshal_data[0] = (Marshal::MAJOR_VERSION).chr
|
||||||
marshal_data[1] = (Marshal::MINOR_VERSION + 1).chr
|
marshal_data[1] = (Marshal::MINOR_VERSION + 1).chr
|
||||||
|
|
||||||
-> { Marshal.send(@method, marshal_data) }.should raise_error(TypeError)
|
-> { Marshal.send(@method, marshal_data) }.should raise_error(TypeError)
|
||||||
|
|
||||||
marshal_data = '\xff\xff'
|
marshal_data = +'\xff\xff'
|
||||||
marshal_data[0] = (Marshal::MAJOR_VERSION - 1).chr
|
marshal_data[0] = (Marshal::MAJOR_VERSION - 1).chr
|
||||||
marshal_data[1] = (Marshal::MINOR_VERSION).chr
|
marshal_data[1] = (Marshal::MINOR_VERSION).chr
|
||||||
|
|
||||||
|
@ -470,7 +470,7 @@ describe :marshal_load, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "loads an array having ivar" do
|
it "loads an array having ivar" do
|
||||||
s = 'well'
|
s = +'well'
|
||||||
s.instance_variable_set(:@foo, 10)
|
s.instance_variable_set(:@foo, 10)
|
||||||
obj = ['5', s, 'hi'].extend(Meths, MethsMore)
|
obj = ['5', s, 'hi'].extend(Meths, MethsMore)
|
||||||
obj.instance_variable_set(:@mix, s)
|
obj.instance_variable_set(:@mix, s)
|
||||||
|
@ -516,7 +516,7 @@ describe :marshal_load, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "preserves hash ivars when hash contains a string having ivar" do
|
it "preserves hash ivars when hash contains a string having ivar" do
|
||||||
s = 'string'
|
s = +'string'
|
||||||
s.instance_variable_set :@string_ivar, 'string ivar'
|
s.instance_variable_set :@string_ivar, 'string ivar'
|
||||||
h = { key: s }
|
h = { key: s }
|
||||||
h.instance_variable_set :@hash_ivar, 'hash ivar'
|
h.instance_variable_set :@hash_ivar, 'hash ivar'
|
||||||
|
@ -600,7 +600,7 @@ describe :marshal_load, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "loads a binary encoded Symbol" do
|
it "loads a binary encoded Symbol" do
|
||||||
s = "\u2192".force_encoding("binary").to_sym
|
s = "\u2192".dup.force_encoding("binary").to_sym
|
||||||
sym = Marshal.send(@method, "\x04\b:\b\xE2\x86\x92")
|
sym = Marshal.send(@method, "\x04\b:\b\xE2\x86\x92")
|
||||||
sym.should == s
|
sym.should == s
|
||||||
sym.encoding.should == Encoding::BINARY
|
sym.encoding.should == Encoding::BINARY
|
||||||
|
@ -614,8 +614,8 @@ describe :marshal_load, shared: true do
|
||||||
value = Marshal.send(@method, dump)
|
value = Marshal.send(@method, dump)
|
||||||
value.map(&:encoding).should == [Encoding::UTF_8, Encoding::UTF_8]
|
value.map(&:encoding).should == [Encoding::UTF_8, Encoding::UTF_8]
|
||||||
expected = [
|
expected = [
|
||||||
"€a".force_encoding(Encoding::UTF_8).to_sym,
|
"€a".dup.force_encoding(Encoding::UTF_8).to_sym,
|
||||||
"€b".force_encoding(Encoding::UTF_8).to_sym
|
"€b".dup.force_encoding(Encoding::UTF_8).to_sym
|
||||||
]
|
]
|
||||||
value.should == expected
|
value.should == expected
|
||||||
|
|
||||||
|
@ -635,7 +635,7 @@ describe :marshal_load, shared: true do
|
||||||
|
|
||||||
describe "for a String" do
|
describe "for a String" do
|
||||||
it "loads a string having ivar with ref to self" do
|
it "loads a string having ivar with ref to self" do
|
||||||
obj = 'hi'
|
obj = +'hi'
|
||||||
obj.instance_variable_set(:@self, obj)
|
obj.instance_variable_set(:@self, obj)
|
||||||
Marshal.send(@method, "\004\bI\"\ahi\006:\n@self@\000").should == obj
|
Marshal.send(@method, "\004\bI\"\ahi\006:\n@self@\000").should == obj
|
||||||
end
|
end
|
||||||
|
@ -647,7 +647,7 @@ describe :marshal_load, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets binmode if it is loading through StringIO stream" do
|
it "sets binmode if it is loading through StringIO stream" do
|
||||||
io = StringIO.new("\004\b:\vsymbol")
|
io = StringIO.new(+"\004\b:\vsymbol")
|
||||||
def io.binmode; raise "binmode"; end
|
def io.binmode; raise "binmode"; end
|
||||||
-> { Marshal.load(io) }.should raise_error(RuntimeError, "binmode")
|
-> { Marshal.load(io) }.should raise_error(RuntimeError, "binmode")
|
||||||
end
|
end
|
||||||
|
@ -663,7 +663,7 @@ describe :marshal_load, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "loads a US-ASCII String" do
|
it "loads a US-ASCII String" do
|
||||||
str = "abc".force_encoding("us-ascii")
|
str = "abc".dup.force_encoding("us-ascii")
|
||||||
data = "\x04\bI\"\babc\x06:\x06EF"
|
data = "\x04\bI\"\babc\x06:\x06EF"
|
||||||
result = Marshal.send(@method, data)
|
result = Marshal.send(@method, data)
|
||||||
result.should == str
|
result.should == str
|
||||||
|
@ -671,7 +671,7 @@ describe :marshal_load, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "loads a UTF-8 String" do
|
it "loads a UTF-8 String" do
|
||||||
str = "\x6d\xc3\xb6\x68\x72\x65".force_encoding("utf-8")
|
str = "\x6d\xc3\xb6\x68\x72\x65".dup.force_encoding("utf-8")
|
||||||
data = "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
|
data = "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
|
||||||
result = Marshal.send(@method, data)
|
result = Marshal.send(@method, data)
|
||||||
result.should == str
|
result.should == str
|
||||||
|
@ -679,7 +679,7 @@ describe :marshal_load, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "loads a String in another encoding" do
|
it "loads a String in another encoding" do
|
||||||
str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".force_encoding("utf-16le")
|
str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".dup.force_encoding("utf-16le")
|
||||||
data = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE"
|
data = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE"
|
||||||
result = Marshal.send(@method, data)
|
result = Marshal.send(@method, data)
|
||||||
result.should == str
|
result.should == str
|
||||||
|
@ -687,8 +687,8 @@ describe :marshal_load, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "loads a String as BINARY if no encoding is specified at the end" do
|
it "loads a String as BINARY if no encoding is specified at the end" do
|
||||||
str = "\xC3\xB8".force_encoding("BINARY")
|
str = "\xC3\xB8".dup.force_encoding("BINARY")
|
||||||
data = "\x04\b\"\a\xC3\xB8".force_encoding("UTF-8")
|
data = "\x04\b\"\a\xC3\xB8".dup.force_encoding("UTF-8")
|
||||||
result = Marshal.send(@method, data)
|
result = Marshal.send(@method, data)
|
||||||
result.encoding.should == Encoding::BINARY
|
result.encoding.should == Encoding::BINARY
|
||||||
result.should == str
|
result.should == str
|
||||||
|
@ -823,7 +823,7 @@ describe :marshal_load, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "loads an Object with a non-US-ASCII instance variable" do
|
it "loads an Object with a non-US-ASCII instance variable" do
|
||||||
ivar = "@é".force_encoding(Encoding::UTF_8).to_sym
|
ivar = "@é".dup.force_encoding(Encoding::UTF_8).to_sym
|
||||||
obj = Marshal.send(@method, "\x04\bo:\vObject\x06I:\b@\xC3\xA9\x06:\x06ETi\x06")
|
obj = Marshal.send(@method, "\x04\bo:\vObject\x06I:\b@\xC3\xA9\x06:\x06ETi\x06")
|
||||||
obj.instance_variables.should == [ivar]
|
obj.instance_variables.should == [ivar]
|
||||||
obj.instance_variables[0].encoding.should == Encoding::UTF_8
|
obj.instance_variables[0].encoding.should == Encoding::UTF_8
|
||||||
|
|
|
@ -113,7 +113,7 @@ describe "MatchData#[Symbol]" do
|
||||||
|
|
||||||
it "returns matches in the String's encoding" do
|
it "returns matches in the String's encoding" do
|
||||||
rex = /(?<t>t(?<a>ack))/u
|
rex = /(?<t>t(?<a>ack))/u
|
||||||
md = 'haystack'.force_encoding('euc-jp').match(rex)
|
md = 'haystack'.dup.force_encoding('euc-jp').match(rex)
|
||||||
md[:t].encoding.should == Encoding::EUC_JP
|
md[:t].encoding.should == Encoding::EUC_JP
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,12 +8,12 @@ describe "MatchData#post_match" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets the encoding to the encoding of the source String" do
|
it "sets the encoding to the encoding of the source String" do
|
||||||
str = "abc".force_encoding Encoding::EUC_JP
|
str = "abc".dup.force_encoding Encoding::EUC_JP
|
||||||
str.match(/b/).post_match.encoding.should equal(Encoding::EUC_JP)
|
str.match(/b/).post_match.encoding.should equal(Encoding::EUC_JP)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets an empty result to the encoding of the source String" do
|
it "sets an empty result to the encoding of the source String" do
|
||||||
str = "abc".force_encoding Encoding::ISO_8859_1
|
str = "abc".dup.force_encoding Encoding::ISO_8859_1
|
||||||
str.match(/c/).post_match.encoding.should equal(Encoding::ISO_8859_1)
|
str.match(/c/).post_match.encoding.should equal(Encoding::ISO_8859_1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,12 @@ describe "MatchData#pre_match" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets the encoding to the encoding of the source String" do
|
it "sets the encoding to the encoding of the source String" do
|
||||||
str = "abc".force_encoding Encoding::EUC_JP
|
str = "abc".dup.force_encoding Encoding::EUC_JP
|
||||||
str.match(/b/).pre_match.encoding.should equal(Encoding::EUC_JP)
|
str.match(/b/).pre_match.encoding.should equal(Encoding::EUC_JP)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets an empty result to the encoding of the source String" do
|
it "sets an empty result to the encoding of the source String" do
|
||||||
str = "abc".force_encoding Encoding::ISO_8859_1
|
str = "abc".dup.force_encoding Encoding::ISO_8859_1
|
||||||
str.match(/a/).pre_match.encoding.should equal(Encoding::ISO_8859_1)
|
str.match(/a/).pre_match.encoding.should equal(Encoding::ISO_8859_1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,9 @@ describe "MatchData#string" do
|
||||||
md.string.should equal(md.string)
|
md.string.should equal(md.string)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a frozen copy of the matched string for gsub(String)" do
|
it "returns a frozen copy of the matched string for gsub!(String)" do
|
||||||
'he[[o'.gsub!('[', ']')
|
s = +'he[[o'
|
||||||
|
s.gsub!('[', ']')
|
||||||
$~.string.should == 'he[[o'
|
$~.string.should == 'he[[o'
|
||||||
$~.string.should.frozen?
|
$~.string.should.frozen?
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,7 +35,7 @@ describe "Method#to_proc" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a proc that can be used by define_method" do
|
it "returns a proc that can be used by define_method" do
|
||||||
x = 'test'
|
x = +'test'
|
||||||
to_s = class << x
|
to_s = class << x
|
||||||
define_method :foo, method(:to_s).to_proc
|
define_method :foo, method(:to_s).to_proc
|
||||||
to_s
|
to_s
|
||||||
|
|
|
@ -316,7 +316,7 @@ describe "Module#using" do
|
||||||
using refinement
|
using refinement
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@a = "1703"
|
@a = +"1703"
|
||||||
|
|
||||||
@a.instance_eval do
|
@a.instance_eval do
|
||||||
def abc
|
def abc
|
||||||
|
|
|
@ -52,7 +52,7 @@ describe "ObjectSpace.define_finalizer" do
|
||||||
Proc.new { puts "finalizer run" }
|
Proc.new { puts "finalizer run" }
|
||||||
end
|
end
|
||||||
handler = scoped
|
handler = scoped
|
||||||
obj = "Test"
|
obj = +"Test"
|
||||||
ObjectSpace.define_finalizer(obj, handler)
|
ObjectSpace.define_finalizer(obj, handler)
|
||||||
exit 0
|
exit 0
|
||||||
RUBY
|
RUBY
|
||||||
|
@ -111,7 +111,7 @@ describe "ObjectSpace.define_finalizer" do
|
||||||
|
|
||||||
it "calls a finalizer at exit even if it is self-referencing" do
|
it "calls a finalizer at exit even if it is self-referencing" do
|
||||||
code = <<-RUBY
|
code = <<-RUBY
|
||||||
obj = "Test"
|
obj = +"Test"
|
||||||
handler = Proc.new { puts "finalizer run" }
|
handler = Proc.new { puts "finalizer run" }
|
||||||
ObjectSpace.define_finalizer(obj, handler)
|
ObjectSpace.define_finalizer(obj, handler)
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -141,9 +141,9 @@ describe "ObjectSpace.define_finalizer" do
|
||||||
|
|
||||||
it "calls a finalizer defined in a finalizer running at exit" do
|
it "calls a finalizer defined in a finalizer running at exit" do
|
||||||
code = <<-RUBY
|
code = <<-RUBY
|
||||||
obj = "Test"
|
obj = +"Test"
|
||||||
handler = Proc.new do
|
handler = Proc.new do
|
||||||
obj2 = "Test"
|
obj2 = +"Test"
|
||||||
handler2 = Proc.new { puts "finalizer 2 run" }
|
handler2 = Proc.new { puts "finalizer 2 run" }
|
||||||
ObjectSpace.define_finalizer(obj2, handler2)
|
ObjectSpace.define_finalizer(obj2, handler2)
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# frozen_string_literal: false
|
||||||
module ProcArefSpecs
|
module ProcArefSpecs
|
||||||
def self.aref
|
def self.aref
|
||||||
proc {|a| a }["sometext"]
|
proc {|a| a }["sometext"]
|
||||||
|
|
|
@ -489,12 +489,12 @@ describe :regexp_new_string, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a Regexp with the input String's encoding" do
|
it "returns a Regexp with the input String's encoding" do
|
||||||
str = "\x82\xa0".force_encoding(Encoding::Shift_JIS)
|
str = "\x82\xa0".dup.force_encoding(Encoding::Shift_JIS)
|
||||||
Regexp.send(@method, str).encoding.should == Encoding::Shift_JIS
|
Regexp.send(@method, str).encoding.should == Encoding::Shift_JIS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a Regexp with source String having the input String's encoding" do
|
it "returns a Regexp with source String having the input String's encoding" do
|
||||||
str = "\x82\xa0".force_encoding(Encoding::Shift_JIS)
|
str = "\x82\xa0".dup.force_encoding(Encoding::Shift_JIS)
|
||||||
Regexp.send(@method, str).source.encoding.should == Encoding::Shift_JIS
|
Regexp.send(@method, str).source.encoding.should == Encoding::Shift_JIS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,23 +18,23 @@ describe :regexp_quote, shared: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "works for broken strings" do
|
it "works for broken strings" do
|
||||||
Regexp.send(@method, "a.\x85b.".force_encoding("US-ASCII")).should =="a\\.\x85b\\.".force_encoding("US-ASCII")
|
Regexp.send(@method, "a.\x85b.".dup.force_encoding("US-ASCII")).should =="a\\.\x85b\\.".dup.force_encoding("US-ASCII")
|
||||||
Regexp.send(@method, "a.\x80".force_encoding("UTF-8")).should == "a\\.\x80".force_encoding("UTF-8")
|
Regexp.send(@method, "a.\x80".dup.force_encoding("UTF-8")).should == "a\\.\x80".dup.force_encoding("UTF-8")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets the encoding of the result to US-ASCII if there are only US-ASCII characters present in the input String" do
|
it "sets the encoding of the result to US-ASCII if there are only US-ASCII characters present in the input String" do
|
||||||
str = "abc".force_encoding("euc-jp")
|
str = "abc".dup.force_encoding("euc-jp")
|
||||||
Regexp.send(@method, str).encoding.should == Encoding::US_ASCII
|
Regexp.send(@method, str).encoding.should == Encoding::US_ASCII
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets the encoding of the result to the encoding of the String if any non-US-ASCII characters are present in an input String with valid encoding" do
|
it "sets the encoding of the result to the encoding of the String if any non-US-ASCII characters are present in an input String with valid encoding" do
|
||||||
str = "ありがとう".force_encoding("utf-8")
|
str = "ありがとう".dup.force_encoding("utf-8")
|
||||||
str.valid_encoding?.should be_true
|
str.valid_encoding?.should be_true
|
||||||
Regexp.send(@method, str).encoding.should == Encoding::UTF_8
|
Regexp.send(@method, str).encoding.should == Encoding::UTF_8
|
||||||
end
|
end
|
||||||
|
|
||||||
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
|
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 = "\xff".dup.force_encoding "us-ascii"
|
||||||
str.valid_encoding?.should be_false
|
str.valid_encoding?.should be_false
|
||||||
Regexp.send(@method, "\xff").encoding.should == Encoding::BINARY
|
Regexp.send(@method, "\xff").encoding.should == Encoding::BINARY
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,12 +7,12 @@ describe "String#ascii_only?" do
|
||||||
it "returns true if the encoding is UTF-8" do
|
it "returns true if the encoding is UTF-8" do
|
||||||
[ ["hello", true],
|
[ ["hello", true],
|
||||||
["hello".encode('UTF-8'), true],
|
["hello".encode('UTF-8'), true],
|
||||||
["hello".force_encoding('UTF-8'), true],
|
["hello".dup.force_encoding('UTF-8'), true],
|
||||||
].should be_computed_by(:ascii_only?)
|
].should be_computed_by(:ascii_only?)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns true if the encoding is US-ASCII" do
|
it "returns true if the encoding is US-ASCII" do
|
||||||
"hello".force_encoding(Encoding::US_ASCII).ascii_only?.should be_true
|
"hello".dup.force_encoding(Encoding::US_ASCII).ascii_only?.should be_true
|
||||||
"hello".encode(Encoding::US_ASCII).ascii_only?.should be_true
|
"hello".encode(Encoding::US_ASCII).ascii_only?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -34,13 +34,13 @@ describe "String#ascii_only?" do
|
||||||
[ ["\u{6666}", false],
|
[ ["\u{6666}", false],
|
||||||
["hello, \u{6666}", false],
|
["hello, \u{6666}", false],
|
||||||
["\u{6666}".encode('UTF-8'), false],
|
["\u{6666}".encode('UTF-8'), false],
|
||||||
["\u{6666}".force_encoding('UTF-8'), false],
|
["\u{6666}".dup.force_encoding('UTF-8'), false],
|
||||||
].should be_computed_by(:ascii_only?)
|
].should be_computed_by(:ascii_only?)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false if the encoding is US-ASCII" do
|
it "returns false if the encoding is US-ASCII" do
|
||||||
[ ["\u{6666}".force_encoding(Encoding::US_ASCII), false],
|
[ ["\u{6666}".dup.force_encoding(Encoding::US_ASCII), false],
|
||||||
["hello, \u{6666}".force_encoding(Encoding::US_ASCII), false],
|
["hello, \u{6666}".dup.force_encoding(Encoding::US_ASCII), false],
|
||||||
].should be_computed_by(:ascii_only?)
|
].should be_computed_by(:ascii_only?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -51,17 +51,16 @@ describe "String#ascii_only?" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false for the empty String with a non-ASCII-compatible encoding" do
|
it "returns false for the empty String with a non-ASCII-compatible encoding" do
|
||||||
"".force_encoding('UTF-16LE').ascii_only?.should be_false
|
"".dup.force_encoding('UTF-16LE').ascii_only?.should be_false
|
||||||
"".encode('UTF-16BE').ascii_only?.should be_false
|
"".encode('UTF-16BE').ascii_only?.should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false for a non-empty String with non-ASCII-compatible encoding" do
|
it "returns false for a non-empty String with non-ASCII-compatible encoding" do
|
||||||
"\x78\x00".force_encoding("UTF-16LE").ascii_only?.should be_false
|
"\x78\x00".dup.force_encoding("UTF-16LE").ascii_only?.should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when interpolating non ascii strings" do
|
it "returns false when interpolating non ascii strings" do
|
||||||
base = "EU currency is"
|
base = "EU currency is".dup.force_encoding(Encoding::US_ASCII)
|
||||||
base.force_encoding(Encoding::US_ASCII)
|
|
||||||
euro = "\u20AC"
|
euro = "\u20AC"
|
||||||
interp = "#{base} #{euro}"
|
interp = "#{base} #{euro}"
|
||||||
euro.ascii_only?.should be_false
|
euro.ascii_only?.should be_false
|
||||||
|
@ -70,14 +69,14 @@ describe "String#ascii_only?" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false after appending non ASCII characters to an empty String" do
|
it "returns false after appending non ASCII characters to an empty String" do
|
||||||
("" << "λ").ascii_only?.should be_false
|
("".dup << "λ").ascii_only?.should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when concatenating an ASCII and non-ASCII String" do
|
it "returns false when concatenating an ASCII and non-ASCII String" do
|
||||||
"".concat("λ").ascii_only?.should be_false
|
"".dup.concat("λ").ascii_only?.should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when replacing an ASCII String with a non-ASCII String" do
|
it "returns false when replacing an ASCII String with a non-ASCII String" do
|
||||||
"".replace("λ").ascii_only?.should be_false
|
"".dup.replace("λ").ascii_only?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
|
|
||||||
describe "String#b" do
|
describe "String#b" do
|
||||||
|
|
|
@ -156,11 +156,11 @@ describe "String#byteindex with String" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles a substring in a superset encoding" do
|
it "handles a substring in a superset encoding" do
|
||||||
'abc'.force_encoding(Encoding::US_ASCII).byteindex('é').should == nil
|
'abc'.dup.force_encoding(Encoding::US_ASCII).byteindex('é').should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles a substring in a subset encoding" do
|
it "handles a substring in a subset encoding" do
|
||||||
'été'.byteindex('t'.force_encoding(Encoding::US_ASCII)).should == 2
|
'été'.byteindex('t'.dup.force_encoding(Encoding::US_ASCII)).should == 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -191,11 +191,11 @@ describe "String#byterindex with String" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles a substring in a superset encoding" do
|
it "handles a substring in a superset encoding" do
|
||||||
'abc'.force_encoding(Encoding::US_ASCII).byterindex('é').should == nil
|
'abc'.dup.force_encoding(Encoding::US_ASCII).byterindex('é').should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles a substring in a subset encoding" do
|
it "handles a substring in a subset encoding" do
|
||||||
'été'.byterindex('t'.force_encoding(Encoding::US_ASCII)).should == 2
|
'été'.byterindex('t'.dup.force_encoding(Encoding::US_ASCII)).should == 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -50,6 +50,6 @@ describe "String#bytes" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is unaffected by #force_encoding" do
|
it "is unaffected by #force_encoding" do
|
||||||
@utf8.force_encoding('ASCII').bytes.to_a.should == @utf8.bytes.to_a
|
@utf8.dup.force_encoding('ASCII').bytes.to_a.should == @utf8.bytes.to_a
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,21 +13,21 @@ describe "String#bytesize" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "works with pseudo-ASCII strings containing single UTF-8 characters" do
|
it "works with pseudo-ASCII strings containing single UTF-8 characters" do
|
||||||
"\u{6666}".force_encoding('ASCII').bytesize.should == 3
|
"\u{6666}".dup.force_encoding('ASCII').bytesize.should == 3
|
||||||
end
|
end
|
||||||
|
|
||||||
it "works with strings containing UTF-8 characters" do
|
it "works with strings containing UTF-8 characters" do
|
||||||
"c \u{6666}".force_encoding('UTF-8').bytesize.should == 5
|
"c \u{6666}".dup.force_encoding('UTF-8').bytesize.should == 5
|
||||||
"c \u{6666}".bytesize.should == 5
|
"c \u{6666}".bytesize.should == 5
|
||||||
end
|
end
|
||||||
|
|
||||||
it "works with pseudo-ASCII strings containing UTF-8 characters" do
|
it "works with pseudo-ASCII strings containing UTF-8 characters" do
|
||||||
"c \u{6666}".force_encoding('ASCII').bytesize.should == 5
|
"c \u{6666}".dup.force_encoding('ASCII').bytesize.should == 5
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns 0 for the empty string" do
|
it "returns 0 for the empty string" do
|
||||||
"".bytesize.should == 0
|
"".bytesize.should == 0
|
||||||
"".force_encoding('ASCII').bytesize.should == 0
|
"".dup.force_encoding('ASCII').bytesize.should == 0
|
||||||
"".force_encoding('UTF-8').bytesize.should == 0
|
"".dup.force_encoding('UTF-8').bytesize.should == 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,10 +19,10 @@ end
|
||||||
|
|
||||||
describe "String#byteslice on on non ASCII strings" do
|
describe "String#byteslice on on non ASCII strings" do
|
||||||
it "returns byteslice of unicode strings" do
|
it "returns byteslice of unicode strings" do
|
||||||
"\u3042".byteslice(1).should == "\x81".force_encoding("UTF-8")
|
"\u3042".byteslice(1).should == "\x81".dup.force_encoding("UTF-8")
|
||||||
"\u3042".byteslice(1, 2).should == "\x81\x82".force_encoding("UTF-8")
|
"\u3042".byteslice(1, 2).should == "\x81\x82".dup.force_encoding("UTF-8")
|
||||||
"\u3042".byteslice(1..2).should == "\x81\x82".force_encoding("UTF-8")
|
"\u3042".byteslice(1..2).should == "\x81\x82".dup.force_encoding("UTF-8")
|
||||||
"\u3042".byteslice(-1).should == "\x82".force_encoding("UTF-8")
|
"\u3042".byteslice(-1).should == "\x82".dup.force_encoding("UTF-8")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a String in the same encoding as self" do
|
it "returns a String in the same encoding as self" do
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
|
|
||||||
describe "String#bytesplice" do
|
describe "String#bytesplice" do
|
||||||
|
|
|
@ -90,7 +90,7 @@ end
|
||||||
|
|
||||||
describe "String#capitalize!" do
|
describe "String#capitalize!" do
|
||||||
it "capitalizes self in place" do
|
it "capitalizes self in place" do
|
||||||
a = "hello"
|
a = +"hello"
|
||||||
a.capitalize!.should equal(a)
|
a.capitalize!.should equal(a)
|
||||||
a.should == "Hello"
|
a.should == "Hello"
|
||||||
end
|
end
|
||||||
|
@ -103,13 +103,13 @@ describe "String#capitalize!" do
|
||||||
|
|
||||||
describe "full Unicode case mapping" do
|
describe "full Unicode case mapping" do
|
||||||
it "modifies self in place for all of Unicode with no option" do
|
it "modifies self in place for all of Unicode with no option" do
|
||||||
a = "äöÜ"
|
a = +"äöÜ"
|
||||||
a.capitalize!
|
a.capitalize!
|
||||||
a.should == "Äöü"
|
a.should == "Äöü"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do
|
it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do
|
||||||
a = "ß"
|
a = +"ß"
|
||||||
a.capitalize!
|
a.capitalize!
|
||||||
a.should == "Ss"
|
a.should == "Ss"
|
||||||
end
|
end
|
||||||
|
@ -121,7 +121,7 @@ describe "String#capitalize!" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "updates string metadata" do
|
it "updates string metadata" do
|
||||||
capitalized = "ßeT"
|
capitalized = +"ßeT"
|
||||||
capitalized.capitalize!
|
capitalized.capitalize!
|
||||||
|
|
||||||
capitalized.should == "Sset"
|
capitalized.should == "Sset"
|
||||||
|
@ -133,7 +133,7 @@ describe "String#capitalize!" do
|
||||||
|
|
||||||
describe "modifies self in place for ASCII-only case mapping" do
|
describe "modifies self in place for ASCII-only case mapping" do
|
||||||
it "does not capitalize non-ASCII characters" do
|
it "does not capitalize non-ASCII characters" do
|
||||||
a = "ßet"
|
a = +"ßet"
|
||||||
a.capitalize!(:ascii)
|
a.capitalize!(:ascii)
|
||||||
a.should == "ßet"
|
a.should == "ßet"
|
||||||
end
|
end
|
||||||
|
@ -147,13 +147,13 @@ describe "String#capitalize!" do
|
||||||
|
|
||||||
describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
|
describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
|
||||||
it "capitalizes ASCII characters according to Turkic semantics" do
|
it "capitalizes ASCII characters according to Turkic semantics" do
|
||||||
a = "iSa"
|
a = +"iSa"
|
||||||
a.capitalize!(:turkic)
|
a.capitalize!(:turkic)
|
||||||
a.should == "İsa"
|
a.should == "İsa"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows Lithuanian as an extra option" do
|
it "allows Lithuanian as an extra option" do
|
||||||
a = "iSa"
|
a = +"iSa"
|
||||||
a.capitalize!(:turkic, :lithuanian)
|
a.capitalize!(:turkic, :lithuanian)
|
||||||
a.should == "İsa"
|
a.should == "İsa"
|
||||||
end
|
end
|
||||||
|
@ -165,13 +165,13 @@ describe "String#capitalize!" do
|
||||||
|
|
||||||
describe "modifies self in place for full Unicode case mapping adapted for Lithuanian" do
|
describe "modifies self in place for full Unicode case mapping adapted for Lithuanian" do
|
||||||
it "currently works the same as full Unicode case mapping" do
|
it "currently works the same as full Unicode case mapping" do
|
||||||
a = "iß"
|
a = +"iß"
|
||||||
a.capitalize!(:lithuanian)
|
a.capitalize!(:lithuanian)
|
||||||
a.should == "Iß"
|
a.should == "Iß"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows Turkic as an extra option (and applies Turkic semantics)" do
|
it "allows Turkic as an extra option (and applies Turkic semantics)" do
|
||||||
a = "iß"
|
a = +"iß"
|
||||||
a.capitalize!(:lithuanian, :turkic)
|
a.capitalize!(:lithuanian, :turkic)
|
||||||
a.should == "İß"
|
a.should == "İß"
|
||||||
end
|
end
|
||||||
|
@ -190,12 +190,12 @@ describe "String#capitalize!" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nil when no changes are made" do
|
it "returns nil when no changes are made" do
|
||||||
a = "Hello"
|
a = +"Hello"
|
||||||
a.capitalize!.should == nil
|
a.capitalize!.should == nil
|
||||||
a.should == "Hello"
|
a.should == "Hello"
|
||||||
|
|
||||||
"".capitalize!.should == nil
|
(+"").capitalize!.should == nil
|
||||||
"H".capitalize!.should == nil
|
(+"H").capitalize!.should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises a FrozenError when self is frozen" do
|
it "raises a FrozenError when self is frozen" do
|
||||||
|
|
|
@ -92,7 +92,7 @@ describe "String#center with length, padding" do
|
||||||
|
|
||||||
describe "with width" do
|
describe "with width" do
|
||||||
it "returns a String in the same encoding as the original" do
|
it "returns a String in the same encoding as the original" do
|
||||||
str = "abc".force_encoding Encoding::IBM437
|
str = "abc".dup.force_encoding Encoding::IBM437
|
||||||
result = str.center 6
|
result = str.center 6
|
||||||
result.should == " abc "
|
result.should == " abc "
|
||||||
result.encoding.should equal(Encoding::IBM437)
|
result.encoding.should equal(Encoding::IBM437)
|
||||||
|
@ -101,7 +101,7 @@ describe "String#center with length, padding" do
|
||||||
|
|
||||||
describe "with width, pattern" do
|
describe "with width, pattern" do
|
||||||
it "returns a String in the compatible encoding" do
|
it "returns a String in the compatible encoding" do
|
||||||
str = "abc".force_encoding Encoding::IBM437
|
str = "abc".dup.force_encoding Encoding::IBM437
|
||||||
result = str.center 6, "あ"
|
result = str.center 6, "あ"
|
||||||
result.should == "あabcああ"
|
result.should == "あabcああ"
|
||||||
result.encoding.should equal(Encoding::UTF_8)
|
result.encoding.should equal(Encoding::UTF_8)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative 'fixtures/classes'
|
require_relative 'fixtures/classes'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative 'fixtures/classes'
|
require_relative 'fixtures/classes'
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
|
|
||||||
describe "String#clear" do
|
describe "String#clear" do
|
||||||
|
|
|
@ -11,7 +11,7 @@ describe "String#codepoints" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an ArgumentError when no block is given if self has an invalid encoding" do
|
it "raises an ArgumentError when no block is given if self has an invalid encoding" do
|
||||||
s = "\xDF".force_encoding(Encoding::UTF_8)
|
s = "\xDF".dup.force_encoding(Encoding::UTF_8)
|
||||||
s.valid_encoding?.should be_false
|
s.valid_encoding?.should be_false
|
||||||
-> { s.codepoints }.should raise_error(ArgumentError)
|
-> { s.codepoints }.should raise_error(ArgumentError)
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,12 +61,12 @@ describe "String#<=> with String" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "ignores encoding difference" do
|
it "ignores encoding difference" do
|
||||||
("ÄÖÛ".force_encoding("utf-8") <=> "ÄÖÜ".force_encoding("iso-8859-1")).should == -1
|
("ÄÖÛ".dup.force_encoding("utf-8") <=> "ÄÖÜ".dup.force_encoding("iso-8859-1")).should == -1
|
||||||
("ÄÖÜ".force_encoding("utf-8") <=> "ÄÖÛ".force_encoding("iso-8859-1")).should == 1
|
("ÄÖÜ".dup.force_encoding("utf-8") <=> "ÄÖÛ".dup.force_encoding("iso-8859-1")).should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns 0 with identical ASCII-compatible bytes of different encodings" do
|
it "returns 0 with identical ASCII-compatible bytes of different encodings" do
|
||||||
("abc".force_encoding("utf-8") <=> "abc".force_encoding("iso-8859-1")).should == 0
|
("abc".dup.force_encoding("utf-8") <=> "abc".dup.force_encoding("iso-8859-1")).should == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
it "compares the indices of the encodings when the strings have identical non-ASCII-compatible bytes" do
|
it "compares the indices of the encodings when the strings have identical non-ASCII-compatible bytes" do
|
||||||
|
@ -77,7 +77,7 @@ describe "String#<=> with String" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns 0 when comparing 2 empty strings but one is not ASCII-compatible" do
|
it "returns 0 when comparing 2 empty strings but one is not ASCII-compatible" do
|
||||||
("" <=> "".force_encoding('iso-2022-jp')).should == 0
|
("" <=> "".dup.force_encoding('iso-2022-jp')).should == 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,19 +8,19 @@ describe "String#concat" do
|
||||||
it_behaves_like :string_concat_type_coercion, :concat
|
it_behaves_like :string_concat_type_coercion, :concat
|
||||||
|
|
||||||
it "takes multiple arguments" do
|
it "takes multiple arguments" do
|
||||||
str = "hello "
|
str = +"hello "
|
||||||
str.concat "wo", "", "rld"
|
str.concat "wo", "", "rld"
|
||||||
str.should == "hello world"
|
str.should == "hello world"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "concatenates the initial value when given arguments contain 2 self" do
|
it "concatenates the initial value when given arguments contain 2 self" do
|
||||||
str = "hello"
|
str = +"hello"
|
||||||
str.concat str, str
|
str.concat str, str
|
||||||
str.should == "hellohellohello"
|
str.should == "hellohellohello"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns self when given no arguments" do
|
it "returns self when given no arguments" do
|
||||||
str = "hello"
|
str = +"hello"
|
||||||
str.concat.should equal(str)
|
str.concat.should equal(str)
|
||||||
str.should == "hello"
|
str.should == "hello"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative 'fixtures/classes'
|
require_relative 'fixtures/classes'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative 'fixtures/classes'
|
require_relative 'fixtures/classes'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative 'fixtures/classes'
|
require_relative 'fixtures/classes'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative 'fixtures/classes'
|
require_relative 'fixtures/classes'
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ describe "String#dup" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not modify the original setbyte-mutated string when changing dupped string" do
|
it "does not modify the original setbyte-mutated string when changing dupped string" do
|
||||||
orig = "a"
|
orig = +"a"
|
||||||
orig.setbyte 0, "b".ord
|
orig.setbyte 0, "b".ord
|
||||||
copy = orig.dup
|
copy = orig.dup
|
||||||
orig.setbyte 0, "c".ord
|
orig.setbyte 0, "c".ord
|
||||||
|
|
|
@ -9,26 +9,26 @@ describe "String#each_byte" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "keeps iterating from the old position (to new string end) when self changes" do
|
it "keeps iterating from the old position (to new string end) when self changes" do
|
||||||
r = ""
|
r = +""
|
||||||
s = "hello world"
|
s = +"hello world"
|
||||||
s.each_byte do |c|
|
s.each_byte do |c|
|
||||||
r << c
|
r << c
|
||||||
s.insert(0, "<>") if r.size < 3
|
s.insert(0, "<>") if r.size < 3
|
||||||
end
|
end
|
||||||
r.should == "h><>hello world"
|
r.should == "h><>hello world"
|
||||||
|
|
||||||
r = ""
|
r = +""
|
||||||
s = "hello world"
|
s = +"hello world"
|
||||||
s.each_byte { |c| s.slice!(-1); r << c }
|
s.each_byte { |c| s.slice!(-1); r << c }
|
||||||
r.should == "hello "
|
r.should == "hello "
|
||||||
|
|
||||||
r = ""
|
r = +""
|
||||||
s = "hello world"
|
s = +"hello world"
|
||||||
s.each_byte { |c| s.slice!(0); r << c }
|
s.each_byte { |c| s.slice!(0); r << c }
|
||||||
r.should == "hlowrd"
|
r.should == "hlowrd"
|
||||||
|
|
||||||
r = ""
|
r = +""
|
||||||
s = "hello world"
|
s = +"hello world"
|
||||||
s.each_byte { |c| s.slice!(0..-1); r << c }
|
s.each_byte { |c| s.slice!(0..-1); r << c }
|
||||||
r.should == "h"
|
r.should == "h"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative 'fixtures/classes'
|
require_relative 'fixtures/classes'
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ describe "String#encode" do
|
||||||
|
|
||||||
it "encodes an ascii substring of a binary string to UTF-8" do
|
it "encodes an ascii substring of a binary string to UTF-8" do
|
||||||
x82 = [0x82].pack('C')
|
x82 = [0x82].pack('C')
|
||||||
str = "#{x82}foo".force_encoding("binary")[1..-1].encode("utf-8")
|
str = "#{x82}foo".dup.force_encoding("binary")[1..-1].encode("utf-8")
|
||||||
str.should == "foo".force_encoding("utf-8")
|
str.should == "foo".dup.force_encoding("utf-8")
|
||||||
str.encoding.should equal(Encoding::UTF_8)
|
str.encoding.should equal(Encoding::UTF_8)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -49,7 +49,7 @@ describe "String#encode" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "round trips a String" do
|
it "round trips a String" do
|
||||||
str = "abc def".force_encoding Encoding::US_ASCII
|
str = "abc def".dup.force_encoding Encoding::US_ASCII
|
||||||
str.encode("utf-32be").encode("ascii").should == "abc def"
|
str.encode("utf-32be").encode("ascii").should == "abc def"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -122,8 +122,7 @@ describe "String#encode" do
|
||||||
|
|
||||||
describe "when passed to, from" do
|
describe "when passed to, from" do
|
||||||
it "returns a copy in the destination encoding when both encodings are the same" do
|
it "returns a copy in the destination encoding when both encodings are the same" do
|
||||||
str = "あ"
|
str = "あ".dup.force_encoding("binary")
|
||||||
str.force_encoding("binary")
|
|
||||||
encoded = str.encode("utf-8", "utf-8")
|
encoded = str.encode("utf-8", "utf-8")
|
||||||
|
|
||||||
encoded.should_not equal(str)
|
encoded.should_not equal(str)
|
||||||
|
@ -155,8 +154,7 @@ describe "String#encode" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a copy in the destination encoding when both encodings are the same" do
|
it "returns a copy in the destination encoding when both encodings are the same" do
|
||||||
str = "あ"
|
str = "あ".dup.force_encoding("binary")
|
||||||
str.force_encoding("binary")
|
|
||||||
encoded = str.encode("utf-8", "utf-8", invalid: :replace)
|
encoded = str.encode("utf-8", "utf-8", invalid: :replace)
|
||||||
|
|
||||||
encoded.should_not equal(str)
|
encoded.should_not equal(str)
|
||||||
|
@ -191,13 +189,13 @@ describe "String#encode!" do
|
||||||
describe "when passed no options" do
|
describe "when passed no options" do
|
||||||
it "returns self when Encoding.default_internal is nil" do
|
it "returns self when Encoding.default_internal is nil" do
|
||||||
Encoding.default_internal = nil
|
Encoding.default_internal = nil
|
||||||
str = "あ"
|
str = +"あ"
|
||||||
str.encode!.should equal(str)
|
str.encode!.should equal(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns self for a ASCII-only String when Encoding.default_internal is nil" do
|
it "returns self for a ASCII-only String when Encoding.default_internal is nil" do
|
||||||
Encoding.default_internal = nil
|
Encoding.default_internal = nil
|
||||||
str = "abc"
|
str = +"abc"
|
||||||
str.encode!.should equal(str)
|
str.encode!.should equal(str)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -205,14 +203,14 @@ describe "String#encode!" do
|
||||||
describe "when passed options" do
|
describe "when passed options" do
|
||||||
it "returns self for ASCII-only String when Encoding.default_internal is nil" do
|
it "returns self for ASCII-only String when Encoding.default_internal is nil" do
|
||||||
Encoding.default_internal = nil
|
Encoding.default_internal = nil
|
||||||
str = "abc"
|
str = +"abc"
|
||||||
str.encode!(invalid: :replace).should equal(str)
|
str.encode!(invalid: :replace).should equal(str)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when passed to encoding" do
|
describe "when passed to encoding" do
|
||||||
it "returns self" do
|
it "returns self" do
|
||||||
str = "abc"
|
str = +"abc"
|
||||||
result = str.encode!(Encoding::BINARY)
|
result = str.encode!(Encoding::BINARY)
|
||||||
result.encoding.should equal(Encoding::BINARY)
|
result.encoding.should equal(Encoding::BINARY)
|
||||||
result.should equal(str)
|
result.should equal(str)
|
||||||
|
@ -221,7 +219,7 @@ describe "String#encode!" do
|
||||||
|
|
||||||
describe "when passed to, from" do
|
describe "when passed to, from" do
|
||||||
it "returns self" do
|
it "returns self" do
|
||||||
str = "ああ"
|
str = +"ああ"
|
||||||
result = str.encode!("euc-jp", "utf-8")
|
result = str.encode!("euc-jp", "utf-8")
|
||||||
result.encoding.should equal(Encoding::EUC_JP)
|
result.encoding.should equal(Encoding::EUC_JP)
|
||||||
result.should equal(str)
|
result.should equal(str)
|
||||||
|
|
|
@ -14,11 +14,11 @@ describe "String#encoding" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the given encoding if #force_encoding has been called" do
|
it "returns the given encoding if #force_encoding has been called" do
|
||||||
"a".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
"a".dup.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the given encoding if #encode!has been called" do
|
it "returns the given encoding if #encode!has been called" do
|
||||||
"a".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
"a".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -108,13 +108,13 @@ describe "String#encoding for Strings with \\u escapes" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the given encoding if #force_encoding has been called" do
|
it "returns the given encoding if #force_encoding has been called" do
|
||||||
"\u{20}".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
"\u{20}".dup.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
||||||
"\u{2020}".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
"\u{2020}".dup.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the given encoding if #encode!has been called" do
|
it "returns the given encoding if #encode!has been called" do
|
||||||
"\u{20}".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
"\u{20}".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
||||||
"\u{2020}".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
"\u{2020}".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -173,16 +173,12 @@ describe "String#encoding for Strings with \\x escapes" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the given encoding if #force_encoding has been called" do
|
it "returns the given encoding if #force_encoding has been called" do
|
||||||
x50 = "\x50"
|
"\x50".dup.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
||||||
x50.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
[212].pack('C').force_encoding(Encoding::ISO_8859_9).encoding.should == Encoding::ISO_8859_9
|
||||||
xD4 = [212].pack('C')
|
|
||||||
xD4.force_encoding(Encoding::ISO_8859_9).encoding.should == Encoding::ISO_8859_9
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the given encoding if #encode!has been called" do
|
it "returns the given encoding if #encode!has been called" do
|
||||||
x50 = "\x50"
|
"\x50".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
||||||
x50.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
|
"x\00".dup.encode!(Encoding::UTF_8).encoding.should == Encoding::UTF_8
|
||||||
x00 = "x\00"
|
|
||||||
x00.encode!(Encoding::UTF_8).encoding.should == Encoding::UTF_8
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
|
|
||||||
describe "String#force_encoding" do
|
describe "String#force_encoding" do
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
|
|
||||||
describe "String#freeze" do
|
describe "String#freeze" do
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative 'fixtures/classes'
|
require_relative 'fixtures/classes'
|
||||||
|
|
||||||
|
|
|
@ -15,16 +15,16 @@ describe "String#include? with String" do
|
||||||
|
|
||||||
it "returns true if both strings are empty" do
|
it "returns true if both strings are empty" do
|
||||||
"".should.include?("")
|
"".should.include?("")
|
||||||
"".force_encoding("EUC-JP").should.include?("")
|
"".dup.force_encoding("EUC-JP").should.include?("")
|
||||||
"".should.include?("".force_encoding("EUC-JP"))
|
"".should.include?("".dup.force_encoding("EUC-JP"))
|
||||||
"".force_encoding("EUC-JP").should.include?("".force_encoding("EUC-JP"))
|
"".dup.force_encoding("EUC-JP").should.include?("".dup.force_encoding("EUC-JP"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns true if the RHS is empty" do
|
it "returns true if the RHS is empty" do
|
||||||
"a".should.include?("")
|
"a".should.include?("")
|
||||||
"a".force_encoding("EUC-JP").should.include?("")
|
"a".dup.force_encoding("EUC-JP").should.include?("")
|
||||||
"a".should.include?("".force_encoding("EUC-JP"))
|
"a".should.include?("".dup.force_encoding("EUC-JP"))
|
||||||
"a".force_encoding("EUC-JP").should.include?("".force_encoding("EUC-JP"))
|
"a".dup.force_encoding("EUC-JP").should.include?("".dup.force_encoding("EUC-JP"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "tries to convert other to string using to_str" do
|
it "tries to convert other to string using to_str" do
|
||||||
|
|
|
@ -161,16 +161,16 @@ describe "String#index with String" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles a substring in a superset encoding" do
|
it "handles a substring in a superset encoding" do
|
||||||
'abc'.force_encoding(Encoding::US_ASCII).index('é').should == nil
|
'abc'.dup.force_encoding(Encoding::US_ASCII).index('é').should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles a substring in a subset encoding" do
|
it "handles a substring in a subset encoding" do
|
||||||
'été'.index('t'.force_encoding(Encoding::US_ASCII)).should == 1
|
'été'.index('t'.dup.force_encoding(Encoding::US_ASCII)).should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
|
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
|
||||||
str = 'abc'.force_encoding("ISO-2022-JP")
|
str = 'abc'.dup.force_encoding("ISO-2022-JP")
|
||||||
pattern = 'b'.force_encoding("EUC-JP")
|
pattern = 'b'.dup.force_encoding("EUC-JP")
|
||||||
|
|
||||||
-> { str.index(pattern) }.should raise_error(Encoding::CompatibilityError, "incompatible character encodings: ISO-2022-JP and EUC-JP")
|
-> { str.index(pattern) }.should raise_error(Encoding::CompatibilityError, "incompatible character encodings: ISO-2022-JP and EUC-JP")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative 'fixtures/classes'
|
require_relative 'fixtures/classes'
|
||||||
|
|
||||||
|
|
|
@ -327,7 +327,7 @@ describe "String#inspect" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "works for broken US-ASCII strings" do
|
it "works for broken US-ASCII strings" do
|
||||||
s = "©".force_encoding("US-ASCII")
|
s = "©".dup.force_encoding("US-ASCII")
|
||||||
s.inspect.should == '"\xC2\xA9"'
|
s.inspect.should == '"\xC2\xA9"'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ describe "String#ljust with length, padding" do
|
||||||
|
|
||||||
describe "with width" do
|
describe "with width" do
|
||||||
it "returns a String in the same encoding as the original" do
|
it "returns a String in the same encoding as the original" do
|
||||||
str = "abc".force_encoding Encoding::IBM437
|
str = "abc".dup.force_encoding Encoding::IBM437
|
||||||
result = str.ljust 5
|
result = str.ljust 5
|
||||||
result.should == "abc "
|
result.should == "abc "
|
||||||
result.encoding.should equal(Encoding::IBM437)
|
result.encoding.should equal(Encoding::IBM437)
|
||||||
|
@ -84,7 +84,7 @@ describe "String#ljust with length, padding" do
|
||||||
|
|
||||||
describe "with width, pattern" do
|
describe "with width, pattern" do
|
||||||
it "returns a String in the compatible encoding" do
|
it "returns a String in the compatible encoding" do
|
||||||
str = "abc".force_encoding Encoding::IBM437
|
str = "abc".dup.force_encoding Encoding::IBM437
|
||||||
result = str.ljust 5, "あ"
|
result = str.ljust 5, "あ"
|
||||||
result.should == "abcああ"
|
result.should == "abcああ"
|
||||||
result.encoding.should equal(Encoding::UTF_8)
|
result.encoding.should equal(Encoding::UTF_8)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative 'fixtures/classes'
|
require_relative 'fixtures/classes'
|
||||||
require_relative 'shared/strip'
|
require_relative 'shared/strip'
|
||||||
|
|
|
@ -27,7 +27,7 @@ describe "String#ord" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises ArgumentError if the character is broken" do
|
it "raises ArgumentError if the character is broken" do
|
||||||
s = "©".force_encoding("US-ASCII")
|
s = "©".dup.force_encoding("US-ASCII")
|
||||||
-> { s.ord }.should raise_error(ArgumentError, "invalid byte sequence in US-ASCII")
|
-> { s.ord }.should raise_error(ArgumentError, "invalid byte sequence in US-ASCII")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,7 +40,7 @@ describe "String#partition with String" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles a pattern in a superset encoding" do
|
it "handles a pattern in a superset encoding" do
|
||||||
string = "hello".force_encoding(Encoding::US_ASCII)
|
string = "hello".dup.force_encoding(Encoding::US_ASCII)
|
||||||
|
|
||||||
result = string.partition("é")
|
result = string.partition("é")
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ describe "String#partition with String" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles a pattern in a subset encoding" do
|
it "handles a pattern in a subset encoding" do
|
||||||
pattern = "o".force_encoding(Encoding::US_ASCII)
|
pattern = "o".dup.force_encoding(Encoding::US_ASCII)
|
||||||
|
|
||||||
result = "héllo world".partition(pattern)
|
result = "héllo world".partition(pattern)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# frozen_string_literal: false
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative 'fixtures/classes'
|
require_relative 'fixtures/classes'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
# frozen_string_literal: false
|
||||||
|
|
||||||
require_relative '../../spec_helper'
|
require_relative '../../spec_helper'
|
||||||
require_relative 'fixtures/classes'
|
require_relative 'fixtures/classes'
|
||||||
|
|
|
@ -197,16 +197,16 @@ describe "String#rindex with String" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles a substring in a superset encoding" do
|
it "handles a substring in a superset encoding" do
|
||||||
'abc'.force_encoding(Encoding::US_ASCII).rindex('é').should == nil
|
'abc'.dup.force_encoding(Encoding::US_ASCII).rindex('é').should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles a substring in a subset encoding" do
|
it "handles a substring in a subset encoding" do
|
||||||
'été'.rindex('t'.force_encoding(Encoding::US_ASCII)).should == 1
|
'été'.rindex('t'.dup.force_encoding(Encoding::US_ASCII)).should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
|
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
|
||||||
str = 'abc'.force_encoding("ISO-2022-JP")
|
str = 'abc'.dup.force_encoding("ISO-2022-JP")
|
||||||
pattern = 'b'.force_encoding("EUC-JP")
|
pattern = 'b'.dup.force_encoding("EUC-JP")
|
||||||
|
|
||||||
-> { str.rindex(pattern) }.should raise_error(Encoding::CompatibilityError, "incompatible character encodings: ISO-2022-JP and EUC-JP")
|
-> { str.rindex(pattern) }.should raise_error(Encoding::CompatibilityError, "incompatible character encodings: ISO-2022-JP and EUC-JP")
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,7 +75,7 @@ describe "String#rjust with length, padding" do
|
||||||
|
|
||||||
describe "with width" do
|
describe "with width" do
|
||||||
it "returns a String in the same encoding as the original" do
|
it "returns a String in the same encoding as the original" do
|
||||||
str = "abc".force_encoding Encoding::IBM437
|
str = "abc".dup.force_encoding Encoding::IBM437
|
||||||
result = str.rjust 5
|
result = str.rjust 5
|
||||||
result.should == " abc"
|
result.should == " abc"
|
||||||
result.encoding.should equal(Encoding::IBM437)
|
result.encoding.should equal(Encoding::IBM437)
|
||||||
|
@ -84,7 +84,7 @@ describe "String#rjust with length, padding" do
|
||||||
|
|
||||||
describe "with width, pattern" do
|
describe "with width, pattern" do
|
||||||
it "returns a String in the compatible encoding" do
|
it "returns a String in the compatible encoding" do
|
||||||
str = "abc".force_encoding Encoding::IBM437
|
str = "abc".dup.force_encoding Encoding::IBM437
|
||||||
result = str.rjust 5, "あ"
|
result = str.rjust 5, "あ"
|
||||||
result.should == "ああabc"
|
result.should == "ああabc"
|
||||||
result.encoding.should equal(Encoding::UTF_8)
|
result.encoding.should equal(Encoding::UTF_8)
|
||||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче