|
| 1 | +import { Expect, Test, TestCase, FocusTest } from "alsatian"; |
| 2 | + |
| 3 | +import * as util from "../src/util"; |
| 4 | + |
| 5 | +export class OverloadTests { |
| 6 | + |
| 7 | + @TestCase("0") |
| 8 | + @TestCase("30") |
| 9 | + @TestCase("30_000") |
| 10 | + @TestCase("30.00") |
| 11 | + @Test("typeof number") |
| 12 | + @FocusTest |
| 13 | + public typeofNumberTest(inp: string) { |
| 14 | + const lua = util.transpileString(`return typeof ${inp};`); |
| 15 | + const result = util.executeLua(lua); |
| 16 | + |
| 17 | + Expect(result).toBe("number"); |
| 18 | + } |
| 19 | + |
| 20 | + @TestCase("\"abc\"") |
| 21 | + @TestCase("`abc`") |
| 22 | + @Test("typeof string") |
| 23 | + public typeofStringTest(inp: string) { |
| 24 | + const lua = util.transpileString(`return typeof ${inp};`); |
| 25 | + const result = util.executeLua(lua); |
| 26 | + |
| 27 | + Expect(result).toBe("string"); |
| 28 | + } |
| 29 | + |
| 30 | + @TestCase("false") |
| 31 | + @TestCase("true") |
| 32 | + @Test("typeof boolean") |
| 33 | + public typeofBooleanTest(inp: string) { |
| 34 | + const lua = util.transpileString(`return typeof ${inp};`); |
| 35 | + const result = util.executeLua(lua); |
| 36 | + |
| 37 | + Expect(result).toBe("boolean"); |
| 38 | + } |
| 39 | + |
| 40 | + @Test("{}") |
| 41 | + @Test("[]") |
| 42 | + @Test("typeof object literal") |
| 43 | + public typeofObjectLiteral(inp: string) { |
| 44 | + const lua = util.transpileString(`return typeof ${inp};`); |
| 45 | + const result = util.executeLua(lua); |
| 46 | + |
| 47 | + Expect(result).toBe("table"); |
| 48 | + } |
| 49 | + |
| 50 | + @Test("typeof class instance") |
| 51 | + public typeofClassInstance() { |
| 52 | + const lua = util.transpileString(`class myClass {} let inst = new myClass(); return typeof inst;`); |
| 53 | + const result = util.executeLua(lua); |
| 54 | + |
| 55 | + Expect(result).toBe("table"); |
| 56 | + } |
| 57 | + |
| 58 | + @Test("null") |
| 59 | + @Test("undefined") |
| 60 | + @Test("typeof undefined") |
| 61 | + public typeofUndefinedTest(inp: string) { |
| 62 | + const lua = util.transpileString(`return typeof ${inp};`); |
| 63 | + const result = util.executeLua(lua); |
| 64 | + |
| 65 | + Expect(result).toBe("nil"); |
| 66 | + } |
| 67 | +} |
0 commit comments