X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/8bf43f6e1898ca921d5e63b4513e4c6b2241ebc5..beab7268e7673b036222e64aac924f850e2b976e:/object.test.js?ds=inline diff --git a/object.test.js b/object.test.js index d5a60bb..a2e718b 100644 --- a/object.test.js +++ b/object.test.js @@ -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]]);