summaryrefslogtreecommitdiff
path: root/tests/napi/typedarray_test.js
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2024-02-12 13:46:50 -0700
committerGitHub <noreply@github.com>2024-02-12 13:46:50 -0700
commitf60720090c7bd8cdf91d7aebd0c42e01c86b3b83 (patch)
tree9becb7ff7e40d37769601fa049beccd101d58a98 /tests/napi/typedarray_test.js
parentbd1358efab8ba7339a8e70034315fa7da840292e (diff)
chore: move test_ffi and test_nap to tests/ [WIP] (#22394)
Moving some additional NAPI and. FFI tests out of the tree root.
Diffstat (limited to 'tests/napi/typedarray_test.js')
-rw-r--r--tests/napi/typedarray_test.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/napi/typedarray_test.js b/tests/napi/typedarray_test.js
new file mode 100644
index 000000000..25729754a
--- /dev/null
+++ b/tests/napi/typedarray_test.js
@@ -0,0 +1,39 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
+import { assert, assertEquals, loadTestLibrary } from "./common.js";
+
+const typedarray = loadTestLibrary();
+
+Deno.test("napi typedarray uint8", function () {
+ const byteArray = new Uint8Array([0, 1, 2]);
+ assertEquals(byteArray.length, 3);
+
+ const byteResult = typedarray.test_multiply(byteArray, 3);
+ assert(byteResult instanceof Uint8Array);
+ assertEquals(byteResult.length, 3);
+ assertEquals(byteResult[0], 0);
+ assertEquals(byteResult[1], 3);
+ assertEquals(byteResult[2], 6);
+});
+
+Deno.test("napi typedarray float64", function () {
+ const doubleArray = new Float64Array([0.0, 1.1, 2.2]);
+ assertEquals(doubleArray.length, 3);
+
+ const doubleResult = typedarray.test_multiply(doubleArray, -3);
+ assert(doubleResult instanceof Float64Array);
+ assertEquals(doubleResult.length, 3);
+ assertEquals(doubleResult[0], -0);
+ assertEquals(Math.round(10 * doubleResult[1]) / 10, -3.3);
+ assertEquals(Math.round(10 * doubleResult[2]) / 10, -6.6);
+});
+
+// TODO(bartlomieju): this test causes segfaults when used with jemalloc.
+// Node documentation provides a hint that this function is not supported by
+// other runtime like electron.
+// Deno.test("napi typedarray external", function () {
+// assertEquals(
+// new Uint8Array(typedarray.test_external()),
+// new Uint8Array([0, 1, 2, 3]),
+// );
+// });