mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 19:11:58 +03:00
add missing evaluation error tests
This commit is contained in:
parent
55d8401a44
commit
d3731be6ef
1 changed files with 25 additions and 3 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
import { describe, it, expect, beforeAll } from "vitest";
|
import { describe, it, expect, beforeAll } from "vitest";
|
||||||
import { SumEngine } from "./index";
|
import { SumEngine } from "./index";
|
||||||
import { qty } from "./types";
|
import { qty, EvalError, XRefError } from "./types";
|
||||||
import type { XRefResolution } from "./evaluator";
|
import type { XRefResolution, EvalCtx } from "./evaluator";
|
||||||
import { formatValue } from "./index";
|
import { evaluate } from "./evaluator";
|
||||||
|
import { formatValue } from "./formatter";
|
||||||
|
|
||||||
let eng: SumEngine;
|
let eng: SumEngine;
|
||||||
|
|
||||||
|
|
@ -423,3 +424,24 @@ describe("cross-sheet references", () => {
|
||||||
expect(r[0].assign).toBe("rent");
|
expect(r[0].assign).toBe("rent");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("evaluation errors", () => {
|
||||||
|
it("throws EvalError for unknown variable", () => {
|
||||||
|
const ctx = {
|
||||||
|
vars: new Map(),
|
||||||
|
reg: eng.reg,
|
||||||
|
historicalRates: {},
|
||||||
|
} as unknown as EvalCtx;
|
||||||
|
expect(() => evaluate({ k: "var", name: "unknown" }, ctx)).toThrowError(EvalError);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws XRefError for unresolved xref", () => {
|
||||||
|
const ctx = {
|
||||||
|
vars: new Map(),
|
||||||
|
reg: eng.reg,
|
||||||
|
historicalRates: {},
|
||||||
|
resolveXRef: () => ({ ok: false, reason: "xref error" }),
|
||||||
|
} as unknown as EvalCtx;
|
||||||
|
expect(() => evaluate({ k: "xref", sheet: "Sheet", key: "key" }, ctx)).toThrowError(XRefError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue