summaryrefslogtreecommitdiff
path: root/tests/napi/bigint_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/bigint_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/bigint_test.js')
-rw-r--r--tests/napi/bigint_test.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/napi/bigint_test.js b/tests/napi/bigint_test.js
new file mode 100644
index 000000000..4a9ada205
--- /dev/null
+++ b/tests/napi/bigint_test.js
@@ -0,0 +1,63 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
+import { assertEquals, assertThrows, loadTestLibrary } from "./common.js";
+
+const bi = loadTestLibrary();
+
+Deno.test("cases", function () {
+ const cases = [
+ 0n,
+ -0n,
+ 1n,
+ -1n,
+ 100n,
+ 2121n,
+ -1233n,
+ 986583n,
+ -976675n,
+ 98765432213456789876546896323445679887645323232436587988766545658n,
+ -4350987086545760976737453646576078997096876957864353245245769809n,
+ ];
+
+ for (const num of cases) {
+ if (num > -(2n ** 63n) && num < 2n ** 63n) {
+ assertEquals(bi.testInt64(num), num);
+ assertEquals(bi.isLossless(num, true), true);
+ } else {
+ assertEquals(bi.isLossless(num, true), false);
+ }
+
+ if (num >= 0 && num < 2n ** 64n) {
+ assertEquals(bi.testUint64(num), num);
+ assertEquals(bi.isLossless(num, false), true);
+ } else {
+ assertEquals(bi.isLossless(num, false), false);
+ }
+
+ assertEquals(bi.testWords(num), num);
+ }
+});
+
+Deno.test(
+ // TODO(bartlomieju): fix this test
+ { ignore: true },
+ function tooBigBigInt() {
+ assertThrows(
+ () => bi.createTooBigBigInt(),
+ Error,
+ "Invalid argument",
+ );
+ },
+);
+
+Deno.test(
+ // TODO(bartlomieju): fix this test
+ { ignore: true },
+ function exceptionForwarding() {
+ assertThrows(
+ () => bi.makeBigIntWordsThrow(),
+ Error,
+ "Maximum BigInt size exceeded",
+ );
+ },
+);