Skip to content

Commit b1fa560

Browse files
committed
Adapt spec tests to not use UTF-32BE or UTF-16BE strings with trailing bytes.
PullRequest: truffleruby/4417
2 parents 9a64b1e + d6379d1 commit b1fa560

File tree

9 files changed

+304
-302
lines changed

9 files changed

+304
-302
lines changed

doc/user/compatibility.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ A possible workaround could be to use natively-allocated strings, but it would b
123123

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

126-
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.
126+
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.
127127

128128
### Threads detect interrupts at different points
129129

spec/ruby/core/dir/shared/glob.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
end
1313

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

spec/ruby/core/encoding/compatible_spec.rb

Lines changed: 292 additions & 292 deletions
Large diffs are not rendered by default.

spec/ruby/core/file/expand_path_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
platform_is_not :windows do
160160
it "raises an Encoding::CompatibilityError if the external encoding is not compatible" do
161161
Encoding.default_external = Encoding::UTF_16BE
162-
-> { File.expand_path("./a") }.should raise_error(Encoding::CompatibilityError)
162+
-> { File.expand_path("./ab") }.should raise_error(Encoding::CompatibilityError)
163163
end
164164
end
165165

spec/ruby/core/io/set_encoding_by_bom_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@
6262
@io.rewind
6363
@io.set_encoding(Encoding::ASCII_8BIT)
6464

65-
File.binwrite(@name, "\xFE\xFFabc")
65+
File.binwrite(@name, "\xFE\xFFabcd")
6666

6767
@io.set_encoding_by_bom.should == Encoding::UTF_16BE
6868
@io.external_encoding.should == Encoding::UTF_16BE
69-
@io.read.b.should == "abc".b
69+
@io.read.b.should == "abcd".b
7070
end
7171

7272
it "returns the result encoding if found BOM UTF_32LE sequence" do
@@ -94,11 +94,11 @@
9494
@io.rewind
9595
@io.set_encoding(Encoding::ASCII_8BIT)
9696

97-
File.binwrite(@name, "\x00\x00\xFE\xFFabc")
97+
File.binwrite(@name, "\x00\x00\xFE\xFFabcd")
9898

9999
@io.set_encoding_by_bom.should == Encoding::UTF_32BE
100100
@io.external_encoding.should == Encoding::UTF_32BE
101-
@io.read.b.should == "abc".b
101+
@io.read.b.should == "abcd".b
102102
end
103103

104104
it "returns nil if io is empty" do

spec/ruby/library/stringio/shared/write.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
end
9595

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

spec/ruby/shared/string/end_with.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
it "checks that we are starting to match at the head of a character" do
5656
"\xC3\xA9".send(@method).should_not.end_with?("\xA9")
5757
"\xe3\x81\x82".send(@method).should_not.end_with?("\x82")
58-
"ab".dup.force_encoding("UTF-16BE").send(@method).should_not.end_with?(
59-
"b".dup.force_encoding("UTF-16BE"))
58+
"\xd8\x00\xdc\x00".dup.force_encoding("UTF-16BE").send(@method).should_not.end_with?(
59+
"\xdc\x00".dup.force_encoding("UTF-16BE"))
6060
end
6161
end

spec/tags/core/file/expand_path_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ slow:File.expand_path raises an Encoding::CompatibilityError if the external enc
1919
slow:File.expand_path does not modify the string argument
2020
slow:File.expand_path does not modify a HOME string argument
2121
slow:File.expand_path returns a String when passed a String subclass
22+
fails:File.expand_path raises an Encoding::CompatibilityError if the external encoding is not compatible

spec/tags/optional/capi/encoding_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ fails:C-API Encoding function rb_enc_get_index returns -1 for an object without
66
fails:C-API Encoding function rb_enc_set_index raises an ArgumentError for a non-encoding capable object
77
fails:C-API Encoding function ENCODING_SET raises an ArgumentError for a non-encoding capable object
88
slow:C-API Encoding function rb_define_dummy_encoding raises EncodingError if too many encodings
9+
fails:C-API Encoding function rb_enc_strlen handles broken strings combines valid character and invalid character counts in UTF-16

0 commit comments

Comments
 (0)