|
| 1 | +import type { KipperCompileResult, KipperError } from "@kipper/core"; |
| 2 | +import { KipperCompiler } from "@kipper/core"; |
| 3 | +import { defaultConfig, ensureTracebackDataExists } from "../index"; |
| 4 | +import { assert } from "chai"; |
| 5 | + |
| 6 | +describe("InvalidErrorBindingTypeError", () => { |
| 7 | + describe("Error", () => { |
| 8 | + it("num error binding", async () => { |
| 9 | + try { |
| 10 | + await new KipperCompiler().compile("try {} catch (e: num) {}", defaultConfig); |
| 11 | + } catch (e) { |
| 12 | + assert.equal((<KipperError>e).constructor.name, "InvalidErrorBindingTypeError", "Expected different error"); |
| 13 | + assert.equal((<KipperError>e).name, "TypeError", "Expected different error"); |
| 14 | + ensureTracebackDataExists(<KipperError>e); |
| 15 | + return; |
| 16 | + } |
| 17 | + assert.fail("Expected 'InvalidErrorBindingTypeError'"); |
| 18 | + }); |
| 19 | + |
| 20 | + it("interface error binding", async () => { |
| 21 | + try { |
| 22 | + await new KipperCompiler().compile("interface A {}; try {} catch (e: A) {}", defaultConfig); |
| 23 | + } catch (e) { |
| 24 | + assert.equal((<KipperError>e).constructor.name, "InvalidErrorBindingTypeError", "Expected different error"); |
| 25 | + assert.equal((<KipperError>e).name, "TypeError", "Expected different error"); |
| 26 | + ensureTracebackDataExists(<KipperError>e); |
| 27 | + return; |
| 28 | + } |
| 29 | + assert.fail("Expected 'InvalidErrorBindingTypeError'"); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + describe("No Error", () => { |
| 34 | + it("no error type", async () => { |
| 35 | + let result: KipperCompileResult | undefined = undefined; |
| 36 | + try { |
| 37 | + result = await new KipperCompiler().compile("try {} catch (e) {}", defaultConfig); |
| 38 | + } catch (e) { |
| 39 | + assert.fail(`Expected no '${(<KipperError>e).name}'`); |
| 40 | + } |
| 41 | + assert.isDefined(result, "Expected defined compilation result"); |
| 42 | + assert.isDefined(result?.programCtx, "Expected programCtx to be defined"); |
| 43 | + assert.isFalse(result?.programCtx?.hasFailed, "Expected no errors"); |
| 44 | + }); |
| 45 | + |
| 46 | + it("any error binding", async () => { |
| 47 | + let result: KipperCompileResult | undefined = undefined; |
| 48 | + try { |
| 49 | + result = await new KipperCompiler().compile("try {} catch (e: any) {}", defaultConfig); |
| 50 | + } catch (e) { |
| 51 | + assert.fail(`Expected no '${(<KipperError>e).name}'`); |
| 52 | + } |
| 53 | + assert.isDefined(result, "Expected defined compilation result"); |
| 54 | + assert.isDefined(result?.programCtx, "Expected programCtx to be defined"); |
| 55 | + assert.isFalse(result?.programCtx?.hasFailed, "Expected no errors"); |
| 56 | + }); |
| 57 | + |
| 58 | + it("class error binding", async () => { |
| 59 | + let result: KipperCompileResult | undefined = undefined; |
| 60 | + try { |
| 61 | + result = await new KipperCompiler().compile("class A {}; try {} catch (e: A) {}", defaultConfig); |
| 62 | + } catch (e) { |
| 63 | + assert.fail(`Expected no '${(<KipperError>e).name}'`); |
| 64 | + } |
| 65 | + assert.isDefined(result, "Expected defined compilation result"); |
| 66 | + assert.isDefined(result?.programCtx, "Expected programCtx to be defined"); |
| 67 | + assert.isFalse(result?.programCtx?.hasFailed, "Expected no errors"); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments