mirror of https://github.com/tc39/test262.git
harness test: testTypedArray.js
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
This commit is contained in:
parent
537ef01882
commit
5165cc11cf
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) 2017 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
description: >
|
||||
Including testTypedArray.js will expose:
|
||||
|
||||
testTypedArrayConversions()
|
||||
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
var threw = false;
|
||||
|
||||
try {
|
||||
testTypedArrayConversions({}, () => {});
|
||||
} catch(err) {
|
||||
threw = true;
|
||||
if (err.constructor !== TypeError) {
|
||||
throw new Error(
|
||||
'Expected a TypeError, but a "' + err.constructor.name +
|
||||
'" was thrown.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (threw === false) {
|
||||
$ERROR('Expected a TypeError, but no error was thrown.');
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
// Copyright (c) 2017 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
description: >
|
||||
Including testTypedArray.js will expose:
|
||||
|
||||
testTypedArrayConversions()
|
||||
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
var callCount = 0;
|
||||
var bcv = {
|
||||
values: [
|
||||
127,
|
||||
],
|
||||
expected: {
|
||||
Int8: [
|
||||
127,
|
||||
],
|
||||
Uint8: [
|
||||
127,
|
||||
],
|
||||
Uint8Clamped: [
|
||||
127,
|
||||
],
|
||||
Int16: [
|
||||
127,
|
||||
],
|
||||
Uint16: [
|
||||
127,
|
||||
],
|
||||
Int32: [
|
||||
127,
|
||||
],
|
||||
Uint32: [
|
||||
127,
|
||||
],
|
||||
Float32: [
|
||||
127,
|
||||
],
|
||||
Float64: [
|
||||
127,
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
testTypedArrayConversions(bcv, function(TA, value, expected, initial) {
|
||||
var sample = new TA([initial]);
|
||||
sample.fill(value);
|
||||
assert.sameValue(initial, 0);
|
||||
assert.sameValue(sample[0], expected);
|
||||
callCount++;
|
||||
});
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (c) 2017 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
description: >
|
||||
Including testTypedArray.js will expose:
|
||||
|
||||
var typedArrayConstructors = [ array of TypedArray constructors ]
|
||||
var TypedArray
|
||||
|
||||
testWithTypedArrayConstructors()
|
||||
testTypedArrayConversions()
|
||||
|
||||
includes: [testTypedArray.js,arrayContains.js]
|
||||
---*/
|
||||
var TAConstructors = [
|
||||
Float64Array,
|
||||
Float32Array,
|
||||
Int32Array,
|
||||
Int16Array,
|
||||
Int8Array,
|
||||
Uint32Array,
|
||||
Uint16Array,
|
||||
Uint8Array,
|
||||
Uint8ClampedArray
|
||||
];
|
||||
var length = TAConstructors.length;
|
||||
|
||||
assert(
|
||||
arrayContains(typedArrayConstructors, TAConstructors),
|
||||
"All TypedArray constructors are accounted for"
|
||||
);
|
||||
assert(typeof TypedArray === "function");
|
||||
assert.sameValue(TypedArray, Object.getPrototypeOf(Uint8Array));
|
||||
|
||||
|
||||
var callCount = 0;
|
||||
testWithTypedArrayConstructors(() => callCount++);
|
||||
assert.sameValue(callCount, length);
|
||||
|
Loading…
Reference in New Issue