mirror of
https://github.com/tc39/test262.git
synced 2025-07-22 13:34:38 +02:00
Update to use different buffers, return case name
This commit is contained in:
parent
216bdb5160
commit
c1d27503e8
@ -123,28 +123,43 @@ function testTypedArrayConversions(byteConversionValues, fn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createTypedArrayVariations(TA, values) {
|
function createTypedArrayVariations(TA, values) {
|
||||||
const rab = new ArrayBuffer(4 * TA.BYTES_PER_ELEMENT, { maxByteLength: 8 * TA.BYTES_PER_ELEMENT });
|
|
||||||
|
|
||||||
let nonresizable = new TA(values);
|
const rab = () => {
|
||||||
let fixedLength = new TA(rab, 0, values.length);
|
let buffer = new ArrayBuffer(4 * TA.BYTES_PER_ELEMENT, { maxByteLength: 8 * TA.BYTES_PER_ELEMENT });
|
||||||
let lengthTracking = new TA(rab, 0);
|
let ta_write = new TA(buffer);
|
||||||
|
|
||||||
let fixedLengthWithOffset = {
|
|
||||||
name: fixedLengthWithOffset,
|
|
||||||
contents: new TA(rab, 2 * TA.BYTES_PER_ELEMENT, (values.length / 2))
|
|
||||||
};
|
|
||||||
|
|
||||||
let lengthTrackingWithOffset = {
|
|
||||||
name: lengthTrackingWithOffset,
|
|
||||||
contents: new TA(rab, 2 * TA.BYTES_PER_ELEMENT)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Writes data to the buffer backing all the arrays
|
|
||||||
let ta_write = new TA(rab);
|
|
||||||
for (let i = 0; i < values.length; ++i) {
|
for (let i = 0; i < values.length; ++i) {
|
||||||
ta_write[i] = values[i];
|
ta_write[i] = values[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nonresizable = {
|
||||||
|
name: 'non-resizable',
|
||||||
|
contents: new TA(values)
|
||||||
|
};
|
||||||
|
|
||||||
|
const fixedLength = {
|
||||||
|
name: 'fixed length',
|
||||||
|
contents: new TA(rab(), 0, values.length)
|
||||||
|
};
|
||||||
|
|
||||||
|
const lengthTracking = {
|
||||||
|
name: 'length tracking',
|
||||||
|
contents: new TA(rab(), 0)
|
||||||
|
};
|
||||||
|
|
||||||
|
const fixedLengthWithOffset = {
|
||||||
|
name: 'fixed length with offset',
|
||||||
|
contents: new TA(rab(), 2 * TA.BYTES_PER_ELEMENT, (values.length / 2))
|
||||||
|
};
|
||||||
|
|
||||||
|
const lengthTrackingWithOffset = {
|
||||||
|
name: 'length tracking with offset',
|
||||||
|
contents: new TA(rab(), 2 * TA.BYTES_PER_ELEMENT)
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
nonresizable,
|
nonresizable,
|
||||||
fixedLength,
|
fixedLength,
|
||||||
|
@ -42,48 +42,19 @@ testWithTypedArrayConstructors(TA => {
|
|||||||
nonresizable,
|
nonresizable,
|
||||||
fixedLength,
|
fixedLength,
|
||||||
lengthTracking,
|
lengthTracking,
|
||||||
].forEach((a) => {
|
].forEach(({ name, contents }) => {
|
||||||
assert.sameValue(a.at(0), 1, 'a.at(0) must return 1')
|
assert.sameValue(contents.at(0), 1, `contents.at(0) must return 1 in ${name}`)
|
||||||
assert.sameValue(a.at(1), 2, 'a.at(1) must return 2')
|
assert.sameValue(contents.at(1), 2, `contents.at(1) must return 2 in ${name}`)
|
||||||
assert.sameValue(a.at(2), 3, 'a.at(2) must return 3')
|
assert.sameValue(contents.at(2), 3, `contents.at(2) must return 3 in ${name}`)
|
||||||
assert.sameValue(a.at(3), 4, 'a.at(3) must return 4')
|
assert.sameValue(contents.at(3), 4, `contents.at(3) must return 4 in ${name}`)
|
||||||
});
|
});
|
||||||
|
|
||||||
[
|
[
|
||||||
fixedLengthWithOffset,
|
fixedLengthWithOffset,
|
||||||
lengthTrackingWithOffset
|
lengthTrackingWithOffset
|
||||||
].forEach((a) => {
|
].forEach(({ name, contents }) => {
|
||||||
assert.sameValue(a.at(0), 3, 'a.at(2) must return 3')
|
assert.sameValue(contents.at(0), 3, `contents.at(0) must return 3 in ${name}`)
|
||||||
assert.sameValue(a.at(1), 4, 'a.at(3) must return 4')
|
assert.sameValue(contents.at(1), 4, `contents.at(1) must return 4 in ${name}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
testWithTypedArrayVariants(TA => {
|
|
||||||
assert.sameValue(typeof TA.prototype.at, 'function', 'The value of `typeof TA.prototype.at` is "function"');
|
|
||||||
|
|
||||||
const values = [1, 2, 3, 4];
|
|
||||||
|
|
||||||
/*
|
|
||||||
Works for non-offset ...
|
|
||||||
*/
|
|
||||||
|
|
||||||
testWithTypedArrayVariants(TA, values, (case) => {
|
|
||||||
/*
|
|
||||||
I updated this to refer to the values array instead of the
|
|
||||||
explicit value because really they should have both been
|
|
||||||
written this way — it makes the connection clear.
|
|
||||||
*/
|
|
||||||
assert.sameValue(a.at(0), values[0], 'a.at(0) must return 1');
|
|
||||||
assert.sameValue(a.at(1), values[1], 'a.at(1) must return 2');
|
|
||||||
assert.sameValue(a.at(2), values[2], 'a.at(2) must return 3');
|
|
||||||
assert.sameValue(a.at(3), values[3], 'a.at(3) must return 4');
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
|
||||||
... and then what do we do for the offsets?
|
|
||||||
*/
|
|
||||||
|
|
||||||
});
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user