Fix tests

This commit is contained in:
2026-10-25 12:50:39 -03:00
parent 4fad43d9cc
commit bcca8fa4a5
3 changed files with 21 additions and 11 deletions
+13 -5
View File
@@ -155,13 +155,21 @@ Deno.test("a table's json says what's wrong with it", () => {
const table = { id: "t:x", pools: [{ entries: [{ item: "t:a" }] }] };
assertEquals(validate_loot_table(table), []);
const problems = (json: unknown) => validate_loot_table(json).join("\n");
assert(problems({ ...table, pools: [{ entries: [] }] }).includes("entries must be a list"));
assert(problems({ ...table, pools: [{ entries: [] }] }).includes("entries can't be empty"));
assert(problems({ ...table, pools: [{ rolls: -1, entries: [{ item: "t:a" }] }] }).includes("rolls"));
assert(problems({ ...table, pools: [{ entries: [{ type: "tag", tag: "t:gems" }] }] }).includes("#tag"));
assert(problems({ ...table, pools: [{ entries: [{ type: "loot_table" }] }] }).includes("table is needed"));
assert(problems({ ...table, conditions: [{ condition: "full_moon" }] }).includes("isn't a loot condition"));
assert(problems({ ...table, functions: [{ function: "enchant" }] }).includes("isn't a loot function"));
assert(problems({ ...table, conditions: [{ condition: "random_chance", chance: 2 }] }).includes("0 to 1"));
assert(
problems({ ...table, pools: [{ entries: [{ type: "loot_table" }] }] }).includes(
"table must be a loot table id",
),
);
assert(problems({ ...table, conditions: [{ condition: "full_moon" }] }).includes("condition must be one of"));
assert(problems({ ...table, functions: [{ function: "enchant" }] }).includes("function must be one of"));
assert(
problems({ ...table, conditions: [{ condition: "random_chance", chance: 2 }] }).includes(
"chance must be at most 1",
),
);
// a mod's own are only checked once its script registers them
assertEquals(validate_loot_table({ ...table, conditions: [{ condition: "m:full_moon" }] }), []);
});