Skip to content

Commit 8fc6914

Browse files
joyeecheungtargos
authored andcommitted
test: update wpt/encoding to 7287608f90
Using `git node wpt encoding` PR-URL: #27860 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 0f86c2b commit 8fc6914

File tree

6 files changed

+173
-22
lines changed

6 files changed

+173
-22
lines changed

test/fixtures/wpt/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ See [test/wpt](../../wpt/README.md) for information on how these tests are run.
1111
Last update:
1212

1313
- console: https://github.com/web-platform-tests/wpt/tree/9786a4b131/console
14-
- encoding: https://github.com/web-platform-tests/wpt/tree/a093a659ed/encoding
14+
- encoding: https://github.com/web-platform-tests/wpt/tree/7287608f90/encoding
1515
- url: https://github.com/web-platform-tests/wpt/tree/418f7fabeb/url
1616
- resources: https://github.com/web-platform-tests/wpt/tree/e1fddfbf80/resources
1717
- interfaces: https://github.com/web-platform-tests/wpt/tree/712c9f275e/interfaces
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
[
2+
{
3+
"input": "Hi",
4+
"read": 0,
5+
"destinationLength": 0,
6+
"written": []
7+
},
8+
{
9+
"input": "A",
10+
"read": 1,
11+
"destinationLength": 10,
12+
"written": [0x41]
13+
},
14+
{
15+
"input": "\u{1D306}", // "\uD834\uDF06"
16+
"read": 2,
17+
"destinationLength": 4,
18+
"written": [0xF0, 0x9D, 0x8C, 0x86]
19+
},
20+
{
21+
"input": "\u{1D306}A",
22+
"read": 0,
23+
"destinationLength": 3,
24+
"written": []
25+
},
26+
{
27+
"input": "\uD834A\uDF06A¥Hi",
28+
"read": 5,
29+
"destinationLength": 10,
30+
"written": [0xEF, 0xBF, 0xBD, 0x41, 0xEF, 0xBF, 0xBD, 0x41, 0xC2, 0xA5]
31+
},
32+
{
33+
"input": "A\uDF06",
34+
"read": 2,
35+
"destinationLength": 4,
36+
"written": [0x41, 0xEF, 0xBF, 0xBD]
37+
},
38+
{
39+
"input": "¥¥",
40+
"read": 2,
41+
"destinationLength": 4,
42+
"written": [0xC2, 0xA5, 0xC2, 0xA5]
43+
}
44+
].forEach(testData => {
45+
[
46+
{
47+
"bufferIncrease": 0,
48+
"destinationOffset": 0,
49+
"filler": 0
50+
},
51+
{
52+
"bufferIncrease": 10,
53+
"destinationOffset": 4,
54+
"filler": 0
55+
},
56+
{
57+
"bufferIncrease": 0,
58+
"destinationOffset": 0,
59+
"filler": 0x80
60+
},
61+
{
62+
"bufferIncrease": 10,
63+
"destinationOffset": 4,
64+
"filler": 0x80
65+
},
66+
{
67+
"bufferIncrease": 0,
68+
"destinationOffset": 0,
69+
"filler": "random"
70+
},
71+
{
72+
"bufferIncrease": 10,
73+
"destinationOffset": 4,
74+
"filler": "random"
75+
}
76+
].forEach(destinationData => {
77+
test(() => {
78+
// Setup
79+
const bufferLength = testData.destinationLength + destinationData.bufferIncrease,
80+
destinationOffset = destinationData.destinationOffset,
81+
destinationLength = testData.destinationLength,
82+
destinationFiller = destinationData.filler,
83+
encoder = new TextEncoder(),
84+
buffer = new ArrayBuffer(bufferLength),
85+
view = new Uint8Array(buffer, destinationOffset, destinationLength),
86+
fullView = new Uint8Array(buffer),
87+
control = new Array(bufferLength);
88+
let byte = destinationFiller;
89+
for (let i = 0; i < bufferLength; i++) {
90+
if (destinationFiller === "random") {
91+
byte = Math.floor(Math.random() * 256);
92+
}
93+
control[i] = byte;
94+
fullView[i] = byte;
95+
}
96+
97+
// It's happening
98+
const result = encoder.encodeInto(testData.input, view);
99+
100+
// Basics
101+
assert_equals(view.byteLength, destinationLength);
102+
assert_equals(view.length, destinationLength);
103+
104+
// Remainder
105+
assert_equals(result.read, testData.read);
106+
assert_equals(result.written, testData.written.length);
107+
for (let i = 0; i < bufferLength; i++) {
108+
if (i < destinationOffset || i >= (destinationOffset + testData.written.length)) {
109+
assert_equals(fullView[i], control[i]);
110+
} else {
111+
assert_equals(fullView[i], testData.written[i - destinationOffset]);
112+
}
113+
}
114+
}, "encodeInto() with " + testData.input + " and destination length " + testData.destinationLength + ", offset " + destinationData.destinationOffset + ", filler " + destinationData.filler);
115+
});
116+
});
117+
118+
[DataView,
119+
Int8Array,
120+
Int16Array,
121+
Int32Array,
122+
Uint16Array,
123+
Uint32Array,
124+
Uint8ClampedArray,
125+
Float32Array,
126+
Float64Array].forEach(view => {
127+
test(() => {
128+
assert_throws(new TypeError(), () => new TextEncoder().encodeInto("", new view(new ArrayBuffer(0))));
129+
}, "Invalid encodeInto() destination: " + view);
130+
});
131+
132+
test(() => {
133+
assert_throws(new TypeError(), () => new TextEncoder().encodeInto("", new ArrayBuffer(10)));
134+
}, "Invalid encodeInto() destination: ArrayBuffer");
135+
136+
test(() => {
137+
const buffer = new ArrayBuffer(10),
138+
view = new Uint8Array(buffer);
139+
let { read, written } = new TextEncoder().encodeInto("", view);
140+
assert_equals(read, 0);
141+
assert_equals(written, 0);
142+
new MessageChannel().port1.postMessage(buffer, [buffer]);
143+
({ read, written } = new TextEncoder().encodeInto("", view));
144+
assert_equals(read, 0);
145+
assert_equals(written, 0);
146+
({ read, written } = new TextEncoder().encodeInto("test", view));
147+
assert_equals(read, 0);
148+
assert_equals(written, 0);
149+
}, "encodeInto() and a detached output buffer");

