]>
Lady’s Gitweb - Pisces/blob - collection.test.js
779b4ca506eee40f02c60e2ae4134e254f842362
1 // ♓🌟 Piscēs ∷ collection.test.js
2 // ====================================================================
4 // Copyright © 2022 Lady [@ Lady’s Computer].
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
18 } from "./dev-deps.js";
23 } from "./collection.js";
25 describe("findIndexedEntry", () => {
26 it("[[Call]] returns undefined if no matching entry exists", () => {
27 assertStrictEquals(findIndexedEntry([], () => true), void {});
28 assertStrictEquals(findIndexedEntry([1], () => false), void {});
31 it("[[Call]] returns an entry for the first match", () => {
33 findIndexedEntry([, true, false], ($) => $ ?? true),
37 findIndexedEntry(["failure", "success"], ($) => $ == "success"),
42 it("[[Call]] works on arraylike objects", () => {
44 findIndexedEntry({ 1: "success", length
: 2 }, ($) => $),
48 findIndexedEntry({ 1: "failure", length
: 1 }, ($) => $),
53 it("[[Call]] only gets the value once", () => {
54 const get1
= spy(() => true);
61 assertSpyCalls(get1
, 1);
64 it("[[Call]] passes the value, index, and this value to the callback", () => {
65 const arr
= ["failure", "success", "success"];
66 const callback
= spy(($) => $ === "success");
68 findIndexedEntry(arr
, callback
, thisArg
);
69 assertSpyCalls(callback
, 2);
70 assertSpyCall(callback
, 0, {
71 args
: ["failure", 0, arr
],
74 assertSpyCall(callback
, 1, {
75 args
: ["success", 1, arr
],
81 describe("isCollection", () => {
82 it("[[Call]] returns false for primitives", () => {
83 assertStrictEquals(isCollection("failure"), false);
86 it("[[Call]] returns false if length throws", () => {
97 it("[[Call]] returns false if length is not an integer index and cannot be converted to one", () => {
99 isCollection({ length
: -1, [Symbol
.isConcatSpreadable
]: true }),
105 [Symbol
.isConcatSpreadable
]: true,
111 length
: 9007199254740992,
112 [Symbol
.isConcatSpreadable
]: true,
118 it("[[Call]] returns true if length is an integer index and the object is concat spreadable", () => {
120 isCollection({ length
: 1, [Symbol
.isConcatSpreadable
]: true }),
124 isCollection({ length
: 0, [Symbol
.isConcatSpreadable
]: true }),
129 length
: 9007199254740991,
130 [Symbol
.isConcatSpreadable
]: true,
136 it("[[Call]] returns true if length can be converted to an index without throwing an error and the object is concat spreadable", () => {
138 isCollection({ length
: -0, [Symbol
.isConcatSpreadable
]: true }),
142 isCollection({ length
: NaN
, [Symbol
.isConcatSpreadable
]: true }),
148 describe("isConcatSpreadable", () => {
149 it("[[Call]] returns false for primitives", () => {
150 assertStrictEquals(isConcatSpreadable("failure"), false);
153 it("[[Call]] returns false if [Symbol.isConcatSpreadable] is null or false", () => {
156 Object
.assign([], { [Symbol
.isConcatSpreadable
]: null }),
162 Object
.assign([], { [Symbol
.isConcatSpreadable
]: false }),
168 it("[[Call]] returns true if [Symbol.isConcatSpreadable] is undefined and the object is an array", () => {
171 Object
.assign([], { [Symbol
.isConcatSpreadable
]: undefined }),
177 it("[[Call]] returns true if [Symbol.isConcatSpreadable] is true", () => {
179 isConcatSpreadable({ [Symbol
.isConcatSpreadable
]: true }),
This page took 0.059548 seconds and 3 git commands to generate.