|
1 | | -import { Expect, Test, TestCase } from "alsatian"; |
| 1 | +import { Expect, Test, TestCase, FocusTest } from "alsatian"; |
| 2 | +import { LuaTarget } from "../../src/Transpiler"; |
2 | 3 |
|
3 | 4 | import * as ts from "typescript"; |
4 | 5 | import * as util from "../src/util"; |
@@ -196,4 +197,63 @@ export class ExpressionTests { |
196 | 197 | // Assert |
197 | 198 | Expect(result).toBe(v1 + v2); |
198 | 199 | } |
| 200 | + |
| 201 | + @TestCase("inst.field", 8) |
| 202 | + @TestCase("inst.field + 3", 8 + 3) |
| 203 | + @TestCase("inst.field * 3", 8 * 3) |
| 204 | + @TestCase("inst.field / 3", 8 / 3) |
| 205 | + @TestCase("inst.field && 3", 8 && 3) |
| 206 | + @TestCase("inst.field || 3", 8 || 3) |
| 207 | + // @TestCase("inst.field & 3", 8 & 3) |
| 208 | + // @TestCase("inst.field | 3", 8 | 3) |
| 209 | + // @TestCase("inst.field << 3", 8 << 3) |
| 210 | + // @TestCase("inst.field >> 1", 8 >> 1) |
| 211 | + @TestCase(`"abc" + inst.field`, "abc8") |
| 212 | + public getAccessorBinary(expression: string, expected: any) { |
| 213 | + const source = `class MyClass {` |
| 214 | + + ` public _field: number;` |
| 215 | + + ` public get field(): number { return this._field + 4; }` |
| 216 | + + ` public set field(v: number) { this._field = v; }` |
| 217 | + + `}` |
| 218 | + + `var inst = new MyClass();` |
| 219 | + + `inst._field = 4;` |
| 220 | + + `return ${expression};`; |
| 221 | + |
| 222 | + // Transpile |
| 223 | + const lua = util.transpileString(source); |
| 224 | + |
| 225 | + // Execute |
| 226 | + const result = util.executeLua(lua); |
| 227 | + |
| 228 | + // Assert |
| 229 | + Expect(result).toBe(expected); |
| 230 | + } |
| 231 | + |
| 232 | + @TestCase("= 4", 4 + 4) |
| 233 | + @TestCase("+= 3", 4 + 3 + 4) |
| 234 | + @TestCase("*= 3", 4 * 3 + 4) |
| 235 | + @TestCase("/= 3", 4 / 3 + 4) |
| 236 | + // @TestCase("&= 3", 4 & 3 + 4) |
| 237 | + // @TestCase("|= 3", 4 | 3 + 4) |
| 238 | + // @TestCase("<<= 3", 4 << 3 + 4) |
| 239 | + // @TestCase(">>= 3", 4 >> 3 + 4) |
| 240 | + public setAccessorBinary(expression: string, expected: any) { |
| 241 | + const source = `class MyClass {` |
| 242 | + + ` public _field: number = 4;` |
| 243 | + + ` public get field(): number { return this._field; }` |
| 244 | + + ` public set field(v: number) { this._field = v + 4; }` |
| 245 | + + `}` |
| 246 | + + `var inst = new MyClass();` |
| 247 | + + `inst.field ${expression};` |
| 248 | + + `return inst._field;`; |
| 249 | + |
| 250 | + // Transpile |
| 251 | + const lua = util.transpileString(source); |
| 252 | + |
| 253 | + // Execute |
| 254 | + const result = util.executeLua(lua); |
| 255 | + |
| 256 | + // Assert |
| 257 | + Expect(result).toBe(expected); |
| 258 | + } |
199 | 259 | } |
0 commit comments