]> Lady’s Gitweb - Pisces/blob - symbol.test.js
Define names and lengths for iterator functions
[Pisces] / symbol.test.js
1 // SPDX-FileCopyrightText: 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
2 // SPDX-License-Identifier: MPL-2.0
3 /**
4 * ⁌ ♓🧩 Piscēs ∷ symbol.test.js
5 *
6 * Copyright © 2023, 2025 Lady [@ Ladys Computer].
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
11 */
12
13 import {
14 assertStrictEquals,
15 assertThrows,
16 describe,
17 it,
18 } from "./dev-deps.js";
19 import {
20 getSymbolDescription,
21 symbolToString,
22 symbolValue,
23 } from "./symbol.js";
24
25 describe("getSymbolDescription", () => {
26 it("[[Call]] returns undefined when the symbol has no description", () => {
27 assertStrictEquals(getSymbolDescription(Symbol()), undefined);
28 });
29
30 it("[[Call]] returns the empty string when the symbol has an empty description", () => {
31 assertStrictEquals(getSymbolDescription(Symbol("")), "");
32 });
33
34 it("[[Call]] returns the description", () => {
35 assertStrictEquals(
36 getSymbolDescription(Symbol("etaoin")),
37 "etaoin",
38 );
39 });
40
41 it("[[Construct]] throws an error", () => {
42 assertThrows(() => new getSymbolDescription(Symbol()));
43 });
44
45 describe(".length", () => {
46 it("[[Get]] returns the correct length", () => {
47 assertStrictEquals(getSymbolDescription.length, 1);
48 });
49 });
50
51 describe(".name", () => {
52 it("[[Get]] returns the correct name", () => {
53 assertStrictEquals(
54 getSymbolDescription.name,
55 "getSymbolDescription",
56 );
57 });
58 });
59 });
60
61 describe("symbolToString", () => {
62 it('[[Call]] returns "Symbol()" when the symbol has no description', () => {
63 assertStrictEquals(symbolToString(Symbol()), "Symbol()");
64 });
65
66 it('[[Call]] returns "Symbol()" when the symbol has an empty description', () => {
67 assertStrictEquals(symbolToString(Symbol("")), "Symbol()");
68 });
69
70 it('[[Call]] returns "Symbol()" wrapping the description', () => {
71 assertStrictEquals(
72 symbolToString(Symbol("etaoin")),
73 "Symbol(etaoin)",
74 );
75 });
76
77 it("[[Construct]] throws an error", () => {
78 assertThrows(() => new symbolToString(Symbol()));
79 });
80
81 describe(".length", () => {
82 it("[[Get]] returns the correct length", () => {
83 assertStrictEquals(symbolToString.length, 1);
84 });
85 });
86
87 describe(".name", () => {
88 it("[[Get]] returns the correct name", () => {
89 assertStrictEquals(
90 symbolToString.name,
91 "symbolToString",
92 );
93 });
94 });
95 });
96
97 describe("symbolValue", () => {
98 it("[[Call]] returns the value of a symbol", () => {
99 const symbol = Symbol();
100 assertStrictEquals(symbolValue(symbol), symbol);
101 });
102
103 it("[[Call]] returns the value of a symbol wrapper", () => {
104 const symbol = Symbol();
105 assertStrictEquals(symbolValue(new Object(symbol)), symbol);
106 });
107
108 it("[[Call]] returns the value of a symbol subclass", () => {
109 class SymbolExtension extends Symbol {
110 constructor(symbol) {
111 return Object.setPrototypeOf(
112 new Object(symbol),
113 SymbolExtension.prototype,
114 );
115 }
116 }
117 const symbol = Symbol();
118 assertStrictEquals(
119 symbolValue(new SymbolExtension(symbol)),
120 symbol,
121 );
122 });
123
124 it("[[Construct]] throws an error", () => {
125 assertThrows(() => new symbolValue(Symbol()));
126 });
127
128 describe(".length", () => {
129 it("[[Get]] returns the correct length", () => {
130 assertStrictEquals(symbolValue.length, 1);
131 });
132 });
133
134 describe(".name", () => {
135 it("[[Get]] returns the correct name", () => {
136 assertStrictEquals(
137 symbolValue.name,
138 "symbolValue",
139 );
140 });
141 });
142 });
This page took 0.456754 seconds and 5 git commands to generate.