]>
Lady’s Gitweb - Pisces/blob - collection.test.js
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";
19 import { findIndexedEntry
, isCollection
} from "./collection.js";
21 describe("findIndexedEntry", () => {
22 it("[[Call]] returns undefined if no matching entry exists", () => {
23 assertStrictEquals(findIndexedEntry([], () => true), void {});
24 assertStrictEquals(findIndexedEntry([1], () => false), void {});
27 it("[[Call]] returns an entry for the first match", () => {
29 findIndexedEntry([, true, false], ($) => $ ?? true),
33 findIndexedEntry(["failure", "success"], ($) => $ == "success"),
38 it("[[Call]] works on arraylike objects", () => {
40 findIndexedEntry({ 1: "success", length
: 2 }, ($) => $),
44 findIndexedEntry({ 1: "failure", length
: 1 }, ($) => $),
49 it("[[Call]] only gets the value once", () => {
50 const get1
= spy(() => true);
57 assertSpyCalls(get1
, 1);
60 it("[[Call]] passes the value, index, and this value to the callback", () => {
61 const arr
= ["failure", "success", "success"];
62 const callback
= spy(($) => $ === "success");
64 findIndexedEntry(arr
, callback
, thisArg
);
65 assertSpyCalls(callback
, 2);
66 assertSpyCall(callback
, 0, {
67 args
: ["failure", 0, arr
],
70 assertSpyCall(callback
, 1, {
71 args
: ["success", 1, arr
],
77 describe("isCollection", () => {
78 it("[[Call]] returns false for primitives", () => {
79 assertStrictEquals(isCollection("failure"), false);
82 it("[[Call]] returns false if length throws", () => {
93 it("[[Call]] returns false if length is not an integer index and cannot be converted to one", () => {
95 isCollection({ length
: -1, [Symbol
.isConcatSpreadable
]: true }),
101 [Symbol
.isConcatSpreadable
]: true,
107 length
: 9007199254740992,
108 [Symbol
.isConcatSpreadable
]: true,
114 it("[[Call]] returns true if length is an integer index and the object is concat spreadable", () => {
116 isCollection({ length
: 1, [Symbol
.isConcatSpreadable
]: true }),
120 isCollection({ length
: 0, [Symbol
.isConcatSpreadable
]: true }),
125 length
: 9007199254740991,
126 [Symbol
.isConcatSpreadable
]: true,
132 it("[[Call]] returns true if length can be converted to an index without throwing an error and the object is concat spreadable", () => {
134 isCollection({ length
: -0, [Symbol
.isConcatSpreadable
]: true }),
138 isCollection({ length
: NaN
, [Symbol
.isConcatSpreadable
]: true }),
This page took 0.116268 seconds and 5 git commands to generate.