]> Lady’s Gitweb - Pisces/blobdiff - value.test.js
Add denseProxy, various collection.js improvements
[Pisces] / value.test.js
index ce6464d07091e19fd89b84b578d7a0ede3cb258f..c55b591eb97c64ca9f5d6b83147067cc1a063829 100644 (file)
@@ -1,11 +1,14 @@
-// β™“πŸŒŸ PiscΔ“s βˆ· value.test.js
-// ====================================================================
-//
-// Copyright Β© 2022–2023 Lady [@ Lady’s Computer].
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * βŒ β™“πŸŒŸ PiscΔ“s βˆ· value.test.js
+ *
+ * Copyright Β© 2022–2023, 2025 Lady [@ Ladys Computer].
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
+ */
 
 import {
   assertEquals,
@@ -16,18 +19,21 @@ import {
 } from "./dev-deps.js";
 import {
   ASYNC_ITERATOR,
+  canonicalNumericIndexSting,
   completePropertyDescriptor,
   HAS_INSTANCE,
   IS_CONCAT_SPREADABLE,
   isAccessorDescriptor,
+  isArrayIndexString,
   isDataDescriptor,
   isFullyPopulatedDescriptor,
   isGenericDescriptor,
+  isIntegerIndexString,
   ITERATOR,
-  LN10,
-  LN2,
-  LOG10ℇ,
-  LOG2ℇ,
+  LN_10,
+  LN_2,
+  LOG10_𝑒,
+  LOG2_𝑒,
   MATCH,
   MATCH_ALL,
   MAXIMUM_NUMBER,
@@ -41,13 +47,13 @@ import {
   ordinaryToPrimitive,
   POSITIVE_INFINITY,
   POSITIVE_ZERO,
-  RECIPROCAL_SQRT2,
+  RECIPROCAL_SQRT_2,
   REPLACE,
   sameValue,
   sameValueZero,
   SPECIES,
   SPLIT,
-  SQRT2,
+  SQRT_2,
   TO_PRIMITIVE,
   TO_STRING_TAG,
   toFunctionName,
@@ -58,9 +64,9 @@ import {
   type,
   UNDEFINED,
   UNSCOPABLES,
-  Ξ•,
-  Ξ ,
-  β„‡,
+  π‘’,
+  πœ€,
+  πœ‹,
 } from "./value.js";
 
 describe("ASYNC_ITERATOR", () => {
@@ -90,27 +96,27 @@ describe("ITERATOR", () => {
   });
 });
 
-describe("LN10", () => {
+describe("LN_10", () => {
   it("[[Get]] is ln(10)", () => {
-    assertStrictEquals(LN10, Math.LN10);
+    assertStrictEquals(LN_10, Math.LN10);
   });
 });
 
-describe("LN2", () => {
+describe("LN_2", () => {
   it("[[Get]] is ln(2)", () => {
-    assertStrictEquals(LN2, Math.LN2);
+    assertStrictEquals(LN_2, Math.LN2);
   });
 });
 
-describe("LOG10ℇ", () => {
-  it("[[Get]] is log10(ℇ)", () => {
-    assertStrictEquals(LOG10ℇ, Math.LOG10E);
+describe("LOG10_𝑒", () => {
+  it("[[Get]] is log10(𝑒)", () => {
+    assertStrictEquals(LOG10_𝑒, Math.LOG10E);
   });
 });
 
-describe("LOG2ℇ", () => {
+describe("LOG2_𝑒", () => {
   it("[[Get]] is log2(ℇ)", () => {
-    assertStrictEquals(LOG2ℇ, Math.LOG2E);
+    assertStrictEquals(LOG2_𝑒, Math.LOG2E);
   });
 });
 
@@ -192,9 +198,9 @@ describe("POSITIVE_ZERO", () => {
   });
 });
 
-describe("RECIPROCAL_SQRT2", () => {
+describe("RECIPROCAL_SQRT_2", () => {
   it("[[Get]] is sqrt(Β½)", () => {
-    assertStrictEquals(RECIPROCAL_SQRT2, Math.SQRT1_2);
+    assertStrictEquals(RECIPROCAL_SQRT_2, Math.SQRT1_2);
   });
 });
 
@@ -216,9 +222,9 @@ describe("SPLIT", () => {
   });
 });
 
-describe("SQRT2", () => {
+describe("SQRT_2", () => {
   it("[[Get]] is sqrt(2)", () => {
-    assertStrictEquals(SQRT2, Math.SQRT2);
+    assertStrictEquals(SQRT_2, Math.SQRT2);
   });
 });
 
@@ -246,6 +252,59 @@ describe("UNSCOPABLES", () => {
   });
 });
 
+describe("canonicalNumericIndexString", () => {
+  it("[[Call]] returns undefined for nonstrings", () => {
+    assertStrictEquals(canonicalNumericIndexString(1), void {});
+  });
+
+  it("[[Call]] returns undefined for noncanonical strings", () => {
+    assertStrictEquals(canonicalNumericIndexString(""), void {});
+    assertStrictEquals(canonicalNumericIndexString("01"), void {});
+    assertStrictEquals(
+      canonicalNumericIndexString("9007199254740993"),
+      void {},
+    );
+  });
+
+  it('[[Call]] returns -0 for "-0"', () => {
+    assertStrictEquals(canonicalNumericIndexString("-0"), -0);
+  });
+
+  it("[[Call]] returns the corresponding number for canonical strings", () => {
+    assertStrictEquals(canonicalNumericIndexString("0"), 0);
+    assertStrictEquals(canonicalNumericIndexString("-0.25"), -0.25);
+    assertStrictEquals(
+      canonicalNumericIndexString("9007199254740992"),
+      9007199254740992,
+    );
+    assertStrictEquals(canonicalNumericIndexString("NaN"), 0 / 0);
+    assertStrictEquals(canonicalNumericIndexString("Infinity"), 1 / 0);
+    assertStrictEquals(
+      canonicalNumericIndexString("-Infinity"),
+      -1 / 0,
+    );
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new canonicalNumericIndexString(""));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(canonicalNumericIndexString.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        canonicalNumericIndexString.name,
+        "canonicalNumericIndexString",
+      );
+    });
+  });
+});
+
 describe("completePropertyDescriptor", () => {
   it("[[Call]] completes a generic descriptor", () => {
     const desc = {};
@@ -349,6 +408,69 @@ describe("isAccessorDescriptor", () => {
   });
 });
 
+describe("isArrayIndexString", () => {
+  it("[[Call]] returns false for nonstrings", () => {
+    assertStrictEquals(isArrayIndexString(1), false);
+  });
+
+  it("[[Call]] returns false for noncanonical strings", () => {
+    assertStrictEquals(isArrayIndexString(""), false);
+    assertStrictEquals(isArrayIndexString("01"), false);
+    assertStrictEquals(isArrayIndexString("9007199254740993"), false);
+  });
+
+  it("[[Call]] returns false for nonfinite numbers", () => {
+    assertStrictEquals(isArrayIndexString("NaN"), false);
+    assertStrictEquals(isArrayIndexString("Infinity"), false);
+    assertStrictEquals(isArrayIndexString("-Infinity"), false);
+  });
+
+  it("[[Call]] returns false for negative numbers", () => {
+    assertStrictEquals(isArrayIndexString("-0"), false);
+    assertStrictEquals(isArrayIndexString("-1"), false);
+  });
+
+  it("[[Call]] returns false for nonintegers", () => {
+    assertStrictEquals(isArrayIndexString("0.25"), false);
+    assertStrictEquals(isArrayIndexString("1.1"), false);
+  });
+
+  it("[[Call]] returns false for numbers greater than or equal to -1 >>> 0", () => {
+    assertStrictEquals(isArrayIndexString(String(-1 >>> 0)), false);
+    assertStrictEquals(
+      isArrayIndexString(String((-1 >>> 0) + 1)),
+      false,
+    );
+  });
+
+  it("[[Call]] returns true for array lengths less than -1 >>> 0", () => {
+    assertStrictEquals(isArrayIndexString("0"), true);
+    assertStrictEquals(
+      isArrayIndexString(String((-1 >>> 0) - 1)),
+      true,
+    );
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new isArrayIndexString("0"));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(isArrayIndexString.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        isArrayIndexString.name,
+        "isArrayIndexString",
+      );
+    });
+  });
+});
+
 describe("isDataDescriptor", () => {
   it("[[Call]] returns false for a generic descriptor", () => {
     assertStrictEquals(isDataDescriptor({}), false);
@@ -502,6 +624,68 @@ describe("isGenericDescriptor", () => {
   });
 });
 
+describe("isIntegerIndexString", () => {
+  it("[[Call]] returns false for nonstrings", () => {
+    assertStrictEquals(isIntegerIndexString(1), false);
+  });
+
+  it("[[Call]] returns false for noncanonical strings", () => {
+    assertStrictEquals(isIntegerIndexString(""), false);
+    assertStrictEquals(isIntegerIndexString("01"), false);
+    assertStrictEquals(
+      isIntegerIndexString("9007199254740993"),
+      false,
+    );
+  });
+
+  it("[[Call]] returns false for nonfinite numbers", () => {
+    assertStrictEquals(isIntegerIndexString("NaN"), false);
+    assertStrictEquals(isIntegerIndexString("Infinity"), false);
+    assertStrictEquals(isIntegerIndexString("-Infinity"), false);
+  });
+
+  it("[[Call]] returns false for negative numbers", () => {
+    assertStrictEquals(isIntegerIndexString("-0"), false);
+    assertStrictEquals(isIntegerIndexString("-1"), false);
+  });
+
+  it("[[Call]] returns false for nonintegers", () => {
+    assertStrictEquals(isIntegerIndexString("0.25"), false);
+    assertStrictEquals(isIntegerIndexString("1.1"), false);
+  });
+
+  it("[[Call]] returns false for numbers greater than or equal to 2 ** 53", () => {
+    assertStrictEquals(
+      isIntegerIndexString("9007199254740992"),
+      false,
+    );
+  });
+
+  it("[[Call]] returns true for safe canonical integer strings", () => {
+    assertStrictEquals(isIntegerIndexString("0"), true);
+    assertStrictEquals(isIntegerIndexString("9007199254740991"), true);
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new isIntegerIndexString("0"));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(isIntegerIndexString.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        isIntegerIndexString.name,
+        "isIntegerIndexString",
+      );
+    });
+  });
+});
+
 describe("ordinaryToPrimitive", () => {
   it("[[Call]] prefers `valueOf` by default", () => {
     const obj = {
@@ -1071,20 +1255,20 @@ describe("type", () => {
   });
 });
 
-describe("Ξ•", () => {
-  it("[[Get]] is Ξ΅", () => {
-    assertStrictEquals(Ξ•, Number.EPSILON);
+describe("𝑒", () => {
+  it("[[Get]] is π‘’", () => {
+    assertStrictEquals(𝑒, Math.E);
   });
 });
 
-describe("Ξ ", () => {
-  it("[[Get]] is Ο€", () => {
-    assertStrictEquals(Ξ , Math.PI);
+describe("πœ€", () => {
+  it("[[Get]] is πœ€", () => {
+    assertStrictEquals(πœ€, Number.EPSILON);
   });
 });
 
-describe("ℇ", () => {
-  it("[[Get]] is β„‡", () => {
-    assertStrictEquals(ℇ, Math.E);
+describe("πœ‹", () => {
+  it("[[Get]] is πœ‹", () => {
+    assertStrictEquals(πœ‹, Math.PI);
   });
 });
This page took 0.234415 seconds and 4 git commands to generate.