ludic/packages/ludic.base/tests/baked_test.ludic
Orkuncakilkaya d8baf4e579 tests: the full suite's seven failures on lang/foundations - one compiler fault and six stale expectations
- the test runner re-makes every state between tests again: since 12fdc07 a state is made by its getter on
  first use, so re-running L_init_globals left the last test's state in place (state/tested failed its
  second test); @L_reset_states forgets every lazy state, and the runner calls it before each test
- diag_json_case counts errors, and an absent @Ref / @Tint / @OneOf target is a warning since d82dc31:
  ref_unknown is 1 error and node_bad 8
- schema_hash.ludic prints 1: a bool is 1 or 0 as text (random_plain's 1 1 1)
- permap_check_case looks for the unit warning without the quotes the JSON escapes
- baked_test's inputs-hash test makes its directory: each test has a temp directory of its own
- ludic deps prints phase 25's five counters too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 21:19:00 +03:00

60 lines
2.4 KiB
Text

# baked_test.ludic - a baked file round-trips its payload; another version or key reads as null; the
# inputs hash is FNV-1a 64 over path, 0 and bytes (tools/bake/baked.py computes the same)
import "ludic.base"
program BakedTest {
function dir() -> string { return Os.temp_dir() + "/ludic-baked-test" }
test "a baked file's payload comes back, for its key and version only" {
let p = buffer(5)
for i in 0 .. 5 { p[i] = 65 + i }
let path = dir() + "/a/b.bin"
expect(bake_write(path, "tiles", 3, 42, p, 5))
let b = baked_open(path, "tiles", 3)
expect(b != null)
expect_eq(len(b), 5)
expect_eq(b[4], 69)
expect(baked_open(path, "tiles", 4) == null)
expect(baked_open(path, "tile", 3) == null)
expect(baked_open(dir() + "/none.bin", "tiles", 3) == null)
}
test "a streamed bake reads a piece of its payload at an offset into the caller's buffer" {
let p = buffer(10)
for i in 0 .. 10 { p[i] = 48 + i }
let path = dir() + "/s.bin"
expect(bake_write(path, "chunks", 1, 0, p, 10))
let bf = baked_open_range(path, "chunks", 1)
expect(bf != null)
expect(baked_len(bf) == 10)
let into = buffer(4)
expect_eq(baked_read(bf, 6, 4, into), 4)
expect_eq(into[0], 54)
expect_eq(baked_read(bf, 8, 4, into), 2)
baked_close(bf)
expect(baked_open_range(path, "chunks", 2) == null)
}
test "the inputs hash follows the path and the bytes" {
Fs.mkdir(dir()) # each test has a temp directory of its own, empty
Fs.write_text(dir() + "/in.txt", "abc")
let h1 = bake_inputs_hash(dir() + "/in.txt")
Fs.write_text(dir() + "/in.txt", "abd")
expect(bake_inputs_hash(dir() + "/in.txt") != h1)
expect(bake_inputs_hash("") == -3750763034362895579)
}
test "an input that is itself a bake hashes by its payload, not its header" {
let p = buffer(3)
for i in 0 .. 3 { p[i] = 120 + i }
let path = dir() + "/chain.bin"
expect(bake_write(path, "terrain", 1, 7, p, 3))
let h1 = bake_inputs_hash(path)
expect(bake_write(path, "terrain", 1, 99, p, 3))
expect(bake_inputs_hash(path) == h1)
p[2] = 0
expect(bake_write(path, "terrain", 1, 99, p, 3))
expect(bake_inputs_hash(path) != h1)
}
test "a dev build says a missing bake once" (bake_st: mut BakeState) {
bake_missing(bake_st, "k")
bake_missing(bake_st, "k")
expect_eq(len(bake_st.said), 1)
}
}