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

Use explicit mutable string literals in Natalie tests #2281

Merged
merged 1 commit into from
Nov 2, 2024
Merged
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
8 changes: 4 additions & 4 deletions test/natalie/encoding_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,8 @@
string.bytes.should == 'a'.encode(Encoding::UTF_16BE).bytes
end

"\xD8\x00\xDC\x00\x00\xFF".force_encoding(Encoding::UTF_16BE).chop!.bytes.should == [216, 0, 220, 0]
"\xD8\x00\xDC\x00\xFF".force_encoding(Encoding::UTF_16BE).chop!.bytes.should == [216, 0, 220, 0]
(+"\xD8\x00\xDC\x00\x00\xFF").force_encoding(Encoding::UTF_16BE).chop!.bytes.should == [216, 0, 220, 0]
(+"\xD8\x00\xDC\x00\xFF").force_encoding(Encoding::UTF_16BE).chop!.bytes.should == [216, 0, 220, 0]
end
end

Expand Down Expand Up @@ -923,8 +923,8 @@
string.bytes.should == 'a'.encode(Encoding::UTF_16LE).bytes
end

"\x00\xD8\x00\xDC\xFF\x00".force_encoding(Encoding::UTF_16LE).chop!.bytes.should == [0, 216, 0, 220]
"\x00\xD8\x00\xDC\xFF".force_encoding(Encoding::UTF_16LE).chop!.bytes.should == [0, 216, 0, 220]
(+"\x00\xD8\x00\xDC\xFF\x00").force_encoding(Encoding::UTF_16LE).chop!.bytes.should == [0, 216, 0, 220]
(+"\x00\xD8\x00\xDC\xFF").force_encoding(Encoding::UTF_16LE).chop!.bytes.should == [0, 216, 0, 220]
end
end

Expand Down
48 changes: 24 additions & 24 deletions test/natalie/string_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

describe '#[]=' do
it 'works well with [start, end] calls where start > 0' do
string = '123456789012'
string = +'123456789012'
string[10, 5] = 'abcde'
string.should == '1234567890abcde'
end
Expand Down Expand Up @@ -176,7 +176,7 @@
end

it 'does not raise an error when encoding binary to binary' do
"\xFF".force_encoding('ASCII-8BIT').encode('ASCII-8BIT').should == "\xFF".force_encoding("ASCII-8BIT")
(+"\xFF").force_encoding('ASCII-8BIT').encode('ASCII-8BIT').should == (+"\xFF").force_encoding("ASCII-8BIT")
end

context "UTF-16BE" do
Expand Down Expand Up @@ -335,7 +335,7 @@

describe '#[]=' do
it 'returns passed string' do
("abc"[1] = "x").should == "x"
((+"abc")[1] = "x").should == "x"
end
end

Expand Down Expand Up @@ -582,7 +582,7 @@

describe '#chomp!' do
it 'does not read out of bounds' do
"\n".chomp!.should == ''
(+"\n").chomp!.should == ''
end
end

Expand Down Expand Up @@ -610,11 +610,11 @@
s.chop!
s.should == ''.encode('UTF-32LE')

s = "\x00\x00\x00".force_encoding('UTF-32LE') # incorrect binary representation - it should take 4 bytes, not 3
s = (+"\x00\x00\x00").force_encoding('UTF-32LE') # incorrect binary representation - it should take 4 bytes, not 3
s.chop!
s.should == "".encode('UTF-32LE')

s = "\x00\x00\x00\x00\x00\xD8\x00\x00".force_encoding('UTF-32LE') # incorrect codepoint 0xD800 - it isn't supported
s = (+"\x00\x00\x00\x00\x00\xD8\x00\x00").force_encoding('UTF-32LE') # incorrect codepoint 0xD800 - it isn't supported
s.chop!
s.should == "\u0000".encode('UTF-32LE')
end
Expand All @@ -631,11 +631,11 @@
s.chop!
s.should == ''.encode('UTF-32BE')

s = "\x00\x00\x00".force_encoding('UTF-32BE') # incorrect binary representation - it should take 4 bytes, not 3
s = (+"\x00\x00\x00").force_encoding('UTF-32BE') # incorrect binary representation - it should take 4 bytes, not 3
s.chop!
s.should == "".encode('UTF-32BE')

