X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/ee0f6916f2f56f17bd232f964fec9a4c7ed6ec89..HEAD:/symbol.test.js diff --git a/symbol.test.js b/symbol.test.js index bedcc72..03abffc 100644 --- a/symbol.test.js +++ b/symbol.test.js @@ -13,7 +13,11 @@ import { describe, it, } from "./dev-deps.js"; -import { getSymbolDescription } from "./symbol.js"; +import { + getSymbolDescription, + symbolToString, + symbolValue, +} from "./symbol.js"; describe("getSymbolDescription", () => { it("[[Call]] returns undefined when the symbol has no description", () => { @@ -31,14 +35,16 @@ describe("getSymbolDescription", () => { ); }); - it("[[Call]] returns the empty string when the symbol has an empty description", () => { - assertStrictEquals(getSymbolDescription(Symbol("")), ""); - }); - it("[[Construct]] throws an error", () => { assertThrows(() => new getSymbolDescription(Symbol())); }); + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(getSymbolDescription.length, 1); + }); + }); + describe(".name", () => { it("[[Get]] returns the correct name", () => { assertStrictEquals( @@ -48,3 +54,86 @@ describe("getSymbolDescription", () => { }); }); }); + +describe("symbolToString", () => { + it('[[Call]] returns "Symbol()" when the symbol has no description', () => { + assertStrictEquals(symbolToString(Symbol()), "Symbol()"); + }); + + it('[[Call]] returns "Symbol()" when the symbol has an empty description', () => { + assertStrictEquals(symbolToString(Symbol("")), "Symbol()"); + }); + + it('[[Call]] returns "Symbol()" wrapping the description', () => { + assertStrictEquals( + symbolToString(Symbol("etaoin")), + "Symbol(etaoin)", + ); + }); + + it("[[Construct]] throws an error", () => { + assertThrows(() => new symbolToString(Symbol())); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(symbolToString.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + symbolToString.name, + "symbolToString", + ); + }); + }); +}); + +describe("symbolValue", () => { + it("[[Call]] returns the value of a symbol", () => { + const symbol = Symbol(); + assertStrictEquals(symbolValue(symbol), symbol); + }); + + it("[[Call]] returns the value of a symbol wrapper", () => { + const symbol = Symbol(); + assertStrictEquals(symbolValue(new Object(symbol)), symbol); + }); + + it("[[Call]] returns the value of a symbol subclass", () => { + class SymbolExtension extends Symbol { + constructor(symbol) { + return Object.setPrototypeOf( + new Object(symbol), + SymbolExtension.prototype, + ); + } + } + const symbol = Symbol(); + assertStrictEquals( + symbolValue(new SymbolExtension(symbol)), + symbol, + ); + }); + + it("[[Construct]] throws an error", () => { + assertThrows(() => new symbolValue(Symbol())); + }); + + describe(".length", () => { + it("[[Get]] returns the correct length", () => { + assertStrictEquals(symbolValue.length, 1); + }); + }); + + describe(".name", () => { + it("[[Get]] returns the correct name", () => { + assertStrictEquals( + symbolValue.name, + "symbolValue", + ); + }); + }); +});