| 1 |
import * as evaluator from "../../_namespaces/evaluator"; |
| 2 |
import * as ts from "../../_namespaces/ts"; |
| 3 |
|
| 4 |
describe("unittests:: evaluation:: updateExpressionInModule", () => { |
| 5 |
// only run BigInt tests if BigInt is supported in the host environment |
| 6 |
const itIfBigInt = typeof BigInt === "function" ? it : it.skip; |
| 7 |
|
| 8 |
it("pre-increment in commonjs using Number", () => { |
| 9 |
const result = evaluator.evaluateTypeScript({ |
| 10 |
files: { |
| 11 |
"/.src/main.ts": ` |
| 12 |
let a = 1; |
| 13 |
export { a }; |
| 14 |
export const b = ++a; |
| 15 |
` |
| 16 |
}, |
| 17 |
rootFiles: ["/.src/main.ts"], |
| 18 |
main: "/.src/main.ts" |
| 19 |
}, { module: ts.ModuleKind.CommonJS }); |
| 20 |
assert.equal(result.a, 2); |
| 21 |
assert.equal(result.b, 2); |
| 22 |
}); |
| 23 |
it("pre-increment in System using Number", () => { |
| 24 |
const result = evaluator.evaluateTypeScript({ |
| 25 |
files: { |
| 26 |
"/.src/main.ts": ` |
| 27 |
let a = 1; |
| 28 |
export { a }; |
| 29 |
export const b = ++a; |
| 30 |
` |
| 31 |
}, |
| 32 |
rootFiles: ["/.src/main.ts"], |
| 33 |
main: "/.src/main.ts" |
| 34 |
}, { module: ts.ModuleKind.System }); |
| 35 |
assert.equal(result.a, 2); |
| 36 |
assert.equal(result.b, 2); |
| 37 |
}); |
| 38 |
itIfBigInt("pre-increment in commonjs using BigInt", () => { |
| 39 |
const result = evaluator.evaluateTypeScript({ |
| 40 |
files: { |
| 41 |
"/.src/main.ts": ` |
| 42 |
let a = BigInt(1); |
| 43 |
export { a }; |
| 44 |
export const b = ++a; |
| 45 |
` |
| 46 |
}, |
| 47 |
rootFiles: ["/.src/main.ts"], |
| 48 |
main: "/.src/main.ts" |
| 49 |
}, { module: ts.ModuleKind.CommonJS }, { BigInt }); |
| 50 |
assert.equal(result.a, BigInt(2)); |
| 51 |
assert.equal(result.b, BigInt(2)); |
| 52 |
}); |
| 53 |
itIfBigInt("pre-increment in System using BigInt", () => { |
| 54 |
const result = evaluator.evaluateTypeScript({ |
| 55 |
files: { |
| 56 |
"/.src/main.ts": ` |
| 57 |
let a = BigInt(1); |
| 58 |
export { a }; |
| 59 |
export const b = ++a; |
| 60 |
` |
| 61 |
}, |
| 62 |
rootFiles: ["/.src/main.ts"], |
| 63 |
main: "/.src/main.ts" |
| 64 |
}, { module: ts.ModuleKind.System }, { BigInt }); |
| 65 |
assert.equal(result.a, BigInt(2)); |
| 66 |
assert.equal(result.b, BigInt(2)); |
| 67 |
}); |
| 68 |
it("post-increment in commonjs using Number", () => { |
| 69 |
const result = evaluator.evaluateTypeScript({ |
| 70 |
files: { |
| 71 |
"/.src/main.ts": ` |
| 72 |
let a = 1; |
| 73 |
export { a }; |
| 74 |
export const b = a++; |
| 75 |
` |
| 76 |
}, |
| 77 |
rootFiles: ["/.src/main.ts"], |
| 78 |
main: "/.src/main.ts" |
| 79 |
}, { module: ts.ModuleKind.CommonJS }); |
| 80 |
assert.equal(result.a, 2); |
| 81 |
assert.equal(result.b, 1); |
| 82 |
}); |
| 83 |
it("post-increment in System using Number", () => { |
| 84 |
const result = evaluator.evaluateTypeScript({ |
| 85 |
files: { |
| 86 |
"/.src/main.ts": ` |
| 87 |
let a = 1; |
| 88 |
export { a }; |
| 89 |
export const b = a++; |
| 90 |
` |
| 91 |
}, |
| 92 |
rootFiles: ["/.src/main.ts"], |
| 93 |
main: "/.src/main.ts" |
| 94 |
}, { module: ts.ModuleKind.System }); |
| 95 |
assert.equal(result.a, 2); |
| 96 |
assert.equal(result.b, 1); |
| 97 |
}); |
| 98 |
itIfBigInt("post-increment in commonjs using BigInt", () => { |
| 99 |
const result = evaluator.evaluateTypeScript({ |
| 100 |
files: { |
| 101 |
"/.src/main.ts": ` |
| 102 |
let a = BigInt(1); |
| 103 |
export { a }; |
| 104 |
export const b = a++; |
| 105 |
` |
| 106 |
}, |
| 107 |
rootFiles: ["/.src/main.ts"], |
| 108 |
main: "/.src/main.ts" |
| 109 |
}, { module: ts.ModuleKind.CommonJS }, { BigInt }); |
| 110 |
assert.equal(result.a, BigInt(2)); |
| 111 |
assert.equal(result.b, BigInt(1)); |
| 112 |
}); |
| 113 |
itIfBigInt("post-increment in System using BigInt", () => { |
| 114 |
const result = evaluator.evaluateTypeScript({ |
| 115 |
files: { |
| 116 |
"/.src/main.ts": ` |
| 117 |
let a = BigInt(1); |
| 118 |
export { a }; |
| 119 |
export const b = a++; |
| 120 |
` |
| 121 |
}, |
| 122 |
rootFiles: ["/.src/main.ts"], |
| 123 |
main: "/.src/main.ts" |
| 124 |
}, { module: ts.ModuleKind.System }, { BigInt }); |
| 125 |
assert.equal(result.a, BigInt(2)); |
| 126 |
assert.equal(result.b, BigInt(1)); |
| 127 |
}); |
| 128 |
}); |