|
|
|
@@ -0,0 +1,43 @@
|
|
|
|
|
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
|
|
import { assert, assertEquals } from "@std/assert";
|
|
|
|
|
import { EverythingRegistry } from "$/common/everything_registry.ts";
|
|
|
|
|
import type { FluidJson } from "$/common/mod_data.ts";
|
|
|
|
|
import { read_bmod } from "$/common/bmod.ts";
|
|
|
|
|
import { register_mod_data } from "$/common/mod_loader.ts";
|
|
|
|
|
import { load_and_check } from "$/tools/check_mods.ts";
|
|
|
|
|
import { pack_mod } from "$/tools/pack_mod.ts";
|
|
|
|
|
|
|
|
|
|
// a mod with only a manifest and the given fluids/ files, by file name
|
|
|
|
|
function fluid_mod(fluids: Record<string, unknown>) {
|
|
|
|
|
const dir = Deno.makeTempDirSync({ prefix: "bworld_fluids_" });
|
|
|
|
|
Deno.mkdirSync(`${dir}/testfluids/fluids`, { recursive: true });
|
|
|
|
|
Deno.writeTextFileSync(
|
|
|
|
|
`${dir}/testfluids/manifest.json`,
|
|
|
|
|
JSON.stringify({ format_version: 1, id: "testfluids", name: "Test Fluids", version: "1.0.0" }),
|
|
|
|
|
);
|
|
|
|
|
for (const [file, fluid] of Object.entries(fluids)) {
|
|
|
|
|
Deno.writeTextFileSync(`${dir}/testfluids/fluids/${file}`, JSON.stringify({ format_version: 1, fluid }));
|
|
|
|
|
}
|
|
|
|
|
return dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Deno.test("a mod's fluids/ file registers a fluid, packed into its .bmod", async () => {
|
|
|
|
|
const syrup = { id: "testfluids:syrup", name: "Maple Syrup", color: "#a0522d" };
|
|
|
|
|
const dir = fluid_mod({ "syrup.json": syrup });
|
|
|
|
|
const mods = load_and_check(dir);
|
|
|
|
|
assertEquals(mods[0].report.errors, []);
|
|
|
|
|
const bmod = read_bmod(await pack_mod(mods[0]), "testfluids.bmod");
|
|
|
|
|
EverythingRegistry.clear();
|
|
|
|
|
register_mod_data([{ id: "testfluids", data: bmod.data }]);
|
|
|
|
|
assertEquals(EverythingRegistry.get<FluidJson>("fluids", "testfluids:syrup"), syrup);
|
|
|
|
|
Deno.removeSync(dir, { recursive: true });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test("a fluid with a bad color fails loading", () => {
|
|
|
|
|
const dir = fluid_mod({ "syrup.json": { id: "testfluids:syrup", color: "brown" } });
|
|
|
|
|
const errors = load_and_check(dir)[0].report.errors;
|
|
|
|
|
assert(errors.some((e) => e.startsWith("fluids/syrup.json:") && e.includes("color")), errors.join("\n"));
|
|
|
|
|
Deno.removeSync(dir, { recursive: true });
|
|
|
|
|
});
|