mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 15:42:01 +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 { 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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue