import { describe, expect, it } from "vitest"; import { World, type Entity } from "../src/index.js"; describe("World", () => { it("create/get/query/remove/snapshot roundtrip", () => { const world = new World(); world.create({ id: "player", type: "player", x: 1, y: 2 }); world.create({ id: "farm", type: "map", width: 12 }); world.create({ id: "plot-1", type: "plot", x: 3, y: 3 }); expect(world.get("player")).toEqual({ id: "player", type: "player", x: 1, y: 2 }); expect(world.get("missing")).toBeUndefined(); const players = world.query({ type: "player" }); expect(players).toHaveLength(1); expect(players[0]?.id).toBe("player"); const all = world.query(); expect(all).toHaveLength(3); expect(world.snapshot()).toHaveLength(3); expect(world.remove("plot-1")).toBe(true); expect(world.remove("plot-1")).toBe(false); expect(world.get("plot-1")).toBeUndefined(); expect(world.snapshot()).toHaveLength(2); const entity: Entity = world.create({ id: "plot-2", type: "plot", x: 0 }); expect(entity).toBe(world.get("plot-2")); }); });