fix(journal): tokenize bare dice notation

The tokenizer only recognized dice when the pattern started with a count (3d6), so a bare d20 fell through to the identifier branch and failed as an unknown identifier. Add a dedicated branch for the bare d-form; DICE_RE already accepted it.
This commit is contained in:
hyper
2026-09-12 23:44:24 +08:00
parent 3532be2335
commit e838f9a4b1
2 changed files with 31 additions and 1 deletions
@@ -379,6 +379,20 @@ describe("evaluateExpression", () => {
expect(result.value.value).toBeLessThanOrEqual(23);
});
test("evaluates bare dice notation", () => {
const result = evaluateExpression("d20", { lookup: () => undefined });
expect(result.value.kind).toBe("number");
expect(result.value.value).toBeGreaterThanOrEqual(1);
expect(result.value.value).toBeLessThanOrEqual(20);
});
test("evaluates bare dice alongside modifiers", () => {
const result = evaluateExpression("d6 + 5", { lookup: () => undefined });
expect(result.value.kind).toBe("number");
expect(result.value.value).toBeGreaterThanOrEqual(6);
expect(result.value.value).toBeLessThanOrEqual(11);
});
test("throws on division by zero", () => {
expect(() =>
evaluateExpression("10 / 0", { lookup: () => undefined }),