From c1bc43b1b10ec9d7c83ebee2af1837b78b784e52 Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Fri, 9 Feb 2018 13:39:06 -0500 Subject: Restore original tests for TypedArrays and optimize files - optimize file names - BigInt folder for TAs.from and of - copy tests preparing for bigint - copy ta prototype methods for bigint - Use an exclusive harness for bigint typedarrays - add features - use proper harness - use preper harness - Restore original tests for TypedArrays - final fixes - fix includes --- harness/testBigIntTypedArray.js | 77 +++++++++++++++++++++++++++++++++++++++++ harness/testTypedArray.js | 16 +-------- 2 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 harness/testBigIntTypedArray.js (limited to 'harness') diff --git a/harness/testBigIntTypedArray.js b/harness/testBigIntTypedArray.js new file mode 100644 index 000000000..90bb3aee4 --- /dev/null +++ b/harness/testBigIntTypedArray.js @@ -0,0 +1,77 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +---*/ + +/** + * Array containing every typed array constructor. + */ +var BigIntTypedArrayConstructors = [ + BigInt64Array, + BigUint64Array +]; + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +function convertToBigInt(x) { + return (Array.isArray(x)) ? x.map(convertToBigInt) : BigInt(x); +} + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + var constructors = selected || BigIntTypedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testBigIntTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithBigIntTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} + \ No newline at end of file diff --git a/harness/testTypedArray.js b/harness/testTypedArray.js index 7f777b56c..bf6c4875e 100644 --- a/harness/testTypedArray.js +++ b/harness/testTypedArray.js @@ -20,22 +20,11 @@ var typedArrayConstructors = [ Uint8ClampedArray ]; -var numericTypedArrayConstructors = typedArrayConstructors.slice(); - -if (typeof BigInt !== "undefined") { - typedArrayConstructors.push(BigInt64Array); - typedArrayConstructors.push(BigUint64Array); -} - /** * The %TypedArray% intrinsic constructor function. */ var TypedArray = Object.getPrototypeOf(Int8Array); -function convertToBigInt(x) { - return (Array.isArray(x)) ? x.map(convertToBigInt) : BigInt(x); -} - /** * Callback for testing a typed array constructor. * @@ -52,12 +41,9 @@ function convertToBigInt(x) { function testWithTypedArrayConstructors(f, selected) { var constructors = selected || typedArrayConstructors; for (var i = 0; i < constructors.length; ++i) { + // TODO: Remove this var N = function(x) { return x; }; var constructor = constructors[i]; - if (constructor.name == "BigInt64Array" || - constructor.name == "BigUint64Array") { - N = convertToBigInt; - } try { f(constructor, N); } catch (e) { -- cgit v1.2.1