]> Lady’s Gitweb - Pisces/blob - symbol.test.js
Add methods for own entries and values to object.js
[Pisces] / symbol.test.js
1 // ♓🌟 Piscēs ∷ symbol.test.js
2 // ====================================================================
3 //
4 // Copyright © 2023 Lady [@ Lady’s Computer].
5 //
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/>.
9
10 import {
11 assertStrictEquals,
12 assertThrows,
13 describe,
14 it,
15 } from "./dev-deps.js";
16 import {
17 getSymbolDescription,
18 symbolToString,
19 symbolValue,
20 } from "./symbol.js";
21
22 describe("getSymbolDescription", () => {
23 it("[[Call]] returns undefined when the symbol has no description", () => {
24 assertStrictEquals(getSymbolDescription(Symbol()), undefined);
25 });
26
27 it("[[Call]] returns the empty string when the symbol has an empty description", () => {
28 assertStrictEquals(getSymbolDescription(Symbol("")), "");
29 });
30
31 it("[[Call]] returns the description", () => {
32 assertStrictEquals(
33 getSymbolDescription(Symbol("etaoin")),
34 "etaoin",
35 );
36 });
37
38 it("[[Construct]] throws an error", () => {
39 assertThrows(() => new getSymbolDescription(Symbol()));
40 });
41
42 describe(".length", () => {
43 it("[[Get]] returns the correct length", () => {
44 assertStrictEquals(getSymbolDescription.length, 1);
45 });
46 });
47
48 describe(".name", () => {
49 it("[[Get]] returns the correct name", () => {
50 assertStrictEquals(
51 getSymbolDescription.name,
52 "getSymbolDescription",
53 );
54 });
55 });
56 });
57
58 describe("symbolToString", () => {
59 it('[[Call]] returns "Symbol()" when the symbol has no description', () => {
60 assertStrictEquals(symbolToString(Symbol()), "Symbol()");
61 });
62
63 it('[[Call]] returns "Symbol()" when the symbol has an empty description', () => {
64 assertStrictEquals(symbolToString(Symbol("")), "Symbol()");
65 });
66
67 it('[[Call]] returns "Symbol()" wrapping the description', () => {
68 assertStrictEquals(
69 symbolToString(Symbol("etaoin")),
70 "Symbol(etaoin)",
71 );
72 });
73
74 it("[[Construct]] throws an error", () => {
75 assertThrows(() => new symbolToString(Symbol()));
76 });
77
78 describe(".length", () => {
79 it("[[Get]] returns the correct length", () => {
80 assertStrictEquals(symbolToString.length, 1);
81 });
82 });
83
84 describe(".name", () => {
85 it("[[Get]] returns the correct name", () => {
86 assertStrictEquals(
87 symbolToString.name,
88 "symbolToString",
89 );
90 });
91 });
92 });
93
94 describe("symbolValue", () => {
95 it("[[Call]] returns the value of a symbol", () => {
96 const symbol = Symbol();
97 assertStrictEquals(symbolValue(symbol), symbol);
98 });
99
100 it("[[Call]] returns the value of a symbol wrapper", () => {
101 const symbol = Symbol();
102 assertStrictEquals(symbolValue(new Object(symbol)), symbol);
103 });
104
105 it("[[Call]] returns the value of a symbol subclass", () => {
106 class SymbolExtension extends Symbol {
107 constructor(symbol) {
108 return Object.setPrototypeOf(
109 new Object(symbol),
110 SymbolExtension.prototype,
111 );
112 }
113 }
114 const symbol = Symbol();
115 assertStrictEquals(
116 symbolValue(new SymbolExtension(symbol)),
117 symbol,
118 );
119 });
120
121 it("[[Construct]] throws an error", () => {
122 assertThrows(() => new symbolValue(Symbol()));
123 });
124
125 describe(".length", () => {
126 it("[[Get]] returns the correct length", () => {
127 assertStrictEquals(symbolValue.length, 1);
128 });
129 });
130
131 describe(".name", () => {
132 it("[[Get]] returns the correct name", () => {
133 assertStrictEquals(
134 symbolValue.name,
135 "symbolValue",
136 );
137 });
138 });
139 });
This page took 0.060584 seconds and 5 git commands to generate.