X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/bf3fe705a9d5f717b3c1794a12726e926ece7ecc..e1cb83c479df2a3e4a5e918867a135ff9dde8121:/iterable.test.js diff --git a/iterable.test.js b/iterable.test.js index 2e62d5c..3651c6c 100644 --- a/iterable.test.js +++ b/iterable.test.js @@ -1,11 +1,14 @@ -// ♓🌟 Piscēs ∷ iterable.test.js -// ==================================================================== -// -// Copyright © 2023 Lady [@ Lady’s Computer]. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at . +// SPDX-FileCopyrightText: 2023, 2025 Lady +// SPDX-License-Identifier: MPL-2.0 +/** + * ⁌ ♓🧩 Piscēs ∷ iterable.test.js + * + * Copyright © 2023, 2025 Lady [@ Ladys Computer]. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at . + */ import { assertEquals, @@ -34,6 +37,25 @@ describe("arrayIteratorFunction", () => { ); }); + it("[[Construct]] throws an error", () => { + assertThrows(() => new arrayIteratorFunction()); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(arrayIteratorFunction.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + arrayIteratorFunction.name, + "arrayIteratorFunction", + ); + }); + }); + describe("()", () => { it("[[Call]] returns a value which inherits from %IteratorPrototype%", () => { const iteratorProto = Object.getPrototypeOf( @@ -107,6 +129,26 @@ describe("arrayIteratorFunction", () => { }); }); + it("[[Construct]] throws an error", () => { + const iterator = arrayIteratorFunction(); + assertThrows(() => new iterator([])); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(arrayIteratorFunction().length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + arrayIteratorFunction().name, + "values", + ); + }); + }); + describe("::next", () => { it("[[Call]] throws if there are values and the mapper is not a generator function", () => { const iterator = arrayIteratorFunction(function () {}); @@ -130,6 +172,25 @@ describe("generatorIteratorFunction", () => { ); }); + it("[[Construct]] throws an error", () => { + assertThrows(() => new generatorIteratorFunction()); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(generatorIteratorFunction.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + generatorIteratorFunction.name, + "generatorIteratorFunction", + ); + }); + }); + describe("()", () => { it("[[Call]] returns a value which inherits from %IteratorPrototype%", () => { const iteratorProto = Object.getPrototypeOf( @@ -215,6 +276,26 @@ describe("generatorIteratorFunction", () => { }); }); + it("[[Construct]] throws an error", () => { + const iterator = generatorIteratorFunction(); + assertThrows(() => new iterator(function* () {})); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(generatorIteratorFunction().length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + generatorIteratorFunction().name, + "yields", + ); + }); + }); + describe("::next", () => { it("[[Call]] throws if there are values and the mapper is not a generator function", () => { const generator = function* () { @@ -248,6 +329,25 @@ describe("mapIteratorFunction", () => { ); }); + it("[[Construct]] throws an error", () => { + assertThrows(() => new mapIteratorFunction()); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(mapIteratorFunction.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + mapIteratorFunction.name, + "mapIteratorFunction", + ); + }); + }); + describe("()", () => { it("[[Call]] returns a value which inherits from %IteratorPrototype%", () => { const iteratorProto = Object.getPrototypeOf( @@ -321,6 +421,26 @@ describe("mapIteratorFunction", () => { }); }); + it("[[Construct]] throws an error", () => { + const iterator = mapIteratorFunction(); + assertThrows(() => new iterator(new Map())); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(mapIteratorFunction().length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + mapIteratorFunction().name, + "entries", + ); + }); + }); + describe("::next", () => { it("[[Call]] throws if there are values and the mapper is not a generator function", () => { const iterator = mapIteratorFunction(function () {}); @@ -344,6 +464,25 @@ describe("setIteratorFunction", () => { ); }); + it("[[Construct]] throws an error", () => { + assertThrows(() => new setIteratorFunction()); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(setIteratorFunction.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + setIteratorFunction.name, + "setIteratorFunction", + ); + }); + }); + describe("()", () => { it("[[Call]] returns a value which inherits from %IteratorPrototype%", () => { const iteratorProto = Object.getPrototypeOf( @@ -417,6 +556,26 @@ describe("setIteratorFunction", () => { }); }); + it("[[Construct]] throws an error", () => { + const iterator = setIteratorFunction(); + assertThrows(() => new iterator(new Set())); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(setIteratorFunction().length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + setIteratorFunction().name, + "values", + ); + }); + }); + describe("::next", () => { it("[[Call]] throws if there are values and the mapper is not a generator function", () => { const iterator = setIteratorFunction(function () {}); @@ -440,6 +599,25 @@ describe("stringIteratorFunction", () => { ); }); + it("[[Construct]] throws an error", () => { + assertThrows(() => new stringIteratorFunction()); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(stringIteratorFunction.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + stringIteratorFunction.name, + "stringIteratorFunction", + ); + }); + }); + describe("()", () => { it("[[Call]] returns a value which inherits from %IteratorPrototype%", () => { const iteratorProto = Object.getPrototypeOf( @@ -518,6 +696,26 @@ describe("stringIteratorFunction", () => { }); }); + it("[[Construct]] throws an error", () => { + const iterator = stringIteratorFunction(); + assertThrows(() => new iterator("")); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(stringIteratorFunction().length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + stringIteratorFunction().name, + "characters", + ); + }); + }); + describe("::next", () => { it("[[Call]] throws if there are values and the mapper is not a generator function", () => { const iterator = stringIteratorFunction(function () {});