summaryrefslogtreecommitdiff
path: root/test_napi/typedarray_test.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-01-14 14:00:48 +0100
committerGitHub <noreply@github.com>2023-01-14 13:00:48 +0000
commitb4ce48c80ab0b2f4c0d32b03b8f49becba8d5416 (patch)
treec247b9b1ba9d48dd099cd08892ea645353f430f4 /test_napi/typedarray_test.js
parentd0f88fc1ca175ce696bdef18778b83c4a7373afd (diff)
fix(napi): correct arguments for napi_get_typedarray_info (#17306)
Diffstat (limited to 'test_napi/typedarray_test.js')
-rw-r--r--test_napi/typedarray_test.js26
1 files changed, 25 insertions, 1 deletions
diff --git a/test_napi/typedarray_test.js b/test_napi/typedarray_test.js
index 3cd084dc8..f9b346626 100644
--- a/test_napi/typedarray_test.js
+++ b/test_napi/typedarray_test.js
@@ -1,9 +1,33 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-import { assertEquals, loadTestLibrary } from "./common.js";
+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);
+});
+
Deno.test("napi typedarray external", function () {
assertEquals(
new Uint8Array(typedarray.test_external()),