]> Lady’s Gitweb - Pisces/blob - symbol.test.js
Add symbolToString and symbolValue to symbol.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(".name", () => {
43 it("[[Get]] returns the correct name", () => {
44 assertStrictEquals(
45 getSymbolDescription.name,
46 "getSymbolDescription",
47 );
48 });
49 });
50 });
51
52 describe("symbolToString", () => {
53 it('[[Call]] returns "Symbol()" when the symbol has no description', () => {
54 assertStrictEquals(symbolToString(Symbol()), "Symbol()");
55 });
56
57 it('[[Call]] returns "Symbol()" when the symbol has an empty description', () => {
58 assertStrictEquals(symbolToString(Symbol("")), "Symbol()");
59 });
60
61 it('[[Call]] returns "Symbol()" wrapping the description', () => {
62 assertStrictEquals(
63 symbolToString(Symbol("etaoin")),
64 "Symbol(etaoin)",
65 );
66 });
67
68 it("[[Construct]] throws an error", () => {
69 assertThrows(() => new symbolToString(Symbol()));
70 });
71
72 describe(".name", () => {
73 it("[[Get]] returns the correct name", () => {
74 assertStrictEquals(
75 symbolToString.name,
76 "symbolToString",
77 );
78 });
79 });
80 });
81
82 describe("symbolValue", () => {
83 it("[[Call]] returns the value of a symbol", () => {
84 const symbol = Symbol();
85 assertStrictEquals(symbolValue(symbol), symbol);
86 });
87
88 it("[[Call]] returns the value of a symbol wrapper", () => {
89 const symbol = Symbol();
90 assertStrictEquals(symbolValue(new Object(symbol)), symbol);
91 });
92
93 it("[[Call]] returns the value of a symbol subclass", () => {
94 class SymbolExtension extends Symbol {
95 constructor(symbol) {
96 return Object.setPrototypeOf(
97 new Object(symbol),
98 SymbolExtension.prototype,
99 );
100 }
101 }
102 const symbol = Symbol();
103 assertStrictEquals(
104 symbolValue(new SymbolExtension(symbol)),
105 symbol,
106 );
107 });
108
109 it("[[Construct]] throws an error", () => {
110 assertThrows(() => new symbolValue(Symbol()));
111 });
112
113 describe(".name", () => {
114 it("[[Get]] returns the correct name", () => {
115 assertStrictEquals(
116 symbolValue.name,
117 "symbolValue",
118 );
119 });
120 });
121 });
This page took 0.208082 seconds and 5 git commands to generate.