Skip to content

Commit

Permalink
test: update wpt/encoding to 7287608f90
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
joyeecheung authored and danbev committed May 28, 2019
1 parent 6abeaac commit 4ccc359
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 22 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See [test/wpt](../../wpt/README.md) for information on how these tests are run.
Last update:

- console: https://github.com/web-platform-tests/wpt/tree/9786a4b131/console
- encoding: https://github.com/web-platform-tests/wpt/tree/a093a659ed/encoding
- encoding: https://github.com/web-platform-tests/wpt/tree/7287608f90/encoding
- url: https://github.com/web-platform-tests/wpt/tree/418f7fabeb/url
- resources: https://github.com/web-platform-tests/wpt/tree/e1fddfbf80/resources
- interfaces: https://github.com/web-platform-tests/wpt/tree/712c9f275e/interfaces
Expand Down
149 changes: 149 additions & 0 deletions test/fixtures/wpt/encoding/encodeInto.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
[
{
"input": "Hi",
"read": 0,
"destinationLength": 0,
"written": []
},
{
"input": "A",
"read": 1,
"destinationLength": 10,
"written": [0x41]
},
{
"input": "\u{1D306}", // "\uD834\uDF06"
"read": 2,
"destinationLength": 4,
"written": [0xF0, 0x9D, 0x8C, 0x86]
},
{
"input": "\u{1D306}A",
"read": 0,
"destinationLength": 3,
"written": []
},
{
"input": "\uD834A\uDF06A¥Hi",
"read": 5,
"destinationLength": 10,
"written": [0xEF, 0xBF, 0xBD, 0x41, 0xEF, 0xBF, 0xBD, 0x41, 0xC2, 0xA5]
},
{
"input": "A\uDF06",
"read": 2,
"destinationLength": 4,
"written": [0x41, 0xEF, 0xBF, 0xBD]
},
{
"input": "¥¥",
"read": 2,
"destinationLength": 4,
"written": [0xC2, 0xA5, 0xC2, 0xA5]
}
].forEach(testData => {
[
{
"bufferIncrease": 0,
"destinationOffset": 0,
"filler": 0
},
{
"bufferIncrease": 10,
"destinationOffset": 4,
"filler": 0
},
{
"bufferIncrease": 0,
"destinationOffset": 0,
"filler": 0x80
},
{
"bufferIncrease": 10,
"destinationOffset": 4,
"filler": 0x80
},
{
"bufferIncrease": 0,
"destinationOffset": 0,
"filler": "random"
},
{
"bufferIncrease": 10,
"destinationOffset": 4,
"filler": "random"
}
].forEach(destinationData => {
test(() => {
// Setup
const bufferLength = testData.destinationLength + destinationData.bufferIncrease,
destinationOffset = destinationData.destinationOffset,
destinationLength = testData.destinationLength,
destinationFiller = destinationData.filler,
encoder = new TextEncoder(),
buffer = new ArrayBuffer(bufferLength),
view = new Uint8Array(buffer, destinationOffset, destinationLength),
fullView = new Uint8Array(buffer),
control = new Array(bufferLength);
let byte = destinationFiller;
for (let i = 0; i < bufferLength; i++) {
if (destinationFiller === "random") {
byte = Math.floor(Math.random() * 256);
}
control[i] = byte;
fullView[i] = byte;
}

// It's happening
const result = encoder.encodeInto(testData.input, view);

// Basics
assert_equals(view.byteLength, destinationLength);
assert_equals(view.length, destinationLength);

// Remainder
assert_equals(result.read, testData.read);
assert_equals(result.written, testData.written.length);
for (let i = 0; i < bufferLength; i++) {
if (i < destinationOffset || i >= (destinationOffset + testData.written.length)) {
assert_equals(fullView[i], control[i]);
} else {
assert_equals(fullView[i], testData.written[i - destinationOffset]);
}
}
}, "encodeInto() with " + testData.input + " and destination length " + testData.destinationLength + ", offset " + destinationData.destinationOffset + ", filler " + destinationData.filler);
});
});

[DataView,
Int8Array,
Int16Array,
Int32Array,
Uint16Array,
Uint32Array,
Uint8ClampedArray,
Float32Array,
Float64Array].forEach(view => {
test(() => {
assert_throws(new TypeError(), () => new TextEncoder().encodeInto("", new view(new ArrayBuffer(0))));
}, "Invalid encodeInto() destination: " + view);
});

test(() => {
assert_throws(new TypeError(), () => new TextEncoder().encodeInto("", new ArrayBuffer(10)));
}, "Invalid encodeInto() destination: ArrayBuffer");

test(() => {
const buffer = new ArrayBuffer(10),
view = new Uint8Array(buffer);
let { read, written } = new TextEncoder().encodeInto("", view);
assert_equals(read, 0);
assert_equals(written, 0);
new MessageChannel().port1.postMessage(buffer, [buffer]);
({ read, written } = new TextEncoder().encodeInto("", view));
assert_equals(read, 0);
assert_equals(written, 0);
({ read, written } = new TextEncoder().encodeInto("test", view));
assert_equals(read, 0);
assert_equals(written, 0);
}, "encodeInto() and a detached output buffer");
20 changes: 0 additions & 20 deletions test/fixtures/wpt/encoding/streams/decode-bad-chunks.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@ const badChunks = [
name: 'array',
value: [65]
},
{
name: 'detached ArrayBufferView',
value: (() => {
const u8 = new Uint8Array([65]);
const ab = u8.buffer;
const mc = new MessageChannel();
mc.port1.postMessage(ab, [ab]);
return u8;
})()
},
{
name: 'detached ArrayBuffer',
value: (() => {
const u8 = new Uint8Array([65]);
const ab = u8.buffer;
const mc = new MessageChannel();
mc.port1.postMessage(ab, [ab]);
return ab;
})()
},
{
name: 'SharedArrayBuffer',
// Use a getter to postpone construction so that all tests don't fail where
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/wpt/encoding/streams/decode-utf8.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,23 @@ promise_test(async () => {
assert_array_equals(array, [expectedOutputString],
'the output should be in one chunk');
}, 'a trailing empty chunk should be ignored');

promise_test(async () => {
const buffer = new ArrayBuffer(3);
const view = new Uint8Array(buffer, 1, 1);
view[0] = 65;
new MessageChannel().port1.postMessage(buffer, [buffer]);
const input = readableStreamFromArray([view]);
const output = input.pipeThrough(new TextDecoderStream());
const array = await readableStreamToArray(output);
assert_array_equals(array, [], 'no chunks should be output');
}, 'decoding a transferred Uint8Array chunk should give no output');

promise_test(async () => {
const buffer = new ArrayBuffer(1);
new MessageChannel().port1.postMessage(buffer, [buffer]);
const input = readableStreamFromArray([buffer]);
const output = input.pipeThrough(new TextDecoderStream());
const array = await readableStreamToArray(output);
assert_array_equals(array, [], 'no chunks should be output');
}, 'decoding a transferred ArrayBuffer chunk should give no output');
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// META: timeout=long
// META: title=Encoding API: Fatal flag for single byte encodings
// META: timeout=long

var singleByteEncodings = [
{encoding: 'IBM866', bad: []},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"path": "console"
},
"encoding": {
"commit": "a093a659ed118112138f8a1ffba97a66c1ea8235",
"commit": "7287608f90f6b9530635d10086fd2ab386faab38",
"path": "encoding"
},
"url": {
Expand Down

0 comments on commit 4ccc359

Please sign in to comment.