Skip to content

Commit

Permalink
Adapt spec tests to not use UTF-32BE or UTF-16BE strings with trailin…
Browse files Browse the repository at this point in the history
…g bytes.

PullRequest: truffleruby/4417
  • Loading branch information
djoooooe committed Dec 3, 2024
2 parents 9a64b1e + d6379d1 commit b1fa560
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 302 deletions.
2 changes: 1 addition & 1 deletion doc/user/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ A possible workaround could be to use natively-allocated strings, but it would b

### Strings in UTF-16 and UTF-32 encoding

TruffleRuby does not support UTF-16 strings with an odd number of bytes (in native endianness). Similarly, with UTF-32 it needs to be a multiple of 4. This is necessary for optimizations, compression, invariants, etc.
TruffleRuby does not support UTF-16 strings with an odd number of bytes. Similarly, with UTF-32 it needs to be a multiple of 4. This is necessary for optimizations, compression, invariants, etc.

### Threads detect interrupts at different points

Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/dir/shared/glob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

it "raises an Encoding::CompatibilityError if the argument encoding is not compatible with US-ASCII" do
pattern = "file*".dup.force_encoding Encoding::UTF_16BE
pattern = "files*".dup.force_encoding Encoding::UTF_16BE
-> { Dir.send(@method, pattern) }.should raise_error(Encoding::CompatibilityError)
end

Expand Down
584 changes: 292 additions & 292 deletions spec/ruby/core/encoding/compatible_spec.rb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spec/ruby/core/file/expand_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
platform_is_not :windows do
it "raises an Encoding::CompatibilityError if the external encoding is not compatible" do
Encoding.default_external = Encoding::UTF_16BE
-> { File.expand_path("./a") }.should raise_error(Encoding::CompatibilityError)
-> { File.expand_path("./ab") }.should raise_error(Encoding::CompatibilityError)
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/ruby/core/io/set_encoding_by_bom_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
@io.rewind
@io.set_encoding(Encoding::ASCII_8BIT)

File.binwrite(@name, "\xFE\xFFabc")
File.binwrite(@name, "\xFE\xFFabcd")

@io.set_encoding_by_bom.should == Encoding::UTF_16BE
@io.external_encoding.should == Encoding::UTF_16BE
@io.read.b.should == "abc".b
@io.read.b.should == "abcd".b
end

it "returns the result encoding if found BOM UTF_32LE sequence" do
Expand Down Expand Up @@ -94,11 +94,11 @@
@io.rewind
@io.set_encoding(Encoding::ASCII_8BIT)

File.binwrite(@name, "\x00\x00\xFE\xFFabc")
File.binwrite(@name, "\x00\x00\xFE\xFFabcd")

@io.set_encoding_by_bom.should == Encoding::UTF_32BE
@io.external_encoding.should == Encoding::UTF_32BE
@io.read.b.should == "abc".b
@io.read.b.should == "abcd".b
end

it "returns nil if io is empty" do
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/library/stringio/shared/write.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
end

it "does not transcode the given string when the external encoding is set and the string encoding is BINARY" do
str = "été".b
str = "été_".b
io = StringIO.new.set_encoding(Encoding::UTF_16BE)
io.external_encoding.should == Encoding::UTF_16BE

Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/shared/string/end_with.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
it "checks that we are starting to match at the head of a character" do
"\xC3\xA9".send(@method).should_not.end_with?("\xA9")
"\xe3\x81\x82".send(@method).should_not.end_with?("\x82")
"ab".dup.force_encoding("UTF-16BE").send(@method).should_not.end_with?(
"b".dup.force_encoding("UTF-16BE"))
"\xd8\x00\xdc\x00".dup.force_encoding("UTF-16BE").send(@method).should_not.end_with?(
"\xdc\x00".dup.force_encoding("UTF-16BE"))
end
end
1 change: 1 addition & 0 deletions spec/tags/core/file/expand_path_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ slow:File.expand_path raises an Encoding::CompatibilityError if the external enc
slow:File.expand_path does not modify the string argument
slow:File.expand_path does not modify a HOME string argument
slow:File.expand_path returns a String when passed a String subclass
fails:File.expand_path raises an Encoding::CompatibilityError if the external encoding is not compatible
1 change: 1 addition & 0 deletions spec/tags/optional/capi/encoding_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ fails:C-API Encoding function rb_enc_get_index returns -1 for an object without
fails:C-API Encoding function rb_enc_set_index raises an ArgumentError for a non-encoding capable object
fails:C-API Encoding function ENCODING_SET raises an ArgumentError for a non-encoding capable object
slow:C-API Encoding function rb_define_dummy_encoding raises EncodingError if too many encodings
fails:C-API Encoding function rb_enc_strlen handles broken strings combines valid character and invalid character counts in UTF-16

0 comments on commit b1fa560

Please sign in to comment.