]> Lady’s Gitweb - Pisces/blobdiff - object.test.js
Move isConcatSpreadable[Object] into object.js
[Pisces] / object.test.js
index d5a60bb68ed60b00f3f31be1c0d1e11b935ab48d..a2e718b189a93ba31179f29dc12b7f9086752f35 100644 (file)
@@ -34,10 +34,13 @@ import {
   getPrototype,
   hasOwnProperty,
   hasProperty,
+  isArraylikeObject,
+  isConcatSpreadableObject,
   isExtensibleObject,
   isUnfrozenObject,
   isUnsealedObject,
   LazyLoader,
+  lengthOfArraylike,
   namedEntries,
   namedKeys,
   namedValues,
@@ -1534,6 +1537,114 @@ describe("hasOwnProperty", () => {
   });
 });
 
+describe("isArraylikeObject", () => {
+  it("[[Call]] returns false for primitives", () => {
+    assertStrictEquals(isArraylikeObject("failure"), false);
+  });
+
+  it("[[Call]] returns false if length throws", () => {
+    assertStrictEquals(
+      isArraylikeObject({
+        get length() {
+          throw void {};
+        },
+      }),
+      false,
+    );
+  });
+
+  it("[[Call]] returns false if length is not a number and cannot be converted to one", () => {
+    assertStrictEquals(isArraylikeObject({ length: 1n }), false);
+  });
+
+  it("[[Call]] returns true if length is convertable to a number", () => {
+    assertStrictEquals(isArraylikeObject({ length: -0 }), true);
+    assertStrictEquals(isArraylikeObject({ length: 1 }), true);
+    assertStrictEquals(isArraylikeObject({ length: -1.25 }), true);
+    assertStrictEquals(
+      isArraylikeObject({ length: 9007199254740992 }),
+      true,
+    );
+    assertStrictEquals(isArraylikeObject({ length: Infinity }), true);
+    assertStrictEquals(isArraylikeObject({ length: "success" }), true);
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new isArraylikeObject({}));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(isArraylikeObject.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        isArraylikeObject.name,
+        "isArraylikeObject",
+      );
+    });
+  });
+});
+
+describe("isConcatSpreadableObject", () => {
+  it("[[Call]] returns false for primitives", () => {
+    assertStrictEquals(isConcatSpreadableObject("failure"), false);
+  });
+
+  it("[[Call]] returns false if [Symbol.isConcatSpreadable] is null or false", () => {
+    assertStrictEquals(
+      isConcatSpreadableObject(
+        Object.assign([], { [Symbol.isConcatSpreadable]: null }),
+      ),
+      false,
+    );
+    assertStrictEquals(
+      isConcatSpreadableObject(
+        Object.assign([], { [Symbol.isConcatSpreadable]: false }),
+      ),
+      false,
+    );
+  });
+
+  it("[[Call]] returns true if [Symbol.isConcatSpreadable] is undefined and the object is an array", () => {
+    assertStrictEquals(
+      isConcatSpreadableObject(
+        Object.assign([], { [Symbol.isConcatSpreadable]: undefined }),
+      ),
+      true,
+    );
+  });
+
+  it("[[Call]] returns true if [Symbol.isConcatSpreadable] is true", () => {
+    assertStrictEquals(
+      isConcatSpreadableObject({ [Symbol.isConcatSpreadable]: true }),
+      true,
+    );
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new isConcatSpreadableObject({}));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(isConcatSpreadableObject.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        isConcatSpreadableObject.name,
+        "isConcatSpreadableObject",
+      );
+    });
+  });
+});
+
 describe("isExtensibleObject", () => {
   it("[[Call]] returns true for extensible objects", () => {
     assertStrictEquals(isExtensibleObject({}), true);
@@ -1648,6 +1759,63 @@ describe("isUnsealedObject", () => {
   });
 });
 
+describe("lengthOfArraylike", () => {
+  it("[[Call]] returns the length", () => {
+    assertStrictEquals(
+      lengthOfArraylike({ length: 9007199254740991 }),
+      9007199254740991,
+    );
+  });
+
+  it("[[Call]] returns a non·nan result", () => {
+    assertStrictEquals(lengthOfArraylike({ length: NaN }), 0);
+    assertStrictEquals(lengthOfArraylike({ length: "failure" }), 0);
+  });
+
+  it("[[Call]] returns an integral result", () => {
+    assertStrictEquals(lengthOfArraylike({ length: 0.25 }), 0);
+    assertStrictEquals(lengthOfArraylike({ length: 1.1 }), 1);
+  });
+
+  it("[[Call]] returns a result greater than or equal to zero", () => {
+    assertStrictEquals(lengthOfArraylike({ length: -0 }), 0);
+    assertStrictEquals(lengthOfArraylike({ length: -1 }), 0);
+    assertStrictEquals(lengthOfArraylike({ length: -Infinity }), 0);
+  });
+
+  it("[[Call]] returns a result less than 2 ** 53", () => {
+    assertStrictEquals(
+      lengthOfArraylike({ length: 9007199254740992 }),
+      9007199254740991,
+    );
+    assertStrictEquals(
+      lengthOfArraylike({ length: Infinity }),
+      9007199254740991,
+    );
+  });
+
+  it("[[Call]] does not require an object argument", () => {
+    assertStrictEquals(lengthOfArraylike("string"), 6);
+    assertStrictEquals(lengthOfArraylike(Symbol()), 0);
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new lengthOfArraylike(""));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(lengthOfArraylike.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(lengthOfArraylike.name, "lengthOfArraylike");
+    });
+  });
+});
+
 describe("namedEntries", () => {
   it("[[Call]] gets named entries", () => {
     assertEquals(namedEntries({ success: true }), [["success", true]]);
This page took 0.028994 seconds and 4 git commands to generate.