This commit is contained in:
Benoit Daloze 2024-03-14 21:44:53 +01:00
Родитель 1d9f99144b
Коммит ed2f685253
209 изменённых файлов: 745 добавлений и 700 удалений

Просмотреть файл

@ -29,7 +29,7 @@ describe "ARGF.readpartial" do
it "clears output buffer even if EOFError is raised because @argf is at end" do
begin
output = "to be cleared"
output = +"to be cleared"
argf [@file1_name] do
@argf.read

Просмотреть файл

@ -9,7 +9,7 @@ describe :argf_getc, shared: true do
it "reads each char of files" do
argf [@file1, @file2] do
chars = ""
chars = +""
@chars.size.times { chars << @argf.send(@method) }
chars.should == @chars
end

Просмотреть файл

@ -15,7 +15,7 @@ describe :argf_read, shared: true do
it "treats second argument as an output buffer" do
argf [@file1_name] do
buffer = ""
buffer = +""
@argf.send(@method, @file1.size, buffer)
buffer.should == @file1
end
@ -23,7 +23,7 @@ describe :argf_read, shared: true do
it "clears output buffer before appending to it" do
argf [@file1_name] do
buffer = "to be cleared"
buffer = +"to be cleared"
@argf.send(@method, @file1.size, buffer)
buffer.should == @file1
end

Просмотреть файл

@ -21,7 +21,7 @@ describe "Array#fill" do
it "does not replicate the filler" do
ary = [1, 2, 3, 4]
str = "x"
str = +"x"
ary.fill(str).should == [str, str, str, str]
str << "y"
ary.should == [str, str, str, str]

Просмотреть файл

@ -2,14 +2,14 @@
module ArraySpecs
def self.array_with_usascii_and_7bit_utf8_strings
[
'foo'.force_encoding('US-ASCII'),
'foo'.dup.force_encoding('US-ASCII'),
'bar'
]
end
def self.array_with_usascii_and_utf8_strings
[
'foo'.force_encoding('US-ASCII'),
'foo'.dup.force_encoding('US-ASCII'),
'báz'
]
end
@ -17,7 +17,7 @@ module ArraySpecs
def self.array_with_7bit_utf8_and_usascii_strings
[
'bar',
'foo'.force_encoding('US-ASCII')
'foo'.dup.force_encoding('US-ASCII')
]
end
@ -25,13 +25,13 @@ module ArraySpecs
[
'báz',
'bar',
'foo'.force_encoding('US-ASCII')
'foo'.dup.force_encoding('US-ASCII')
]
end
def self.array_with_usascii_and_utf8_strings
[
'foo'.force_encoding('US-ASCII'),
'foo'.dup.force_encoding('US-ASCII'),
'bar',
'báz'
]
@ -41,7 +41,7 @@ module ArraySpecs
[
'bar',
'báz',
'foo'.force_encoding('BINARY')
'foo'.dup.force_encoding('BINARY')
]
end
@ -55,14 +55,14 @@ module ArraySpecs
def self.array_with_usascii_and_7bit_binary_strings
[
'bar'.force_encoding('US-ASCII'),
'foo'.force_encoding('BINARY')
'bar'.dup.force_encoding('US-ASCII'),
'foo'.dup.force_encoding('BINARY')
]
end
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')
]
end

Просмотреть файл

@ -13,13 +13,13 @@ describe "Array#pack with :buffer option" do
it "adds result at the end of buffer content" do
n = [ 65, 66, 67 ] # result without buffer is "ABC"
buffer = ""
buffer = +""
n.pack("ccc", buffer: buffer).should == "ABC"
buffer = "123"
buffer = +"123"
n.pack("ccc", buffer: buffer).should == "123ABC"
buffer = "12345"
buffer = +"12345"
n.pack("ccc", buffer: buffer).should == "12345ABC"
end
@ -31,19 +31,19 @@ describe "Array#pack with :buffer option" do
context "offset (@) is specified" do
it 'keeps buffer content if it is longer than offset' do
n = [ 65, 66, 67 ]
buffer = "123456"
buffer = +"123456"
n.pack("@3ccc", buffer: buffer).should == "123ABC"
end
it "fills the gap with \\0 if buffer content is shorter than offset" do
n = [ 65, 66, 67 ]
buffer = "123"
buffer = +"123"
n.pack("@6ccc", buffer: buffer).should == "123\0\0\0ABC"
end
it 'does not keep buffer content if it is longer than offset + result' do
n = [ 65, 66, 67 ]
buffer = "1234567890"
buffer = +"1234567890"
n.pack("@3ccc", buffer: buffer).should == "123ABC"
end
end

Просмотреть файл

