harness test: testTypedArray.js

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
This commit is contained in:
Rick Waldron 2017-06-23 11:50:09 -04:00
parent 537ef01882
commit 5165cc11cf
3 changed files with 122 additions and 0 deletions

View File

@ -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.');
}

View File

@ -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++;
});

View File

@ -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);