зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1586437 [wpt PR 19531] - TextEncoder/TextDecoder SharedArrayBuffer tests, a=testonly
Automatic update from web-platform-tests Encoding: TextEncoder/TextDecoder SharedArrayBuffer tests For https://github.com/whatwg/encoding/pull/182. -- wpt-commits: a910ad1791d138e10558c3ab0db1a29c6a8c5058 wpt-pr: 19531
This commit is contained in:
Родитель
61ea79880c
Коммит
201ff7aa2c
|
@ -74,44 +74,46 @@
|
|||
"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);
|
||||
["ArrayBuffer", "SharedArrayBuffer"].forEach(arrayBufferOrSharedArrayBuffer => {
|
||||
test(() => {
|
||||
// Setup
|
||||
const bufferLength = testData.destinationLength + destinationData.bufferIncrease,
|
||||
destinationOffset = destinationData.destinationOffset,
|
||||
destinationLength = testData.destinationLength,
|
||||
destinationFiller = destinationData.filler,
|
||||
encoder = new TextEncoder(),
|
||||
buffer = new self[arrayBufferOrSharedArrayBuffer](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;
|
||||
}
|
||||
control[i] = byte;
|
||||
fullView[i] = byte;
|
||||
}
|
||||
|
||||
// It's happening
|
||||
const result = encoder.encodeInto(testData.input, view);
|
||||
// It's happening
|
||||
const result = encoder.encodeInto(testData.input, view);
|
||||
|
||||
// Basics
|
||||
assert_equals(view.byteLength, destinationLength);
|
||||
assert_equals(view.length, destinationLength);
|
||||
// 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]);
|
||||
// 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);
|
||||
}, "encodeInto() into " + arrayBufferOrSharedArrayBuffer + " with " + testData.input + " and destination length " + testData.destinationLength + ", offset " + destinationData.destinationOffset + ", filler " + destinationData.filler);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -124,14 +126,20 @@
|
|||
Uint8ClampedArray,
|
||||
Float32Array,
|
||||
Float64Array].forEach(view => {
|
||||
test(() => {
|
||||
assert_throws(new TypeError(), () => new TextEncoder().encodeInto("", new view(new ArrayBuffer(0))));
|
||||
}, "Invalid encodeInto() destination: " + view.name);
|
||||
});
|
||||
["ArrayBuffer", "SharedArrayBuffer"].forEach((arrayBufferOrSharedArrayBuffer) => {
|
||||
test(() => {
|
||||
assert_throws(new TypeError(), () => new TextEncoder().encodeInto("", new view(new self[arrayBufferOrSharedArrayBuffer](0))));
|
||||
}, "Invalid encodeInto() destination: " + view.name + ", backed by: " + arrayBufferOrSharedArrayBuffer);
|
||||
});
|
||||
});
|
||||
|
||||
["ArrayBuffer", "SharedArrayBuffer"].forEach((arrayBufferOrSharedArrayBuffer) => {
|
||||
test(() => {
|
||||
assert_throws(new TypeError(), () => new TextEncoder().encodeInto("", new self[arrayBufferOrSharedArrayBuffer](10)));
|
||||
}, "Invalid encodeInto() destination: " + arrayBufferOrSharedArrayBuffer);
|
||||
});
|
||||
|
||||
|
||||
test(() => {
|
||||
assert_throws(new TypeError(), () => new TextEncoder().encodeInto("", new ArrayBuffer(10)));
|
||||
}, "Invalid encodeInto() destination: ArrayBuffer");
|
||||
|
||||
test(() => {
|
||||
const buffer = new ArrayBuffer(10),
|
||||
|
|
|
@ -22,20 +22,6 @@ const badChunks = [
|
|||
{
|
||||
name: 'array',
|
||||
value: [65]
|
||||
},
|
||||
{
|
||||
name: 'SharedArrayBuffer',
|
||||
// Use a getter to postpone construction so that all tests don't fail where
|
||||
// SharedArrayBuffer is not yet implemented.
|
||||
get value() {
|
||||
return new SharedArrayBuffer();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'shared Uint8Array',
|
||||
get value() {
|
||||
new Uint8Array(new SharedArrayBuffer())
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
|
|
|
@ -4,41 +4,48 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const emptyChunk = new Uint8Array([]);
|
||||
const inputChunk = new Uint8Array([73, 32, 240, 159, 146, 153, 32, 115, 116,
|
||||
114, 101, 97, 109, 115]);
|
||||
const expectedOutputString = 'I \u{1F499} streams';
|
||||
["ArrayBuffer", "SharedArrayBuffer"].forEach((arrayBufferOrSharedArrayBuffer) => {
|
||||
const inputChunkData = [73, 32, 240, 159, 146, 153, 32, 115, 116,
|
||||
114, 101, 97, 109, 115]
|
||||
|
||||
promise_test(async () => {
|
||||
const input = readableStreamFromArray([inputChunk]);
|
||||
const output = input.pipeThrough(new TextDecoderStream());
|
||||
const array = await readableStreamToArray(output);
|
||||
assert_array_equals(array, [expectedOutputString],
|
||||
'the output should be in one chunk');
|
||||
}, 'decoding one UTF-8 chunk should give one output string');
|
||||
const emptyChunk = new Uint8Array(new self[arrayBufferOrSharedArrayBuffer](0));
|
||||
const inputChunk = new Uint8Array(new self[arrayBufferOrSharedArrayBuffer](inputChunkData.length));
|
||||
|
||||
promise_test(async () => {
|
||||
const input = readableStreamFromArray([emptyChunk]);
|
||||
const output = input.pipeThrough(new TextDecoderStream());
|
||||
const array = await readableStreamToArray(output);
|
||||
assert_array_equals(array, [], 'no chunks should be output');
|
||||
}, 'decoding an empty chunk should give no output chunks');
|
||||
inputChunk.set(inputChunkData);
|
||||
|
||||
promise_test(async () => {
|
||||
const input = readableStreamFromArray([emptyChunk, inputChunk]);
|
||||
const output = input.pipeThrough(new TextDecoderStream());
|
||||
const array = await readableStreamToArray(output);
|
||||
assert_array_equals(array, [expectedOutputString],
|
||||
'the output should be in one chunk');
|
||||
}, 'an initial empty chunk should be ignored');
|
||||
const expectedOutputString = 'I \u{1F499} streams';
|
||||
|
||||
promise_test(async () => {
|
||||
const input = readableStreamFromArray([inputChunk, emptyChunk]);
|
||||
const output = input.pipeThrough(new TextDecoderStream());
|
||||
const array = await readableStreamToArray(output);
|
||||
assert_array_equals(array, [expectedOutputString],
|
||||
'the output should be in one chunk');
|
||||
}, 'a trailing empty chunk should be ignored');
|
||||
promise_test(async () => {
|
||||
const input = readableStreamFromArray([inputChunk]);
|
||||
const output = input.pipeThrough(new TextDecoderStream());
|
||||
const array = await readableStreamToArray(output);
|
||||
assert_array_equals(array, [expectedOutputString],
|
||||
'the output should be in one chunk');
|
||||
}, 'decoding one UTF-8 chunk should give one output string - ' + arrayBufferOrSharedArrayBuffer);
|
||||
|
||||
promise_test(async () => {
|
||||
const input = readableStreamFromArray([emptyChunk]);
|
||||
const output = input.pipeThrough(new TextDecoderStream());
|
||||
const array = await readableStreamToArray(output);
|
||||
assert_array_equals(array, [], 'no chunks should be output');
|
||||
}, 'decoding an empty chunk should give no output chunks - ' + arrayBufferOrSharedArrayBuffer);
|
||||
|
||||
promise_test(async () => {
|
||||
const input = readableStreamFromArray([emptyChunk, inputChunk]);
|
||||
const output = input.pipeThrough(new TextDecoderStream());
|
||||
const array = await readableStreamToArray(output);
|
||||
assert_array_equals(array, [expectedOutputString],
|
||||
'the output should be in one chunk');
|
||||
}, 'an initial empty chunk should be ignored - ' + arrayBufferOrSharedArrayBuffer);
|
||||
|
||||
promise_test(async () => {
|
||||
const input = readableStreamFromArray([inputChunk, emptyChunk]);
|
||||
const output = input.pipeThrough(new TextDecoderStream());
|
||||
const array = await readableStreamToArray(output);
|
||||
assert_array_equals(array, [expectedOutputString],
|
||||
'the output should be in one chunk');
|
||||
}, 'a trailing empty chunk should be ignored- ' + arrayBufferOrSharedArrayBuffer);
|
||||
});
|
||||
|
||||
promise_test(async () => {
|
||||
const buffer = new ArrayBuffer(3);
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
test(() => {
|
||||
const buf = new ArrayBuffer(2),
|
||||
view = new Uint8Array(buf),
|
||||
buf2 = new ArrayBuffer(2),
|
||||
view2 = new Uint8Array(buf2),
|
||||
decoder = new TextDecoder("utf-8")
|
||||
view[0] = 0xEF
|
||||
view[1] = 0xBB
|
||||
view2[0] = 0xBF
|
||||
view2[1] = 0x40
|
||||
assert_equals(decoder.decode(buf, {stream:true}), "")
|
||||
view[0] = 0x01
|
||||
view[1] = 0x02
|
||||
assert_equals(decoder.decode(buf2), "@")
|
||||
}, "Modify buffer after passing it in")
|
||||
["ArrayBuffer", "SharedArrayBuffer"].forEach(arrayBufferOrSharedArrayBuffer => {
|
||||
test(() => {
|
||||
const buf = new self[arrayBufferOrSharedArrayBuffer](2),
|
||||
view = new Uint8Array(buf),
|
||||
buf2 = new self[arrayBufferOrSharedArrayBuffer](2),
|
||||
view2 = new Uint8Array(buf2),
|
||||
decoder = new TextDecoder("utf-8");
|
||||
view[0] = 0xEF;
|
||||
view[1] = 0xBB;
|
||||
view2[0] = 0xBF;
|
||||
view2[1] = 0x40;
|
||||
assert_equals(decoder.decode(buf, {stream:true}), "");
|
||||
view[0] = 0x01;
|
||||
view[1] = 0x02;
|
||||
assert_equals(decoder.decode(buf2), "@");
|
||||
}, "Modify buffer after passing it in (" + arrayBufferOrSharedArrayBuffer + ")");
|
||||
});
|
||||
|
|
|
@ -16,21 +16,25 @@ var octets = {
|
|||
0xDF,0xFF]
|
||||
};
|
||||
|
||||
Object.keys(octets).forEach(function(encoding) {
|
||||
for (var len = 1; len <= 5; ++len) {
|
||||
test(function() {
|
||||
var encoded = octets[encoding];
|
||||
["ArrayBuffer", "SharedArrayBuffer"].forEach((arrayBufferOrSharedArrayBuffer) => {
|
||||
Object.keys(octets).forEach(function(encoding) {
|
||||
for (var len = 1; len <= 5; ++len) {
|
||||
test(function() {
|
||||
var encoded = octets[encoding];
|
||||
|
||||
var out = '';
|
||||
var decoder = new TextDecoder(encoding);
|
||||
for (var i = 0; i < encoded.length; i += len) {
|
||||
var sub = [];
|
||||
for (var j = i; j < encoded.length && j < i + len; ++j)
|
||||
sub.push(encoded[j]);
|
||||
out += decoder.decode(new Uint8Array(sub), {stream: true});
|
||||
}
|
||||
out += decoder.decode();
|
||||
assert_equals(out, string);
|
||||
}, 'Streaming decode: ' + encoding + ', ' + len + ' byte window');
|
||||
}
|
||||
});
|
||||
var out = '';
|
||||
var decoder = new TextDecoder(encoding);
|
||||
for (var i = 0; i < encoded.length; i += len) {
|
||||
var sub = [];
|
||||
for (var j = i; j < encoded.length && j < i + len; ++j)
|
||||
sub.push(encoded[j]);
|
||||
var uintArray = new Uint8Array(new self[arrayBufferOrSharedArrayBuffer](sub.length));
|
||||
uintArray.set(sub);
|
||||
out += decoder.decode(uintArray, {stream: true});
|
||||
}
|
||||
out += decoder.decode();
|
||||
assert_equals(out, string);
|
||||
}, 'Streaming decode: ' + encoding + ', ' + len + ' byte window (' + arrayBufferOrSharedArrayBuffer + ')');
|
||||
}
|
||||
});
|
||||
})
|
||||
|
|
Загрузка…
Ссылка в новой задаче