@ -40,7 +40,7 @@ describe :array_pack_string, shared: true do
f = pack_format("*")
[ [["\u{3042 3044 3046 3048}", 0x2000B].pack(f+"U"), Encoding::BINARY],
[["abcde\xd1", "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY],
[["a".force_encoding("ascii"), "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY],
[["a".dup.force_encoding("ascii"), "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY],
# under discussion [ruby-dev:37294]
[["\u{3042 3044 3046 3048}", 1].pack(f+"N"), Encoding::BINARY]
].should be_computed_by(:encoding)

Просмотреть файл

@ -19,7 +19,7 @@ describe :array_inspect, shared: true do
end
it "does not call #to_s on a String returned from #inspect" do
str = "abc"
str = +"abc"
str.should_not_receive(:to_s)
[str].send(@method).should == '["abc"]'
@ -98,8 +98,8 @@ describe :array_inspect, shared: true do
end
it "does not raise if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
utf_16be = mock(+"utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode(Encoding::UTF_16BE))
[utf_16be].send(@method).should == '["utf_16be \u3042"]'
end

Просмотреть файл

@ -17,7 +17,8 @@ describe "Complex#inspect" do
it "calls #inspect on real and imaginary" do
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.should_receive(:inspect).and_return("2")
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
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.should_receive(:inspect).and_return("(2)")
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
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.should_receive(:to_s).and_return("2")
imaginary.should_receive(:<).any_number_of_times.and_return(false)

Просмотреть файл

@ -47,7 +47,7 @@ describe "Dir.children" do
encoding = Encoding.find("filesystem")
encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
platform_is_not :windows do
children.should include("こんにちは.txt".force_encoding(encoding))
children.should include("こんにちは.txt".dup.force_encoding(encoding))
end
children.first.encoding.should equal(Encoding.find("filesystem"))
end
@ -113,7 +113,7 @@ describe "Dir#children" do
encoding = Encoding.find("filesystem")
encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
platform_is_not :windows do
children.should include("こんにちは.txt".force_encoding(encoding))
children.should include("こんにちは.txt".dup.force_encoding(encoding))
end
children.first.encoding.should equal(Encoding.find("filesystem"))
end

Просмотреть файл

@ -47,7 +47,7 @@ describe "Dir.entries" do
encoding = Encoding.find("filesystem")
encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
platform_is_not :windows do
entries.should include("こんにちは.txt".force_encoding(encoding))
entries.should include("こんにちは.txt".dup.force_encoding(encoding))
end
entries.first.encoding.should equal(Encoding.find("filesystem"))
end

Просмотреть файл

@ -12,7 +12,7 @@ describe :dir_glob, shared: true do
end
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)
end

Просмотреть файл

@ -7,7 +7,7 @@ require_relative '../../spec_helper'
describe "Encoding.compatible? String, String" do
describe "when the first's Encoding is valid US-ASCII" do
before :each do
@str = "abc".force_encoding Encoding::US_ASCII
@str = "abc".dup.force_encoding Encoding::US_ASCII
end
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
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, "123".force_encoding("Shift_JIS"), "abc".force_encoding("UTF-8"), Encoding::Shift_JIS]
[ [Encoding, "abc".dup.force_encoding("UTF-8"), "123".dup.force_encoding("Shift_JIS"), Encoding::UTF_8],
[Encoding, "123".dup.force_encoding("Shift_JIS"), "abc".dup.force_encoding("UTF-8"), Encoding::Shift_JIS]
].should be_computed_by(:compatible?)
end
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, "123".force_encoding("US-ASCII"), "abc".force_encoding("BINARY"), Encoding::US_ASCII]
[ [Encoding, "abc".dup.force_encoding("BINARY"), "123".dup.force_encoding("US-ASCII"), Encoding::BINARY],
[Encoding, "123".dup.force_encoding("US-ASCII"), "abc".dup.force_encoding("BINARY"), Encoding::US_ASCII]
].should be_computed_by(:compatible?)
end
it "returns the second's Encoding if the second is ASCII compatible but not ASCII only" do
[ [Encoding, "abc".force_encoding("UTF-8"), "\xff".force_encoding("Shift_JIS"), Encoding::Shift_JIS],
[Encoding, "123".force_encoding("Shift_JIS"), "\xff".force_encoding("UTF-8"), Encoding::UTF_8],
[Encoding, "abc".force_encoding("BINARY"), "\xff".force_encoding("US-ASCII"), Encoding::US_ASCII],
[Encoding, "123".force_encoding("US-ASCII"), "\xff".force_encoding("BINARY"), Encoding::BINARY],
[ [Encoding, "abc".dup.force_encoding("UTF-8"), "\xff".dup.force_encoding("Shift_JIS"), Encoding::Shift_JIS],
[Encoding, "123".dup.force_encoding("Shift_JIS"), "\xff".dup.force_encoding("UTF-8"), Encoding::UTF_8],
[Encoding, "abc".dup.force_encoding("BINARY"), "\xff".dup.force_encoding("US-ASCII"), Encoding::US_ASCII],
[Encoding, "123".dup.force_encoding("US-ASCII"), "\xff".dup.force_encoding("BINARY"), Encoding::BINARY],
].should be_computed_by(:compatible?)
end
it "returns nil if the second's Encoding is not ASCII compatible" do
a = "abc".force_encoding("UTF-8")
b = "1234".force_encoding("UTF-16LE")
a = "abc".dup.force_encoding("UTF-8")
b = "1234".dup.force_encoding("UTF-16LE")
Encoding.compatible?(a, b).should be_nil
end
end
@ -75,7 +75,7 @@ describe "Encoding.compatible? String, String" do
describe "when the first's Encoding is not ASCII compatible" do
before :each do
@str = "abc".force_encoding Encoding::UTF_7
@str = "abc".dup.force_encoding Encoding::UTF_7
end
it "returns nil when the second String is US-ASCII" do
@ -91,14 +91,14 @@ describe "Encoding.compatible? String, String" do
end
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
end
end
describe "when the first's Encoding is invalid" do
before :each do
@str = "\xff".force_encoding Encoding::UTF_8
@str = "\xff".dup.force_encoding Encoding::UTF_8
end
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
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
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
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 "and the first's Encoding is ASCII compatible" do
before :each do
@str = "".force_encoding("utf-8")
@str = "".dup.force_encoding("utf-8")
end
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
before :each do
@str = "".force_encoding Encoding::UTF_7
@str = "".dup.force_encoding Encoding::UTF_7
end
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
before :each do
@str = "abc".force_encoding("utf-7")
@str = "abc".dup.force_encoding("utf-7")
end
it "returns the first Encoding" do
@ -165,7 +165,7 @@ end
describe "Encoding.compatible? String, Regexp" 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
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
[ [Encoding, "\xff", Encoding::BINARY],
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
[Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
[Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
[Encoding, "\xa4\xa2".dup.force_encoding("euc-jp"), Encoding::EUC_JP],
[Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS],
].should be_computed_by(:compatible?, /abc/)
end
end
describe "Encoding.compatible? String, Symbol" 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
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
[ [Encoding, "\xff", Encoding::BINARY],
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
[Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
[Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
[Encoding, "\xa4\xa2".dup.force_encoding("euc-jp"), Encoding::EUC_JP],
[Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS],
].should be_computed_by(:compatible?, :abc)
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
[ [Encoding, "\xff", Encoding::BINARY],
[Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
[Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
[Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
[Encoding, "\xa4\xa2".dup.force_encoding("euc-jp"), Encoding::EUC_JP],
[Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS],
].should be_computed_by(:compatible?, Encoding::US_ASCII)
end
@ -242,7 +242,7 @@ end
describe "Encoding.compatible? Regexp, String" 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
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
[ [Encoding, Regexp.new("\xff"), Encoding::BINARY],
[Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
[Encoding, Regexp.new("\xa4\xa2".force_encoding("euc-jp")), Encoding::EUC_JP],
[Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
[Encoding, Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp")), Encoding::EUC_JP],
[Encoding, Regexp.new("\x82\xa0".dup.force_encoding("shift_jis")), Encoding::Shift_JIS],
].should be_computed_by(:compatible?, /abc/)
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
[ [Encoding, Regexp.new("\xff"), Encoding::BINARY],
[Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
[Encoding, Regexp.new("\xa4\xa2".force_encoding("euc-jp")), Encoding::EUC_JP],
[Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
[Encoding, Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp")), Encoding::EUC_JP],
[Encoding, Regexp.new("\x82\xa0".dup.force_encoding("shift_jis")), Encoding::Shift_JIS],
].should be_computed_by(:compatible?, /abc/)
end
end
describe "Encoding.compatible? Symbol, String" 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
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
a = Regexp.new("\xff")
b = Regexp.new("\u3042".encode("utf-8"))
c = Regexp.new("\xa4\xa2".force_encoding("euc-jp"))
d = Regexp.new("\x82\xa0".force_encoding("shift_jis"))
c = Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp"))
d = Regexp.new("\x82\xa0".dup.force_encoding("shift_jis"))
[ [Encoding, :abc, a, Encoding::BINARY],
[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
[ [Encoding, "\xff".to_sym, Encoding::BINARY],
[Encoding, "\u3042".encode("utf-8").to_sym, Encoding::UTF_8],
[Encoding, "\xa4\xa2".force_encoding("euc-jp").to_sym, Encoding::EUC_JP],
[Encoding, "\x82\xa0".force_encoding("shift_jis").to_sym, Encoding::Shift_JIS],
[Encoding, "\xa4\xa2".dup.force_encoding("euc-jp").to_sym, Encoding::EUC_JP],
[Encoding, "\x82\xa0".dup.force_encoding("shift_jis").to_sym, Encoding::Shift_JIS],
].should be_computed_by(:compatible?, :abc)
end
end

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true
require_relative '../../../spec_helper'
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
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
end
it "transcodes the given String to the target encoding" do
ec = Encoding::Converter.new("utf-8", "euc-jp")
ec.convert("\u3042".force_encoding('UTF-8')).should == \
"\xA4\xA2".force_encoding('EUC-JP')
ec.convert("\u3042".dup.force_encoding('UTF-8')).should == \
"\xA4\xA2".dup.force_encoding('EUC-JP')
end
it "allows Strings of different encodings to the source encoding" do
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
end
it "reuses the given encoding pair if called multiple times" do
ec = Encoding::Converter.new('ascii', 'SJIS')
ec.convert('a'.force_encoding('ASCII')).should == 'a'.force_encoding('SJIS')
ec.convert('b'.force_encoding('ASCII')).should == 'b'.force_encoding('SJIS')
ec.convert('a'.dup.force_encoding('ASCII')).should == 'a'.dup.force_encoding('SJIS')
ec.convert('b'.dup.force_encoding('ASCII')).should == 'b'.dup.force_encoding('SJIS')
end
it "raises UndefinedConversionError if the String contains characters invalid for the target encoding" do
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)
end

Просмотреть файл

@ -16,8 +16,8 @@ describe "Encoding::Converter#finish" do
end
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.finish.should == "\e(B".force_encoding('iso-2022-jp')
@ec.convert("\u{9999}").should == "\e$B9a".dup.force_encoding('iso-2022-jp')
@ec.finish.should == "\e(B".dup.force_encoding('iso-2022-jp')
end
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
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
end
it "returns nil when #primitive_convert last returned :destination_buffer_full" do
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
ec.last_error.should be_nil
end
it "returns nil when #primitive_convert last returned :finished" do
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
end
it "returns nil if the last conversion succeeded but the penultimate failed" do
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
ec.primitive_convert(+"\xf1abcd", +"").should == :invalid_byte_sequence
ec.primitive_convert("glark".dup.force_encoding('utf-8'), +"").should == :finished
ec.last_error.should be_nil
end
it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :invalid_byte_sequence" do
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)
end
it "returns an Encoding::UndefinedConversionError when #primitive_convert last returned :undefined_conversion" do
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)
end
it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :incomplete_input" do
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)
end

Просмотреть файл

@ -107,7 +107,7 @@ describe "Encoding::Converter.new" do
it "sets the replacement String to '\\uFFFD'" do
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
it "sets the replacement String encoding to UTF-8" do

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: false
require_relative '../../../spec_helper'
describe "Encoding::Converter#primitive_convert" do

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: false
require_relative '../../../spec_helper'
describe "Encoding::Converter#primitive_errinfo" do

Просмотреть файл

@ -4,7 +4,7 @@ require_relative '../../../spec_helper'
describe "Encoding::Converter#putback" do
before :each do
@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
it "returns a String" do
@ -36,21 +36,21 @@ describe "Encoding::Converter#putback" do
it "returns the problematic bytes for UTF-16LE" do
ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
src = "\x00\xd8\x61\x00"
dst = ""
src = +"\x00\xd8\x61\x00"
dst = +""
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.putback.should == "a\x00".force_encoding("utf-16le")
ec.putback.should == "a\x00".dup.force_encoding("utf-16le")
ec.putback.should == ""
end
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")
src = "\x00\xd8\x61\x00"
dst = ""
src = +"\x00\xd8\x61\x00"
dst = +""
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.putback(2).should == "a\x00".force_encoding("utf-16le")
ec.putback(2).should == "a\x00".dup.force_encoding("utf-16le")
ec.putback.should == ""
end
end

Просмотреть файл

@ -13,7 +13,7 @@ describe "Encoding::Converter#replacement" do
it "returns \\uFFFD when the destination encoding is UTF-8" do
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
end
end
@ -38,33 +38,33 @@ describe "Encoding::Converter#replacement=" do
it "sets #replacement" do
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.should == '?'.force_encoding('utf-8')
ec.replacement.should == '?'.dup.force_encoding('utf-8')
end
it "raises an UndefinedConversionError is the argument cannot be converted into the destination encoding" do
ec = Encoding::Converter.new("sjis", "ascii")
utf8_q = "\u{986}".force_encoding('utf-8')
ec.primitive_convert(utf8_q.dup, "").should == :undefined_conversion
utf8_q = "\u{986}".dup.force_encoding('utf-8')
ec.primitive_convert(utf8_q.dup, +"").should == :undefined_conversion
-> { ec.replacement = utf8_q }.should \
raise_error(Encoding::UndefinedConversionError)
end
it "does not change the replacement character if the argument cannot be converted into the destination encoding" do
ec = Encoding::Converter.new("sjis", "ascii")
utf8_q = "\u{986}".force_encoding('utf-8')
ec.primitive_convert(utf8_q.dup, "").should == :undefined_conversion
utf8_q = "\u{986}".dup.force_encoding('utf-8')
ec.primitive_convert(utf8_q.dup, +"").should == :undefined_conversion
-> { ec.replacement = utf8_q }.should \
raise_error(Encoding::UndefinedConversionError)
ec.replacement.should == "?".force_encoding('us-ascii')
ec.replacement.should == "?".dup.force_encoding('us-ascii')
end
it "uses the replacement character" do
ec = Encoding::Converter.new("utf-8", "us-ascii", :invalid => :replace, :undef => :replace)
ec.replacement = "!"
dest = ""
status = ec.primitive_convert "中文123", dest
dest = +""
status = ec.primitive_convert(+"中文123", dest)
status.should == :finished
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
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
ec.primitive_convert("\xA1",'').should == :incomplete_input
ec.primitive_convert(+"\xA1", +'').should == :incomplete_input
begin
ec.convert("\xA1")
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
ec = Encoding::Converter.new("ascii", "utf-8")
ec.primitive_convert("\xfffffffff",'').should == :invalid_byte_sequence
ec.primitive_convert(+"\xfffffffff", +'').should == :invalid_byte_sequence
begin
ec.convert("\xfffffffff")
rescue Encoding::InvalidByteSequenceError => e

Просмотреть файл

@ -15,11 +15,11 @@ describe "Encoding::InvalidByteSequenceError#readagain_bytes" do
it "returns the bytes to be read again" do
@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]
@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]
end

Просмотреть файл

@ -18,8 +18,8 @@ describe "Encoding#replicate" do
e.name.should == name
Encoding.find(name).should == e
"a".force_encoding(e).valid_encoding?.should be_true
"\x80".force_encoding(e).valid_encoding?.should be_false
"a".dup.force_encoding(e).valid_encoding?.should be_true
"\x80".dup.force_encoding(e).valid_encoding?.should be_false
end
it "returns a replica of UTF-8" do
@ -28,9 +28,9 @@ describe "Encoding#replicate" do
e.name.should == name
Encoding.find(name).should == e
"a".force_encoding(e).valid_encoding?.should be_true
"\u3042".force_encoding(e).valid_encoding?.should be_true
"\x80".force_encoding(e).valid_encoding?.should be_false
"a".dup.force_encoding(e).valid_encoding?.should be_true
"\u3042".dup.force_encoding(e).valid_encoding?.should be_true
"\x80".dup.force_encoding(e).valid_encoding?.should be_false
end
it "returns a replica of UTF-16BE" do
@ -39,9 +39,9 @@ describe "Encoding#replicate" do
e.name.should == name
Encoding.find(name).should == e
"a".force_encoding(e).valid_encoding?.should be_false
"\x30\x42".force_encoding(e).valid_encoding?.should be_true
"\x80".force_encoding(e).valid_encoding?.should be_false
"a".dup.force_encoding(e).valid_encoding?.should be_false
"\x30\x42".dup.force_encoding(e).valid_encoding?.should be_true
"\x80".dup.force_encoding(e).valid_encoding?.should be_false
end
it "returns a replica of ISO-2022-JP" do
@ -61,7 +61,7 @@ describe "Encoding#replicate" do
e.name.should == name
Encoding.find(name).should == e
s = "abc".force_encoding(e)
s = "abc".dup.force_encoding(e)
s.encoding.should == e
s.encoding.name.should == name
end

Просмотреть файл

@ -23,14 +23,6 @@ ruby_version_is "3.2" do
product.size.should == Float::INFINITY
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
enum = Object.new
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
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)
weird_path = [222, 173, 190, 175].pack('C*')

Просмотреть файл

@ -1,7 +1,7 @@
describe :file_path, shared: true do
before :each do
@name = "file_to_path"
@path = tmp(@name)
@path = tmp("file_to_path")
@name = File.basename(@path)
touch @path
end

Просмотреть файл

@ -22,11 +22,11 @@ describe "Hash#assoc" do
end
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
k1 = 'pear'
k1 = 'pear'.dup
h[k1] = :red
k2 = 'pear'
k2 = 'pear'.dup
h[k2] = :green
h.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)
end
# Behaviour confirmed in bug #1871
# Behaviour confirmed in https://bugs.ruby-lang.org/issues/1871
it "persists over #dups" do
@idh['foo'] = :bar
@idh['foo'] = :glark
@idh['foo'.dup] = :bar
@idh['foo'.dup] = :glark
@idh.dup.should == @idh
@idh.dup.size.should == @idh.size
@idh.dup.should.compare_by_identity?
end
it "persists over #clones" do
@idh['foo'] = :bar
@idh['foo'] = :glark
@idh['foo'.dup] = :bar
@idh['foo'.dup] = :glark
@idh.clone.should == @idh
@idh.clone.size.should == @idh.size
@idh.dup.should.compare_by_identity?
end
it "does not copy string keys" do
@ -109,8 +111,11 @@ describe "Hash#compare_by_identity" do
end
it "gives different identity for string literals" do
eval <<~RUBY
# frozen_string_literal: false
@idh['foo'] = 1
@idh['foo'] = 2
RUBY
@idh.values.should == [1, 2]
@idh.size.should == 2
end

Просмотреть файл

@ -30,7 +30,7 @@ describe "Hash#[]" do
end
it "does not create copies of the immediate default value" do
str = "foo"
str = +"foo"
h = Hash.new(str)
a = h[:a]
b = h[:b]

Просмотреть файл

@ -9,7 +9,7 @@ describe :hash_store, shared: true do
it "duplicates string keys using dup semantics" do
# dup doesn't copy singleton methods
key = "foo"
key = +"foo"
def key.reverse() "bar" end
h = {}
h.send(@method, key, 0)
@ -44,7 +44,7 @@ describe :hash_store, shared: true do
end
it "duplicates and freezes string keys" do
key = "foo"
key = +"foo"
h = {}
h.send(@method, key, 0)
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
h = { "a" => 1, "b" => 2, "c" => 3, "d" => 4 }
key1 = "foo"
key2 = "foo"
key1 = "foo".dup
key2 = "foo".dup
key1.should_not equal(key2)
h[key1] = 41
frozen_key = h.keys.last

Просмотреть файл

@ -24,7 +24,7 @@ describe :hash_to_s, shared: true do
end
it "does not call #to_s on a String returned from #inspect" do
str = "abc"
str = +"abc"
str.should_not_receive(:to_s)
{ 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
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"}'
end

Просмотреть файл

@ -12,7 +12,7 @@ describe "IO#ioctl" do
guard -> { RUBY_PLATFORM.include?("86") } do # x86 / x86_64
it "resizes an empty String to match the output size" do
File.open(__FILE__, 'r') do |f|
buffer = ''
buffer = +''
# FIONREAD in /usr/include/asm-generic/ioctls.h
f.ioctl 0x541B, buffer
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
it "accepts a length, an offset, and an output buffer" do
buffer = "foo"
buffer = +"foo"
@file.pread(3, 4, buffer)
buffer.should == "567"
end
it "shrinks the buffer in case of less bytes read" do
buffer = "foo"
buffer = +"foo"
@file.pread(1, 0, buffer)
buffer.should == "1"
end
it "grows the buffer in case of more bytes read" do
buffer = "foo"
buffer = +"foo"
@file.pread(5, 0, buffer)
buffer.should == "12345"
end
@ -57,7 +57,7 @@ guard -> { platform_is_not :windows or ruby_version_is "3.3" } do
end
it "does not reset the buffer when reading with maxlen = 0" do
buffer = "foo"
buffer = +"foo"
@file.pread(0, 4, buffer)
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
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)
buffer.should_not.is_a?(String)
buffer.to_str.should == "1234"

Просмотреть файл

@ -6,7 +6,7 @@ describe "IO#puts" do
@before_separator = $/
@name = tmp("io_puts.txt")
@io = new_io @name
ScratchPad.record ""
ScratchPad.record(+"")
def @io.write(str)
ScratchPad << str
end

Просмотреть файл

@ -96,21 +96,21 @@ describe "IO#read_nonblock" do
end
it "reads into the passed buffer" do
buffer = ""
buffer = +""
@write.write("1")
@read.read_nonblock(1, buffer)
buffer.should == "1"
end
it "returns the passed buffer" do
buffer = ""
buffer = +""
@write.write("1")
output = @read.read_nonblock(1, buffer)
output.should equal(buffer)
end
it "discards the existing buffer content upon successful read" do
buffer = "existing content"
buffer = +"existing content"
@write.write("hello world")
@write.close
@read.read_nonblock(11, buffer)
@ -118,7 +118,7 @@ describe "IO#read_nonblock" do
end
it "discards the existing buffer content upon error" do
buffer = "existing content"
buffer = +"existing content"
@write.close
-> { @read.read_nonblock(1, buffer) }.should raise_error(EOFError)
buffer.should be_empty

Просмотреть файл

@ -294,19 +294,19 @@ describe "IO#read" do
it "clears the output buffer if there is nothing to read" do
@io.pos = 10
buf = 'non-empty string'
buf = +'non-empty string'
@io.read(10, buf).should == nil
buf.should == ''
buf = 'non-empty string'
buf = +'non-empty string'
@io.read(nil, buf).should == ""
buf.should == ''
buf = 'non-empty string'
buf = +'non-empty string'
@io.read(0, buf).should == ""
@ -344,53 +344,53 @@ describe "IO#read" do
end
it "places the specified number of bytes in the buffer" do
buf = ""
buf = +""
@io.read 5, buf
buf.should == "12345"
end
it "expands the buffer when too small" do
buf = "ABCDE"
buf = +"ABCDE"
@io.read nil, buf
buf.should == @contents
end
it "overwrites the buffer" do
buf = "ABCDEFGHIJ"
buf = +"ABCDEFGHIJ"
@io.read nil, buf
buf.should == @contents
end
it "truncates the buffer when too big" do
buf = "ABCDEFGHIJKLMNO"
buf = +"ABCDEFGHIJKLMNO"
@io.read nil, buf
buf.should == @contents
@io.rewind
buf = "ABCDEFGHIJKLMNO"
buf = +"ABCDEFGHIJKLMNO"
@io.read 5, buf
buf.should == @contents[0..4]
end
it "returns the given buffer" do
buf = ""
buf = +""
@io.read(nil, buf).should equal buf
end
it "returns the given buffer when there is nothing to read" do
buf = ""
buf = +""
@io.read
@io.read(nil, buf).should equal buf
end
it "coerces the second argument to string and uses it as a buffer" do
buf = "ABCDE"
buf = +"ABCDE"
obj = mock("buff")
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
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 == "ありがとう\n"
end
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)
buf.encoding.should equal(Encoding::UTF_8)
end
@ -612,14 +612,14 @@ describe :io_read_size_internal_encoding, shared: true do
end
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)
buf.should == [164, 162, 164, 234].pack('C*').force_encoding(Encoding::ISO_8859_1)
buf.encoding.should equal(Encoding::ISO_8859_1)
end
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(1, buf).should be_nil

Просмотреть файл

@ -59,7 +59,7 @@ describe "IO#readpartial" do
end
it "discards the existing buffer content upon successful read" do
buffer = "existing content"
buffer = +"existing content"
@wr.write("hello world")
@wr.close
@rd.readpartial(11, buffer)
@ -74,7 +74,7 @@ describe "IO#readpartial" do
end
it "discards the existing buffer content upon error" do
buffer = 'hello'
buffer = +'hello'
@wr.close
-> { @rd.readpartial(1, buffer) }.should raise_error(EOFError)
buffer.should be_empty
@ -95,7 +95,7 @@ describe "IO#readpartial" do
ruby_bug "#18421", ""..."3.0.4" 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
buffer.should == ""
end

Просмотреть файл

@ -99,7 +99,7 @@ describe :io_readlines_options_19, shared: true do
end
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
end
end

Просмотреть файл

@ -21,25 +21,25 @@ describe "IO#sysread on a file" do
end
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
buf.should == "012345678901234"
@file.rewind
buf = "ABCDE" # small buffer
buf = +"ABCDE" # small buffer
@file.sysread(15, buf).should == buf
buf.should == "012345678901234"
@file.rewind
buf = "ABCDE" * 5 # large buffer
buf = +"ABCDE" * 5 # large buffer
@file.sysread(15, buf).should == buf
buf.should == "012345678901234"
end
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)
@file.sysread(15, obj).should == buf
buf.should == "012345678901234"
@ -90,19 +90,19 @@ describe "IO#sysread on a file" do
end
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
buffer.should == "existing content"
end
it "discards the existing buffer content upon successful read" do
buffer = "existing content"
buffer = +"existing content"
@file.sysread(11, buffer)
buffer.should == "01234567890"
end
it "discards the existing buffer content upon error" do
buffer = "existing content"
buffer = +"existing content"
@file.seek(0, :END)
-> { @file.sysread(1, buffer) }.should raise_error(EOFError)
buffer.should be_empty

Просмотреть файл

@ -41,7 +41,7 @@ describe :kernel_float, shared: true do
end
it "converts Strings to floats without calling #to_f" do
string = "10"
string = +"10"
string.should_not_receive(:to_f)
@object.send(:Float, string).should == 10.0
end

Просмотреть файл

@ -78,7 +78,7 @@ describe :kernel_String, shared: true do
end
it "returns the same object if it is already a String" do
string = "Hello"
string = +"Hello"
string.should_not_receive(:to_s)
string2 = @object.send(@method, string)
string.should equal(string2)

Просмотреть файл

@ -35,7 +35,7 @@ describe "Kernel.catch" do
end
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
it "catches a Symbol when thrown a matching Symbol" do

Просмотреть файл

@ -19,7 +19,7 @@ describe "Kernel#class" do
end
it "returns the first non-singleton class" do
a = "hello"
a = +"hello"
def a.my_singleton_method; end
a.class.should equal(String)
end

Просмотреть файл

@ -350,9 +350,6 @@ CODE
end
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
# encoding: UTF-8
# frozen_string_literal: true
@ -403,6 +400,7 @@ CODE
end
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
some_token_before_magic_comment = :anything
# frozen_string_literal: true
@ -411,11 +409,11 @@ class EvalSpecs
end
CODE
-> { 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
-> { 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
end
end

Просмотреть файл

@ -14,14 +14,14 @@ describe :kernel_sprintf_encoding, shared: true do
end
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.encoding.should equal(Encoding::KOI8_U)
end
it "returns a String in the argument's encoding if format encoding is more restrictive" do
string = "foo %s".force_encoding(Encoding::US_ASCII)
argument = "b\303\274r".force_encoding(Encoding::UTF_8)
string = "foo %s".dup.force_encoding(Encoding::US_ASCII)
argument = "b\303\274r".dup.force_encoding(Encoding::UTF_8)
result = @method.call(string, argument)
result.encoding.should equal(Encoding::UTF_8)
@ -56,7 +56,7 @@ describe :kernel_sprintf_encoding, shared: true do
end
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.encoding.should == Encoding::EUC_JP

Просмотреть файл

@ -76,7 +76,7 @@ describe "Marshal.dump" do
end
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"
end
@ -85,8 +85,8 @@ describe "Marshal.dump" do
symbol1 = "I:\t\xE2\x82\xACa\x06:\x06ET"
symbol2 = "I:\t\xE2\x82\xACb\x06;\x06T"
value = [
"€a".force_encoding(Encoding::UTF_8).to_sym,
"€b".force_encoding(Encoding::UTF_8).to_sym
"€a".dup.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}"
@ -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
class MarshalSpec::M1::A
def _dump(level)
s = "<dump>"
s = +"<dump>"
s.instance_variable_set(:@foo, "bar")
s
end
@ -194,7 +194,7 @@ describe "Marshal.dump" do
end
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"
end
@ -217,7 +217,7 @@ describe "Marshal.dump" do
end
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"
end
@ -285,11 +285,11 @@ describe "Marshal.dump" do
describe "with a 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
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
it "dumps a long String" do
@ -297,7 +297,7 @@ describe "Marshal.dump" do
end
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
it "dumps a String subclass" do
@ -314,23 +314,23 @@ describe "Marshal.dump" do
end
it "dumps a String with instance variables" do
str = ""
str = +""
str.instance_variable_set("@foo", "bar")
Marshal.dump(str.force_encoding("binary")).should == "\x04\bI\"\x00\x06:\t@foo\"\bbar"
end
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"
end
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"
end
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"
Marshal.dump(str).should == result
end
@ -364,7 +364,7 @@ describe "Marshal.dump" do
end
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"
end
@ -383,18 +383,18 @@ describe "Marshal.dump" do
end
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"
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"
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"
end
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"
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
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)
Marshal.dump(obj).should == "\x04\bo:\vObject\x06I:\b@\xC3\xA9\x06:\x06ETi\x06"
end
@ -685,7 +685,7 @@ describe "Marshal.dump" do
end
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"
end

Просмотреть файл

@ -38,7 +38,7 @@ class UserDefinedWithIvar
attr_reader :a, :b, :c
def initialize
@a = 'stuff'
@a = +'stuff'
@a.instance_variable_set :@foo, :UserDefinedWithIvar
@b = 'more'
@c = @b
@ -267,7 +267,7 @@ module MarshalSpec
end
end
module_eval(<<~ruby.force_encoding(Encoding::UTF_8))
module_eval(<<~ruby.dup.force_encoding(Encoding::UTF_8))
class MultibyteぁあぃいClass
end
@ -313,7 +313,7 @@ module MarshalSpec
"\004\b\"\012small"],
"String big" => ['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"],
"String subclass" => [UserString.new,
"\004\bC:\017UserString\"\000"],
@ -420,7 +420,7 @@ module MarshalSpec
"\x04\bI\"\nsmall\x06:\x06EF"],
"String big" => ['big' * 100,
"\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"],
"String subclass" => [UserString.new,
"\004\bC:\017UserString\"\000"],

Просмотреть файл

@ -183,7 +183,7 @@ describe :marshal_load, shared: true do
describe "when called with a proc" do
it "call the proc with frozen objects" do
arr = []
s = 'hi'
s = +'hi'
s.instance_variable_set(:@foo, 5)
st = Struct.new("Brittle", :a).new
st.instance_variable_set(:@clue, 'none')
@ -268,7 +268,7 @@ describe :marshal_load, shared: true do
it "loads an Array with proc" do
arr = []
s = 'hi'
s = +'hi'
s.instance_variable_set(:@foo, 5)
st = Struct.new("Brittle", :a).new
st.instance_variable_set(:@clue, 'none')
@ -413,13 +413,13 @@ describe :marshal_load, shared: true do
end
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[1] = (Marshal::MINOR_VERSION + 1).chr
-> { 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[1] = (Marshal::MINOR_VERSION).chr
@ -470,7 +470,7 @@ describe :marshal_load, shared: true do
end
it "loads an array having ivar" do
s = 'well'
s = +'well'
s.instance_variable_set(:@foo, 10)
obj = ['5', s, 'hi'].extend(Meths, MethsMore)
obj.instance_variable_set(:@mix, s)
@ -516,7 +516,7 @@ describe :marshal_load, shared: true do
end
it "preserves hash ivars when hash contains a string having ivar" do
s = 'string'
s = +'string'
s.instance_variable_set :@string_ivar, 'string ivar'
h = { key: s }
h.instance_variable_set :@hash_ivar, 'hash ivar'
@ -600,7 +600,7 @@ describe :marshal_load, shared: true do
end
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.should == s
sym.encoding.should == Encoding::BINARY
@ -614,8 +614,8 @@ describe :marshal_load, shared: true do
value = Marshal.send(@method, dump)
value.map(&:encoding).should == [Encoding::UTF_8, Encoding::UTF_8]
expected = [
"€a".force_encoding(Encoding::UTF_8).to_sym,
"€b".force_encoding(Encoding::UTF_8).to_sym
"€a".dup.force_encoding(Encoding::UTF_8).to_sym,
"€b".dup.force_encoding(Encoding::UTF_8).to_sym
]
value.should == expected
@ -635,7 +635,7 @@ describe :marshal_load, shared: true do
describe "for a String" do
it "loads a string having ivar with ref to self" do
obj = 'hi'
obj = +'hi'
obj.instance_variable_set(:@self, obj)
Marshal.send(@method, "\004\bI\"\ahi\006:\n@self@\000").should == obj
end
@ -647,7 +647,7 @@ describe :marshal_load, shared: true do
end
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
-> { Marshal.load(io) }.should raise_error(RuntimeError, "binmode")
end
@ -663,7 +663,7 @@ describe :marshal_load, shared: true do
end
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"
result = Marshal.send(@method, data)
result.should == str
@ -671,7 +671,7 @@ describe :marshal_load, shared: true do
end
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"
result = Marshal.send(@method, data)
result.should == str
@ -679,7 +679,7 @@ describe :marshal_load, shared: true do
end
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"
result = Marshal.send(@method, data)
result.should == str
@ -687,8 +687,8 @@ describe :marshal_load, shared: true do
end
it "loads a String as BINARY if no encoding is specified at the end" do
str = "\xC3\xB8".force_encoding("BINARY")
data = "\x04\b\"\a\xC3\xB8".force_encoding("UTF-8")
str = "\xC3\xB8".dup.force_encoding("BINARY")
data = "\x04\b\"\a\xC3\xB8".dup.force_encoding("UTF-8")
result = Marshal.send(@method, data)
result.encoding.should == Encoding::BINARY
result.should == str
@ -823,7 +823,7 @@ describe :marshal_load, shared: true do
end
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.instance_variables.should == [ivar]
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
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
end
end

Просмотреть файл

@ -8,12 +8,12 @@ describe "MatchData#post_match" do
end
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)
end
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)
end

Просмотреть файл

@ -8,12 +8,12 @@ describe "MatchData#pre_match" do
end
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)
end
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)
end

Просмотреть файл

@ -17,8 +17,9 @@ describe "MatchData#string" do
md.string.should equal(md.string)
end
it "returns a frozen copy of the matched string for gsub(String)" do
'he[[o'.gsub!('[', ']')
it "returns a frozen copy of the matched string for gsub!(String)" do
s = +'he[[o'
s.gsub!('[', ']')
$~.string.should == 'he[[o'
$~.string.should.frozen?
end

Просмотреть файл

@ -35,7 +35,7 @@ describe "Method#to_proc" do
end
it "returns a proc that can be used by define_method" do
x = 'test'
x = +'test'
to_s = class << x
define_method :foo, method(:to_s).to_proc
to_s

Просмотреть файл

@ -316,7 +316,7 @@ describe "Module#using" do
using refinement
def initialize
@a = "1703"
@a = +"1703"
@a.instance_eval do
def abc

Просмотреть файл

@ -52,7 +52,7 @@ describe "ObjectSpace.define_finalizer" do
Proc.new { puts "finalizer run" }
end
handler = scoped
obj = "Test"
obj = +"Test"
ObjectSpace.define_finalizer(obj, handler)
exit 0
RUBY
@ -111,7 +111,7 @@ describe "ObjectSpace.define_finalizer" do
it "calls a finalizer at exit even if it is self-referencing" do
code = <<-RUBY
obj = "Test"
obj = +"Test"
handler = Proc.new { puts "finalizer run" }
ObjectSpace.define_finalizer(obj, handler)
exit 0
@ -141,9 +141,9 @@ describe "ObjectSpace.define_finalizer" do
it "calls a finalizer defined in a finalizer running at exit" do
code = <<-RUBY
obj = "Test"
obj = +"Test"
handler = Proc.new do
obj2 = "Test"
obj2 = +"Test"
handler2 = Proc.new { puts "finalizer 2 run" }
ObjectSpace.define_finalizer(obj2, handler2)
exit 0

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: false
module ProcArefSpecs
def self.aref
proc {|a| a }["sometext"]

Просмотреть файл

@ -489,12 +489,12 @@ describe :regexp_new_string, shared: true do
end
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
end
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
end
end

Просмотреть файл

@ -18,23 +18,23 @@ describe :regexp_quote, shared: true do
end
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.\x80".force_encoding("UTF-8")).should == "a\\.\x80".force_encoding("UTF-8")
Regexp.send(@method, "a.\x85b.".dup.force_encoding("US-ASCII")).should =="a\\.\x85b\\.".dup.force_encoding("US-ASCII")
Regexp.send(@method, "a.\x80".dup.force_encoding("UTF-8")).should == "a\\.\x80".dup.force_encoding("UTF-8")
end
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
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
str = "ありがとう".force_encoding("utf-8")
str = "ありがとう".dup.force_encoding("utf-8")
str.valid_encoding?.should be_true
Regexp.send(@method, str).encoding.should == Encoding::UTF_8
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
str = "\xff".force_encoding "us-ascii"
str = "\xff".dup.force_encoding "us-ascii"
str.valid_encoding?.should be_false
Regexp.send(@method, "\xff").encoding.should == Encoding::BINARY
end

Просмотреть файл

@ -7,12 +7,12 @@ describe "String#ascii_only?" do
it "returns true if the encoding is UTF-8" do
[ ["hello", 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?)
end
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
end
@ -34,13 +34,13 @@ describe "String#ascii_only?" do
[ ["\u{6666}", false],
["hello, \u{6666}", 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?)
end
it "returns false if the encoding is US-ASCII" do
[ ["\u{6666}".force_encoding(Encoding::US_ASCII), false],
["hello, \u{6666}".force_encoding(Encoding::US_ASCII), false],
[ ["\u{6666}".dup.force_encoding(Encoding::US_ASCII), false],
["hello, \u{6666}".dup.force_encoding(Encoding::US_ASCII), false],
].should be_computed_by(:ascii_only?)
end
end
@ -51,17 +51,16 @@ describe "String#ascii_only?" do
end
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
end
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
it "returns false when interpolating non ascii strings" do
base = "EU currency is"
base.force_encoding(Encoding::US_ASCII)
base = "EU currency is".dup.force_encoding(Encoding::US_ASCII)
euro = "\u20AC"
interp = "#{base} #{euro}"
euro.ascii_only?.should be_false
@ -70,14 +69,14 @@ describe "String#ascii_only?" do
end
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
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
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

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: false
require_relative '../../spec_helper'
describe "String#b" do

Просмотреть файл

@ -156,11 +156,11 @@ describe "String#byteindex with String" do
end
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
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

Просмотреть файл

@ -191,11 +191,11 @@ describe "String#byterindex with String" do
end
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
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

Просмотреть файл

@ -50,6 +50,6 @@ describe "String#bytes" do
end
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

Просмотреть файл

@ -13,21 +13,21 @@ describe "String#bytesize" do
end
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
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
end
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
it "returns 0 for the empty string" do
"".bytesize.should == 0
"".force_encoding('ASCII').bytesize.should == 0
"".force_encoding('UTF-8').bytesize.should == 0
"".dup.force_encoding('ASCII').bytesize.should == 0
"".dup.force_encoding('UTF-8').bytesize.should == 0
end
end

Просмотреть файл

@ -19,10 +19,10 @@ end
describe "String#byteslice on on non ASCII strings" do
it "returns byteslice of unicode strings" do
"\u3042".byteslice(1).should == "\x81".force_encoding("UTF-8")
"\u3042".byteslice(1, 2).should == "\x81\x82".force_encoding("UTF-8")
"\u3042".byteslice(1..2).should == "\x81\x82".force_encoding("UTF-8")
"\u3042".byteslice(-1).should == "\x82".force_encoding("UTF-8")
"\u3042".byteslice(1).should == "\x81".dup.force_encoding("UTF-8")
"\u3042".byteslice(1, 2).should == "\x81\x82".dup.force_encoding("UTF-8")
"\u3042".byteslice(1..2).should == "\x81\x82".dup.force_encoding("UTF-8")
"\u3042".byteslice(-1).should == "\x82".dup.force_encoding("UTF-8")
end
it "returns a String in the same encoding as self" do

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: false
require_relative '../../spec_helper'
describe "String#bytesplice" do

Просмотреть файл

@ -90,7 +90,7 @@ end
describe "String#capitalize!" do
it "capitalizes self in place" do
a = "hello"
a = +"hello"
a.capitalize!.should equal(a)
a.should == "Hello"
end
@ -103,13 +103,13 @@ describe "String#capitalize!" do
describe "full Unicode case mapping" do
it "modifies self in place for all of Unicode with no option" do
a = "äöÜ"
a = +"äöÜ"
a.capitalize!
a.should == "Äöü"
end
it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do
a = "ß"
a = +"ß"
a.capitalize!
a.should == "Ss"
end
@ -121,7 +121,7 @@ describe "String#capitalize!" do
end
it "updates string metadata" do
capitalized = "ßeT"
capitalized = +"ßeT"
capitalized.capitalize!
capitalized.should == "Sset"
@ -133,7 +133,7 @@ describe "String#capitalize!" do
describe "modifies self in place for ASCII-only case mapping" do
it "does not capitalize non-ASCII characters" do
a = "ßet"
a = +"ßet"
a.capitalize!(:ascii)
a.should == "ßet"
end
@ -147,13 +147,13 @@ describe "String#capitalize!" 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
a = "iSa"
a = +"iSa"
a.capitalize!(:turkic)
a.should == "İsa"
end
it "allows Lithuanian as an extra option" do
a = "iSa"
a = +"iSa"
a.capitalize!(:turkic, :lithuanian)
a.should == "İsa"
end
@ -165,13 +165,13 @@ describe "String#capitalize!" 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
a = ""
a = +""
a.capitalize!(:lithuanian)
a.should == ""
end
it "allows Turkic as an extra option (and applies Turkic semantics)" do
a = ""
a = +""
a.capitalize!(:lithuanian, :turkic)
a.should == "İß"
end
@ -190,12 +190,12 @@ describe "String#capitalize!" do
end
it "returns nil when no changes are made" do
a = "Hello"
a = +"Hello"
a.capitalize!.should == nil
a.should == "Hello"
"".capitalize!.should == nil
"H".capitalize!.should == nil
(+"").capitalize!.should == nil
(+"H").capitalize!.should == nil
end
it "raises a FrozenError when self is frozen" do

Просмотреть файл

@ -92,7 +92,7 @@ describe "String#center with length, padding" do
describe "with width" 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.should == " abc "
result.encoding.should equal(Encoding::IBM437)
@ -101,7 +101,7 @@ describe "String#center with length, padding" do
describe "with width, pattern" 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.should == "あabcああ"
result.encoding.should equal(Encoding::UTF_8)

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: false
require_relative '../../spec_helper'
describe "String#clear" do

Просмотреть файл

@ -11,7 +11,7 @@ describe "String#codepoints" do
end
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.codepoints }.should raise_error(ArgumentError)
end

Просмотреть файл

@ -61,12 +61,12 @@ describe "String#<=> with String" do
end
it "ignores encoding difference" do
("ÄÖÛ".force_encoding("utf-8") <=> "ÄÖÜ".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
("ÄÖÜ".dup.force_encoding("utf-8") <=> "ÄÖÛ".dup.force_encoding("iso-8859-1")).should == 1
end
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
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
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

Просмотреть файл

@ -8,19 +8,19 @@ describe "String#concat" do
it_behaves_like :string_concat_type_coercion, :concat
it "takes multiple arguments" do
str = "hello "
str = +"hello "
str.concat "wo", "", "rld"
str.should == "hello world"
end
it "concatenates the initial value when given arguments contain 2 self" do
str = "hello"
str = +"hello"
str.concat str, str
str.should == "hellohellohello"
end
it "returns self when given no arguments" do
str = "hello"
str = +"hello"
str.concat.should equal(str)
str.should == "hello"
end

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

Просмотреть файл

@ -51,7 +51,7 @@ describe "String#dup" do
end
it "does not modify the original setbyte-mutated string when changing dupped string" do
orig = "a"
orig = +"a"
orig.setbyte 0, "b".ord
copy = orig.dup
orig.setbyte 0, "c".ord

Просмотреть файл

@ -9,26 +9,26 @@ describe "String#each_byte" do
end
it "keeps iterating from the old position (to new string end) when self changes" do
r = ""
s = "hello world"
r = +""
s = +"hello world"
s.each_byte do |c|
r << c
s.insert(0, "<>") if r.size < 3
end
r.should == "h><>hello world"
r = ""
s = "hello world"
r = +""
s = +"hello world"
s.each_byte { |c| s.slice!(-1); r << c }
r.should == "hello "
r = ""
s = "hello world"
r = +""
s = +"hello world"
s.each_byte { |c| s.slice!(0); r << c }
r.should == "hlowrd"
r = ""
s = "hello world"
r = +""
s = +"hello world"
s.each_byte { |c| s.slice!(0..-1); r << c }
r.should == "h"
end

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: false
require_relative '../../spec_helper'
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
x82 = [0x82].pack('C')
str = "#{x82}foo".force_encoding("binary")[1..-1].encode("utf-8")
str.should == "foo".force_encoding("utf-8")
str = "#{x82}foo".dup.force_encoding("binary")[1..-1].encode("utf-8")
str.should == "foo".dup.force_encoding("utf-8")
str.encoding.should equal(Encoding::UTF_8)
end
end
@ -49,7 +49,7 @@ describe "String#encode" do
end
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"
end
end
@ -122,8 +122,7 @@ describe "String#encode" do
describe "when passed to, from" do
it "returns a copy in the destination encoding when both encodings are the same" do
str = ""
str.force_encoding("binary")
str = "".dup.force_encoding("binary")
encoded = str.encode("utf-8", "utf-8")
encoded.should_not equal(str)
@ -155,8 +154,7 @@ describe "String#encode" do
end
it "returns a copy in the destination encoding when both encodings are the same" do
str = ""
str.force_encoding("binary")
str = "".dup.force_encoding("binary")
encoded = str.encode("utf-8", "utf-8", invalid: :replace)
encoded.should_not equal(str)
@ -191,13 +189,13 @@ describe "String#encode!" do
describe "when passed no options" do
it "returns self when Encoding.default_internal is nil" do
Encoding.default_internal = nil
str = ""
str = +""
str.encode!.should equal(str)
end
it "returns self for a ASCII-only String when Encoding.default_internal is nil" do
Encoding.default_internal = nil
str = "abc"
str = +"abc"
str.encode!.should equal(str)
end
end
@ -205,14 +203,14 @@ describe "String#encode!" do
describe "when passed options" do
it "returns self for ASCII-only String when Encoding.default_internal is nil" do
Encoding.default_internal = nil
str = "abc"
str = +"abc"
str.encode!(invalid: :replace).should equal(str)
end
end
describe "when passed to encoding" do
it "returns self" do
str = "abc"
str = +"abc"
result = str.encode!(Encoding::BINARY)
result.encoding.should equal(Encoding::BINARY)
result.should equal(str)
@ -221,7 +219,7 @@ describe "String#encode!" do
describe "when passed to, from" do
it "returns self" do
str = "ああ"
str = +"ああ"
result = str.encode!("euc-jp", "utf-8")
result.encoding.should equal(Encoding::EUC_JP)
result.should equal(str)

Просмотреть файл

@ -14,11 +14,11 @@ describe "String#encoding" do
end
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
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
@ -108,13 +108,13 @@ describe "String#encoding for Strings with \\u escapes" do
end
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{2020}".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}".dup.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
end
it "returns the given encoding if #encode!has been called" do
"\u{20}".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
"\u{2020}".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
"\u{20}".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
"\u{2020}".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
end
end
@ -173,16 +173,12 @@ describe "String#encoding for Strings with \\x escapes" do
end
it "returns the given encoding if #force_encoding has been called" do
x50 = "\x50"
x50.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
xD4 = [212].pack('C')
xD4.force_encoding(Encoding::ISO_8859_9).encoding.should == Encoding::ISO_8859_9
"\x50".dup.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
end
it "returns the given encoding if #encode!has been called" do
x50 = "\x50"
x50.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
x00 = "x\00"
x00.encode!(Encoding::UTF_8).encoding.should == Encoding::UTF_8
"\x50".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
"x\00".dup.encode!(Encoding::UTF_8).encoding.should == Encoding::UTF_8
end
end

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: false
require_relative '../../spec_helper'
describe "String#force_encoding" do

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: false
require_relative '../../spec_helper'
describe "String#freeze" do

Просмотреть файл

@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

Просмотреть файл

@ -15,16 +15,16 @@ describe "String#include? with String" do
it "returns true if both strings are empty" do
"".should.include?("")
"".force_encoding("EUC-JP").should.include?("")
"".should.include?("".force_encoding("EUC-JP"))
"".force_encoding("EUC-JP").should.include?("".force_encoding("EUC-JP"))
"".dup.force_encoding("EUC-JP").should.include?("")
"".should.include?("".dup.force_encoding("EUC-JP"))
"".dup.force_encoding("EUC-JP").should.include?("".dup.force_encoding("EUC-JP"))
end
it "returns true if the RHS is empty" do
"a".should.include?("")
"a".force_encoding("EUC-JP").should.include?("")
"a".should.include?("".force_encoding("EUC-JP"))
"a".force_encoding("EUC-JP").should.include?("".force_encoding("EUC-JP"))
"a".dup.force_encoding("EUC-JP").should.include?("")
"a".should.include?("".dup.force_encoding("EUC-JP"))
"a".dup.force_encoding("EUC-JP").should.include?("".dup.force_encoding("EUC-JP"))
end
it "tries to convert other to string using to_str" do

Просмотреть файл

@ -161,16 +161,16 @@ describe "String#index with String" do
end
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
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
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
str = 'abc'.force_encoding("ISO-2022-JP")
pattern = 'b'.force_encoding("EUC-JP")
str = 'abc'.dup.force_encoding("ISO-2022-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")
end

Просмотреть файл

@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

Просмотреть файл

@ -327,7 +327,7 @@ describe "String#inspect" do
end
it "works for broken US-ASCII strings" do
s = "©".force_encoding("US-ASCII")
s = "©".dup.force_encoding("US-ASCII")
s.inspect.should == '"\xC2\xA9"'
end

Просмотреть файл

@ -75,7 +75,7 @@ describe "String#ljust with length, padding" do
describe "with width" 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.should == "abc "
result.encoding.should equal(Encoding::IBM437)
@ -84,7 +84,7 @@ describe "String#ljust with length, padding" do
describe "with width, pattern" 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.should == "abcああ"
result.encoding.should equal(Encoding::UTF_8)

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
require_relative 'shared/strip'

Просмотреть файл

@ -27,7 +27,7 @@ describe "String#ord" do
end
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")
end
end

Просмотреть файл

@ -40,7 +40,7 @@ describe "String#partition with String" do
end
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("é")
@ -51,7 +51,7 @@ describe "String#partition with String" do
end
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)

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

Просмотреть файл

@ -1,4 +1,5 @@
# encoding: utf-8
# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

Просмотреть файл

@ -197,16 +197,16 @@ describe "String#rindex with String" do
end
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
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
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
str = 'abc'.force_encoding("ISO-2022-JP")
pattern = 'b'.force_encoding("EUC-JP")
str = 'abc'.dup.force_encoding("ISO-2022-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")
end

Просмотреть файл

@ -75,7 +75,7 @@ describe "String#rjust with length, padding" do
describe "with width" 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.should == " abc"
result.encoding.should equal(Encoding::IBM437)
@ -84,7 +84,7 @@ describe "String#rjust with length, padding" do
describe "with width, pattern" 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.should == "ああabc"
result.encoding.should equal(Encoding::UTF_8)

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше