tests/codecs (m-z): comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:50:53 -05:00
1 parent 98b4ce533e
commit a6732d45f2
23 files changed
+46 -177

No files matched your search

+1 -13
View File
@@ -1,7 +1,4 @@
-- codecs/text/Nbt tests: random trees written by Python's nbtlib (Java big-endian, Bedrock little-endian, gzip, zlib,
-- the level.dat header) decode to nbtlib's typed values (a canonical dump), re-encode to nbtlib's exact bytes in both
-- byte orders, nbtlib's SNBT (indented and compact) parses to the same values and our SNBT reads back exactly;
-- Bedrock network varint NBT; modified UTF-8; long extremes; SNBT grammar details; peek; errors; the fuzz pass.
-- codecs/text/Nbt tests: random trees by Python's nbtlib (Java / Bedrock, gzip, zlib) decode, re-encode exactly, SNBT.
-- Fixtures: tools/fixtures/nbt.py.
local T = require("@tests/T")
local Nbt = require("@rosetta/codecs/text/Nbt")
@@ -68,7 +65,6 @@ local function same(a: buffer, b: string): boolean
return buffer.tostring(a) == b
end
-- 1. nbtlib trees
for _, c in Fx.cases do
local v, info = Nbt.decode(c.raw)
t:check(v ~= nil, c.name .. ": decode " .. tostring(info))
@@ -87,7 +83,6 @@ for _, c in Fx.cases do
t:eq(wi.endian, if k == "little" or k == "header" then "little" else "big", c.name .. ": " .. k .. " endian")
end
t:eq(wi.compression, if k == "gzip" or k == "zlib" then k else "none", c.name .. ": " .. k .. " compression")
-- written back the same way it was read
local again = Nbt.encode(w) :: buffer
local w2, wi2 = Nbt.decode(again)
t:eq(canon(w2), c.canon, c.name .. ": " .. k .. " round trip")
@@ -116,7 +111,6 @@ for _, c in Fx.cases do
end
end
-- 2. Bedrock network NBT
for i, c in Fx.net do
local v, info = Nbt.decode(c.data, { varint = true })
t:check(v ~= nil, "net " .. i .. ": " .. tostring(info))
@@ -124,7 +118,6 @@ for i, c in Fx.net do
t:check(same(Nbt.encode(v, { varint = true }) :: buffer, c.data), "net " .. i .. ": same bytes")
end
-- 3. details
do
-- longs: exact past 2^53, both directions
for _, s in { "9223372036854775807", "-9223372036854775808", "9007199254740993", "-9007199254740993", "4294967296", "-1" } do
@@ -155,14 +148,12 @@ do
t:eq(tostring(Nbt.byte(3)), "3b", "tostring byte")
t:eq(tostring(Nbt.float(0.1)), "0.1f", "tostring float (shortest)")
t:check(Nbt.short(5) == Nbt.short(5) and Nbt.short(5) ~= Nbt.int(5) :: any, "tag equality")
-- get
local g = assert(Nbt.parse("{Data:{Pos:[1.0d,2.5d,3.0d],Inv:[{id:\"x\"}]}}"))
t:eq(Nbt.get(g, "Data.Pos[1]").value, 2.5, "get list element")
t:eq(Nbt.get(g, "Data.Inv[0].id"), "x", "get nested")
t:eq(Nbt.get(g, "Data.Missing.x"), nil, "get missing")
end
-- 4. SNBT grammar
do
local cases: { { string } } = {
{ "1b", "byte:1" }, { "-5S", "short:-5" }, { "7", "int:7" }, { "7i", "int:7" }, { "1_000", "int:1000" },
@@ -200,7 +191,6 @@ do
t:check(e3 and e3.code == Err.LIMIT, "depth limit")
end
-- 5. peek
do
local c = Fx.cases[2]
for _, k in { "raw", "gzip", "zlib", "header" } do
@@ -210,7 +200,6 @@ do
t:eq(Nbt.peek(buffer.fromstring("hello world")), nil, "peek text")
end
-- 6. errors
do
local _, e = Nbt.decode("\10\0\0\1\0\1a")
t:check(e and e.code == Err.TRUNCATED, "truncated")
@@ -233,7 +222,6 @@ do
t:check(e6 and e6.code == Err.ARG, "encode function")
end
-- 7. fuzz
local samples = {}
for i = 1, 8 do
table.insert(samples, Fx.cases[i].raw)