add missing evaluation error tests

This commit is contained in:
Horizontal42 2026-08-09 15:59:56 +03:00 • committed by GitHub
parent 55d8401a44
commit d3731be6ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,8 +1,9 @@
import { describe, it, expect, beforeAll } from "vitest";
import { SumEngine } from "./index";
import { qty } from "./types";
import type { XRefResolution } from "./evaluator";
import { formatValue } from "./index";
import { qty, EvalError, XRefError } from "./types";
import type { XRefResolution, EvalCtx } from "./evaluator";
import { evaluate } from "./evaluator";
import { formatValue } from "./formatter";
let eng: SumEngine;
@ -423,3 +424,24 @@ describe("cross-sheet references", () => {
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);
});
});