]> Lady’s Gitweb - Pisces/commitdiff
Move isArrayIndexString into string.js
authorLady <redacted>
Fri, 17 Nov 2023 02:47:41 +0000 (21:47 -0500)
committerLady <redacted>
Fri, 17 Nov 2023 02:49:48 +0000 (21:49 -0500)
…and add some missing tests for isIntegerIndexString.

collection.js
collection.test.js
string.js
string.test.js

index 0d4e623456d72aecbb9ada812087f5824d7fab6e..69c0beefabf16bd9d64fe57f17f82d8ab11dd3e7 100644 (file)
@@ -8,14 +8,7 @@
 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 
 import { call, createCallableFunction } from "./function.js";
-import { canonicalNumericIndexString } from "./string.js";
-import {
-  lengthOfArraylike,
-  sameValue,
-  toIndex,
-  toLength,
-  type,
-} from "./value.js";
+import { lengthOfArraylike, toIndex, type } from "./value.js";
 
 const { prototype: arrayPrototype } = Array;
 
@@ -200,19 +193,6 @@ export const indices = createCallableFunction(
   "indices",
 );
 
-/** Returns whether the provided value is an array index string. */
-export const isArrayIndexString = ($) => {
-  const value = canonicalNumericIndexString($);
-  if (value !== undefined) {
-    // The provided value is a canonical numeric index string.
-    return sameValue(value, 0) || value > 0 && value < -1 >>> 0 &&
-        value === toLength(value);
-  } else {
-    // The provided value is not a canonical numeric index string.
-    return false;
-  }
-};
-
 /** Returns whether the provided value is arraylike. */
 export const isArraylikeObject = ($) => {
   if (type($) !== "object") {
index 7c242cc987023ab23d35f01dbbf7c9809a6336b7..acd90d2eaa73046c744cdf3cd6668683582fe8f0 100644 (file)
@@ -18,7 +18,6 @@ import {
 } from "./dev-deps.js";
 import {
   findIndexedEntry,
-  isArrayIndexString,
   isArraylikeObject,
   isCollection,
   isConcatSpreadable,
@@ -80,50 +79,6 @@ describe("findIndexedEntry", () => {
   });
 });
 
-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,
-    );
-  });
-});
-
 describe("isArraylikeObject", () => {
   it("[[Call]] returns false for primitives", () => {
     assertStrictEquals(isArraylikeObject("failure"), false);
index bffa6d2ac9198201af7e1b6760a9fe15a3962abe..0bd5f9e03bc4dc0c9b5622a969757dfd2f78890b 100644 (file)
--- a/string.js
+++ b/string.js
@@ -521,6 +521,19 @@ export const getLastSubstringIndex = createCallableFunction(
   { name: "getLastSubstringIndex" },
 );
 
+/** Returns whether the provided value is an array index string. */
+export const isArrayIndexString = ($) => {
+  const value = canonicalNumericIndexString($);
+  if (value !== undefined) {
+    // The provided value is a canonical numeric index string.
+    return sameValue(value, 0) || value > 0 && value < -1 >>> 0 &&
+        value === toLength(value);
+  } else {
+    // The provided value is not a canonical numeric index string.
+    return false;
+  }
+};
+
 /**
  * Returns the result of joining the provided iterable.
  *
index bdef3897cde4c7a1fa8babfbf1086bf1c941d252..47a87db4aeefd98060f71242d2141546db30ff3e 100644 (file)
@@ -29,6 +29,7 @@ import {
   getCodeUnit,
   getFirstSubstringIndex,
   getLastSubstringIndex,
+  isArrayIndexString,
   isIntegerIndexString,
   join,
   Matcher,
@@ -934,6 +935,69 @@ describe("getLastSubstringIndex", () => {
   });
 });
 
+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("isIntegerIndexString", () => {
   it("[[Call]] returns false for nonstrings", () => {
     assertStrictEquals(isIntegerIndexString(1), false);
@@ -975,6 +1039,25 @@ describe("isIntegerIndexString", () => {
     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("join", () => {
This page took 0.033139 seconds and 4 git commands to generate.