| 1 |
import * as evaluator from "../../_namespaces/evaluator"; |
| 2 |
import * as ts from "../../_namespaces/ts"; |
| 3 |
|
| 4 |
describe("unittests:: evaluation:: generatorEvaluation", () => { |
| 5 |
it("throw before start (es5)", () => { |
| 6 |
const { gen, output } = evaluator.evaluateTypeScript(` |
| 7 |
export const output: string[] = []; |
| 8 |
export function * gen() { |
| 9 |
output.push("start"); |
| 10 |
yield 1; |
| 11 |
output.push("end"); |
| 12 |
} |
| 13 |
`, { target: ts.ScriptTarget.ES5 }); |
| 14 |
|
| 15 |
const g = gen(); |
| 16 |
const e = new Error(); |
| 17 |
assert.throws(() => g.throw(e), e); |
| 18 |
assert.deepEqual(g.next(), { value: undefined, done: true }); |
| 19 |
assert.deepEqual(output, []); |
| 20 |
}); |
| 21 |
it("return before start (es5)", () => { |
| 22 |
const { gen, output } = evaluator.evaluateTypeScript(` |
| 23 |
export const output: string[] = []; |
| 24 |
export function * gen() { |
| 25 |
output.push("start"); |
| 26 |
yield 1; |
| 27 |
output.push("end"); |
| 28 |
} |
| 29 |
`, { target: ts.ScriptTarget.ES5 }); |
| 30 |
|
| 31 |
const g = gen(); |
| 32 |
assert.deepEqual(g.return(2), { value: 2, done: true }); |
| 33 |
assert.deepEqual(g.next(), { value: undefined, done: true }); |
| 34 |
assert.deepEqual(output, []); |
| 35 |
}); |
| 36 |
}); |