From 5165cc11cfd629633d606010bb51b6c55a2c38f8 Mon Sep 17 00:00:00 2001
From: Rick Waldron <waldron.rick@gmail.com>
Date: Fri, 23 Jun 2017 11:50:09 -0400
Subject: [PATCH] harness test: testTypedArray.js

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
---
 .../testTypedArray-conversions-call-error.js  | 29 ++++++++++
 test/harness/testTypedArray-conversions.js    | 54 +++++++++++++++++++
 test/harness/testTypedArray.js                | 39 ++++++++++++++
 3 files changed, 122 insertions(+)
 create mode 100644 test/harness/testTypedArray-conversions-call-error.js
 create mode 100644 test/harness/testTypedArray-conversions.js
 create mode 100644 test/harness/testTypedArray.js

diff --git a/test/harness/testTypedArray-conversions-call-error.js b/test/harness/testTypedArray-conversions-call-error.js
new file mode 100644
index 0000000000..20837bed2a
--- /dev/null
+++ b/test/harness/testTypedArray-conversions-call-error.js
@@ -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.');
+}
+
+
diff --git a/test/harness/testTypedArray-conversions.js b/test/harness/testTypedArray-conversions.js
new file mode 100644
index 0000000000..05a44c552a
--- /dev/null
+++ b/test/harness/testTypedArray-conversions.js
@@ -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++;
+});
+
diff --git a/test/harness/testTypedArray.js b/test/harness/testTypedArray.js
new file mode 100644
index 0000000000..ffb6e9e3b7
--- /dev/null
+++ b/test/harness/testTypedArray.js
@@ -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);
+
-- 
GitLab