From bcca8fa4a5d2882fd2d4e594941c43a7ab82618c Mon Sep 17 00:00:00 2001 From: Paula Date: Sun, 25 Oct 2026 12:50:39 -0300 Subject: [PATCH] Fix tests --- tests/biome_test.ts | 2 +- tests/loot_test.ts | 18 +++++++++++++----- tests/texture_animation_test.ts | 12 +++++++----- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/tests/biome_test.ts b/tests/biome_test.ts index b84239f..24e1b42 100644 --- a/tests/biome_test.ts +++ b/tests/biome_test.ts @@ -63,7 +63,7 @@ Deno.test("bad biome json is reported", () => { assert(validate_biome({ ...PLAIN, colors: { grass: "green" } }).some((p) => p.startsWith("colors.grass"))); // which kinds of tree there are is up to the trees feature, see tests/wood_test.ts assertEquals(validate_biome({ ...PLAIN, trees: { chance: 2, kinds: ["palm"] } }), [ - "trees.chance must be a number from 0 to 1", + "trees.chance must be at most 1", ]); assert(validate_biome({ ...PLAIN, trees: { chance: 1, kinds: [] } }).some((p) => p.startsWith("trees.kinds"))); assert(validate_biome({ id: "my_mod:flat" }).some((p) => p.startsWith("surface"))); diff --git a/tests/loot_test.ts b/tests/loot_test.ts index f2937ed..1bea4a1 100644 --- a/tests/loot_test.ts +++ b/tests/loot_test.ts @@ -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" }] }), []); }); diff --git a/tests/texture_animation_test.ts b/tests/texture_animation_test.ts index c2cf249..22feead 100644 --- a/tests/texture_animation_test.ts +++ b/tests/texture_animation_test.ts @@ -43,14 +43,16 @@ Deno.test("a texture's .json that doesn't fit its png says why", () => { assertEquals(validate_texture_json({ animation: {} }, size), []); assertEquals(validate_texture_json([], size), ['must be { "animation": { ... } }']); assertEquals(validate_texture_json({ animation: { frametime: 0 } }, size), [ - "animation.frametime must be a whole number of ticks, at least 1", + "animation.frametime must be 1 or more", ]); assertEquals(validate_texture_json({ animation: { height: 20 } }, size), [ "the png is 16×48, which doesn't split into 16×20 frames", ]); - assertEquals(validate_texture_json({ animation: { frames: [0, 3, { index: 1 }] } }, size), [ - "animation.frames[1]: the png has frames 0 to 2", - "animation.frames[2]: time must be a whole number of ticks, at least 1", + assertEquals(validate_texture_json({ animation: { frames: [0, 3] } }, size), [ + "animation.frames[1] isn't one of the png's frames, 0 to 2", + ]); + assertEquals(validate_texture_json({ animation: { frames: [{ index: 1 }] } }, size), [ + "animation.frames[0].time is required", ]); }); @@ -111,7 +113,7 @@ Deno.test("a texture's .json is checked, packed into the .bmod and read back", a "broken.bmod", ), Error, - "textures/goo.json: animation.frames[0]: the png has frames 0 to 1", + "textures/goo.json: animation.frames[0] isn't one of the png's frames, 0 to 1", ); });