test/fixtures/wpt/encoding/streams/decode-bad-chunks.any.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,6 @@ const badChunks = [
2323
name: 'array',
2424
value: [65]
2525
},
26-
{
27-
name: 'detached ArrayBufferView',
28-
value: (() => {
29-
const u8 = new Uint8Array([65]);
30-
const ab = u8.buffer;
31-
const mc = new MessageChannel();
32-
mc.port1.postMessage(ab, [ab]);
33-
return u8;
34-
})()
35-
},
36-
{
37-
name: 'detached ArrayBuffer',
38-
value: (() => {
39-
const u8 = new Uint8Array([65]);
40-
const ab = u8.buffer;
41-
const mc = new MessageChannel();
42-
mc.port1.postMessage(ab, [ab]);
43-
return ab;
44-
})()
45-
},
4626
{
4727
name: 'SharedArrayBuffer',
4828
// Use a getter to postpone construction so that all tests don't fail where

test/fixtures/wpt/encoding/streams/decode-utf8.any.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,23 @@ promise_test(async () => {
3939
assert_array_equals(array, [expectedOutputString],
4040
'the output should be in one chunk');
4141
}, 'a trailing empty chunk should be ignored');
42+
43+
promise_test(async () => {
44+
const buffer = new ArrayBuffer(3);
45+
const view = new Uint8Array(buffer, 1, 1);
46+
view[0] = 65;
47+
new MessageChannel().port1.postMessage(buffer, [buffer]);
48+
const input = readableStreamFromArray([view]);
49+
const output = input.pipeThrough(new TextDecoderStream());
50+
const array = await readableStreamToArray(output);
51+
assert_array_equals(array, [], 'no chunks should be output');
52+
}, 'decoding a transferred Uint8Array chunk should give no output');
53+
54+
promise_test(async () => {
55+
const buffer = new ArrayBuffer(1);
56+
new MessageChannel().port1.postMessage(buffer, [buffer]);
57+
const input = readableStreamFromArray([buffer]);
58+
const output = input.pipeThrough(new TextDecoderStream());
59+
const array = await readableStreamToArray(output);
60+
assert_array_equals(array, [], 'no chunks should be output');
61+
}, 'decoding a transferred ArrayBuffer chunk should give no output');

test/fixtures/wpt/encoding/textdecoder-fatal-single-byte.any.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// META: timeout=long
12
// META: title=Encoding API: Fatal flag for single byte encodings
3+
// META: timeout=long
24

35
var singleByteEncodings = [
46
{encoding: 'IBM866', bad: []},

test/fixtures/wpt/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"path": "console"
55
},
66
"encoding": {
7-
"commit": "a093a659ed118112138f8a1ffba97a66c1ea8235",
7+
"commit": "7287608f90f6b9530635d10086fd2ab386faab38",
88
"path": "encoding"
99
},
1010
"url": {

0 commit comments

Comments
 (0)