|
| 1 | +import { Expect, Test, TestCase } from "alsatian"; |
| 2 | +import * as util from "../../src/util"; |
| 3 | +import { CompilerOptions, LuaLibImportKind } from '../../../src/CompilerOptions'; |
| 4 | + |
| 5 | +export class SymbolTests { |
| 6 | + private compilerOptions: CompilerOptions = { |
| 7 | + lib: ["esnext"], |
| 8 | + luaLibImport: LuaLibImportKind.Require, |
| 9 | + }; |
| 10 | + |
| 11 | + @Test("symbol.toString()") |
| 12 | + @TestCase() |
| 13 | + @TestCase(1) |
| 14 | + @TestCase("name") |
| 15 | + public symbolToString(description?: string | number): void |
| 16 | + { |
| 17 | + const result = util.transpileAndExecute(` |
| 18 | + return Symbol(${JSON.stringify(description)}).toString(); |
| 19 | + `, this.compilerOptions); |
| 20 | + |
| 21 | + Expect(result).toBe(`Symbol(${description || ''})`); |
| 22 | + } |
| 23 | + |
| 24 | + @Test("symbol.description") |
| 25 | + @TestCase() |
| 26 | + @TestCase(1) |
| 27 | + @TestCase("name") |
| 28 | + public symbolDescription(description?: string | number): void |
| 29 | + { |
| 30 | + const result = util.transpileAndExecute(` |
| 31 | + return Symbol(${JSON.stringify(description)}).description; |
| 32 | + `, this.compilerOptions); |
| 33 | + |
| 34 | + Expect(result).toBe(description); |
| 35 | + } |
| 36 | + |
| 37 | + @Test("Symbol.for") |
| 38 | + public symbolFor(): void |
| 39 | + { |
| 40 | + const result = util.transpileAndExecute(` |
| 41 | + return Symbol.for("name").description; |
| 42 | + `, this.compilerOptions); |
| 43 | + |
| 44 | + Expect(result).toBe("name"); |
| 45 | + } |
| 46 | + |
| 47 | + @Test("Symbol.for reference") |
| 48 | + public symbolForReference(): void |
| 49 | + { |
| 50 | + const result = util.transpileAndExecute(` |
| 51 | + return Symbol.for("a") === Symbol.for("a"); |
| 52 | + `); |
| 53 | + |
| 54 | + Expect(result).toBe(true); |
| 55 | + } |
| 56 | + |
| 57 | + @Test("Symbol.keyFor") |
| 58 | + public symbolKeyFor(): void |
| 59 | + { |
| 60 | + const result = util.transpileAndExecute(` |
| 61 | + const sym = Symbol.for("a"); |
| 62 | + Symbol.for("b"); |
| 63 | + return Symbol.keyFor(sym); |
| 64 | + `); |
| 65 | + |
| 66 | + Expect(result).toBe("a"); |
| 67 | + } |
| 68 | + |
| 69 | + @Test("Symbol.keyFor empty") |
| 70 | + public symbolKeyForEmpty(): void |
| 71 | + { |
| 72 | + const result = util.transpileAndExecute(` |
| 73 | + Symbol.for("a"); |
| 74 | + return Symbol.keyFor(Symbol()); |
| 75 | + `); |
| 76 | + |
| 77 | + Expect(result).toBe(undefined); |
| 78 | + } |
| 79 | +} |
0 commit comments