s = "\x00\x00\x00\x00\x00\x00\xD8\x00".force_encoding('UTF-32BE') # incorrect codepoint 0xD800 - it isn't supported
s = (+"\x00\x00\x00\x00\x00\x00\xD8\x00").force_encoding('UTF-32BE') # incorrect codepoint 0xD800 - it isn't supported
s.chop!
s.should == "\u0000".encode('UTF-32BE')
end
Expand All @@ -661,23 +661,23 @@
s.should == 'foo'.encode('UTF-16LE')

# FIXME
# s = 'foo'.encode('UTF-16LE') + "\xFF".force_encoding('UTF-16LE') # incorrect 1-byte sequence
# s = 'foo'.encode('UTF-16LE') + (+"\xFF").force_encoding('UTF-16LE') # incorrect 1-byte sequence
# s.chop!
# s.bytes.should == 'foo'.encode('UTF-16LE').bytes

# FIXME
# s = 'foo'.encode('UTF-16LE') + "\x00\xD8\x00".force_encoding('UTF-16LE') # incorrect 3-byte sequence
# s = 'foo'.encode('UTF-16LE') + (+"\x00\xD8\x00").force_encoding('UTF-16LE') # incorrect 3-byte sequence
# s.chop!
# s.should == 'foo'.encode('UTF-16LE') + "\x00\xD8".force_encoding('UTF-16LE')
# s.should == 'foo'.encode('UTF-16LE') + (+"\x00\xD8").force_encoding('UTF-16LE')

# incorrect sequence: the second code unit - DC00-1 - within D800-DFFF
s = 'foo'.encode('UTF-16LE') + "\x00\xD8\xFF\xDB".force_encoding('UTF-16LE')
s = 'foo'.encode('UTF-16LE') + (+"\x00\xD8\xFF\xDB").force_encoding('UTF-16LE')
s.chop!
s.should == 'foo'.encode('UTF-16LE') + "\x00\xD8".force_encoding('UTF-16LE')
s.should == 'foo'.encode('UTF-16LE') + (+"\x00\xD8").force_encoding('UTF-16LE')

# FIXME
# incorrect sequence: the first code unit - DBFF+1 - within D800-DFFF
# s = 'foo'.encode('UTF-16LE') + "\x00\xDC\x00\xDC".force_encoding('UTF-16LE')
# s = 'foo'.encode('UTF-16LE') + (+"\x00\xDC\x00\xDC").force_encoding('UTF-16LE')
# s.chop!
# s.should == 'foo'.encode('UTF-16LE')
end
Expand Down Expand Up @@ -790,35 +790,35 @@ def initialize(s)
# Test EucJpEncoding::prev_char method
it "chops the last char of an empty string" do
# empty string case
s = ''.force_encoding('EUCJP')
s = (+'').force_encoding('EUCJP')
s.chop!
s.should == ''.force_encoding('EUCJP')
s.should == (+'').force_encoding('EUCJP')
end

it "chops the last char of a string with single-byte final char" do
# single-byte char
s = "foo\x77".force_encoding('EUCJP')
s = (+"foo\x77").force_encoding('EUCJP')
s.chop!
s.should == 'foo'.force_encoding('EUCJP')
s.should == (+'foo').force_encoding('EUCJP')
end

it "chops the last char of a string with two-byte final char" do
# two-byte char removal
s = "foo\xA1\xA1".force_encoding('EUCJP')
s = (+"foo\xA1\xA1").force_encoding('EUCJP')
s.chop!
s.should == 'foo'.force_encoding('EUCJP')
s.should == (+'foo').force_encoding('EUCJP')

# two-byte char removal (8E lead)
s = "foo\x8E\xA1".force_encoding('EUCJP')
s = (+"foo\x8E\xA1").force_encoding('EUCJP')
s.chop!
s.should == 'foo'.force_encoding('EUCJP')
s.should == (+'foo').force_encoding('EUCJP')
end

it "chops the last char of a string with three-byte final char" do
# three-byte char removal (8E lead)
s = "foo\x8F\xA1\xA2".force_encoding('EUCJP')
s = (+"foo\x8F\xA1\xA2").force_encoding('EUCJP')
s.chop!
s.should == 'foo'.force_encoding('EUCJP')
s.should == (+'foo').force_encoding('EUCJP')
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/support/spec_helpers/tmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
end
SPEC_TEMP_DIR = spec_temp_dir

SPEC_TEMP_UNIQUIFIER = "0"
SPEC_TEMP_UNIQUIFIER = +"0"

at_exit do
begin
Expand Down
Loading