Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1142 but with an extra commit to ease reviewing the diff #1143

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ jobs:
matrix:
os: [ ubuntu, macos, windows ]
ruby: [ 3.0.6, 3.1.4, 3.2.2, 3.3.0 ]
rubyopt: [""]
include:
- os: ubuntu
ruby: 3.3.0
rubyopt: "--enable-frozen-string-literal"

runs-on: ${{ matrix.os }}-latest
steps:
- name: git config autocrlf
Expand All @@ -28,6 +34,7 @@ jobs:
if: matrix.os == 'ubuntu'
env:
CHECK_LEAKS: true
RUBYOPT: "${{ matrix.rubyopt }}"
run: ../mspec/bin/mspec -j --timeout 30

- name: Run specs (macOS)
Expand Down
2 changes: 1 addition & 1 deletion core/argf/readpartial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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
Expand Down
2 changes: 1 addition & 1 deletion core/argf/shared/getc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

it "reads each char of files" do
argf [@file1, @file2] do
chars = ""
chars = +""
@chars.size.times { chars << @argf.send(@method) }
chars.should == @chars
end
Expand Down
4 changes: 2 additions & 2 deletions core/argf/shared/read.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

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
end

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
Expand Down
2 changes: 1 addition & 1 deletion core/array/fill_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

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]
Expand Down
12 changes: 6 additions & 6 deletions core/array/pack/buffer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
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

Expand All @@ -31,19 +31,19 @@
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
Expand Down
6 changes: 3 additions & 3 deletions core/array/shared/inspect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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"]'
Expand Down Expand Up @@ -98,8 +98,8 @@
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
Expand Down
6 changes: 4 additions & 2 deletions core/complex/inspect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

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)
Expand All @@ -26,7 +27,8 @@

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)
Expand Down
3 changes: 2 additions & 1 deletion core/complex/to_s_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@

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)
Expand Down
1 change: 1 addition & 0 deletions core/encoding/converter/convert_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: true
require_relative '../../../spec_helper'

describe "Encoding::Converter#convert" do
Expand Down
14 changes: 7 additions & 7 deletions core/encoding/converter/last_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,39 @@

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".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".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

Expand Down
1 change: 1 addition & 0 deletions core/encoding/converter/primitive_convert_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: false
require_relative '../../../spec_helper'

describe "Encoding::Converter#primitive_convert" do
Expand Down
1 change: 1 addition & 0 deletions core/encoding/converter/primitive_errinfo_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding: binary -*-
# frozen_string_literal: false
require_relative '../../../spec_helper'

describe "Encoding::Converter#primitive_errinfo" do
Expand Down
10 changes: 5 additions & 5 deletions core/encoding/converter/putback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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
Expand Down Expand Up @@ -36,8 +36,8 @@

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")
Expand All @@ -46,8 +46,8 @@

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")
Expand Down
8 changes: 4 additions & 4 deletions core/encoding/converter/replacement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
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
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
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')
Expand All @@ -63,8 +63,8 @@
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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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
Expand All @@ -18,7 +18,7 @@

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
Expand Down
4 changes: 2 additions & 2 deletions core/file/shared/path.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions core/hash/assoc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
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
eregon marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
15 changes: 10 additions & 5 deletions core/hash/compare_by_identity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,21 @@ def o.hash; 123; end
-> { @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
Expand All @@ -109,8 +111,11 @@ def o.hash; 123; end
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
andrykonchin marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion core/hash/element_reference_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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]
Expand Down
Loading
Loading