tests/core: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:49:47 -05:00
1 parent e23adf2a2d
commit 53aa9a6ebf
4 files changed
+3 -24

No files matched your search

+1 -5
View File
@@ -1,5 +1,4 @@
-- core/Base64 tests: the RFC 4648 vectors, encode / decode against Python's base64 (standard, URL-safe, unpadded) for every length 0..70
-- and some large inputs, whitespace and missing padding on decode, data: URIs, bad input, and the fuzz no-throw pass.
-- core/Base64 tests: the RFC 4648 vectors and Python's base64 (standard, URL-safe, unpadded), data: URIs, bad input.
-- Fixtures: tools/fixtures/base64.py.
local T = require("@tests/T")
local Base64 = require("@rosetta/core/Base64")
@@ -43,15 +42,12 @@ end
t:eq(Base64.encode("foobarfoobarfo", { wrap = 8 }), "Zm9vYmFy\nZm9vYmFy\nZm8=", "wrap 8")
t:eq(Base64.encode("foobarfoobar", { wrap = 8 }), "Zm9vYmFy\nZm9vYmFy", "wrap at the end")
t:eq(Base64.encode("foobarfoobar", { wrap = 9 }), "Zm9vYmFy\nZm9vYmFy", "wrap rounds to groups")
-- a sub-range
t:eq(Base64.encode(buffer.fromstring("xxhelloyy"), nil, 2, 5), "aGVsbG8=", "encode a range")
-- data URIs
local b, mime = Base64.decodeDataUri("data:application/gltf-buffer;base64,AAEC")
t:check(b and buffer.len(b) == 3 and buffer.readu8(b, 2) == 2 and mime == "application/gltf-buffer", "data URI")
local b2, m2 = Base64.decodeDataUri("data:,a%20b")
t:check(b2 and buffer.tostring(b2) == "a b" and m2 == "text/plain", "percent-encoded data URI")
t:eq(Base64.dataUri(buffer.fromstring("hi"), "text/plain"), "data:text/plain;base64,aGk=", "dataUri")
-- bad input
t:check(Base64.decode("ab$d") == nil, "bad character")
t:check(Base64.decode("abcde") == nil, "a lone last character")
t:check(Base64.decode("ab==cd") == nil, "data after padding")
+1 -8
View File
@@ -1,6 +1,4 @@
-- core/Bits and codecs/entropy/Huffman tests: LSB / MSB readers and writers round-trip random fields of 1..32 bits, align /
-- peek / bytePos, overrun is a sticky error; canonical codes, length-limited code lengths, LSB and MSB decoding tables
-- (with subtables) decode what the writers wrote; invalid code sets are rejected.
-- core/Bits and codecs/entropy/Huffman tests: bit readers / writers, canonical codes, length limits, decoding tables.
local T = require("@tests/T")
local Bits = require("@rosetta/core/Bits")
local Huffman = require("@rosetta/codecs/entropy/Huffman")
@@ -9,7 +7,6 @@ local Err = require("@rosetta/core/Err")
local t = T.suite("bits")
local rand = T.rng(7)
-- round trips
for _, kind in { "lsb", "msb" } do
local w = if kind == "lsb" then Bits.lsbWriter() else Bits.msbWriter()
local fields = {}
@@ -46,7 +43,6 @@ for _, kind in { "lsb", "msb" } do
t:check(r.err and r.err.code == Err.TRUNCATED, kind .. ": overrun is TRUNCATED")
end
-- known bit orders
do
local lsb = Bits.lsbReader(T.bytes({ 0xB4 })) -- 1011 0100
t:eq(lsb:read(3), 4, "lsb: first field is the low bits")
@@ -83,7 +79,6 @@ do
t:eq(Huffman.reverse(1, 3), 4, "reverse 3 bits")
end
-- lengths: limits, Kraft equality, single symbol
local function kraft(lens: { number }): number
local s = 0
for _, l in lens do
@@ -113,7 +108,6 @@ do
t:check(u[1] == 2 and u[4] == 2, "uniform")
end
-- decoding tables: random code sets, encode with the writer, decode through LSB and MSB tables
for trial = 1, 30 do
local nsym = 2 + rand(300)
local freqs = {}
@@ -161,7 +155,6 @@ for trial = 1, 30 do
end
end
-- invalid code sets
do
local over = T.bytes({ 1, 1, 1 }) -- three 1-bit codes
t:eq(Huffman.buildLsb(over, 0, 3, buffer.create(1024 * 4), 8), -1, "over-subscribed")
+1 -10
View File
@@ -1,6 +1,4 @@
-- core/Bytes, core/Err, core/Crc32, core/Adler32, core/Input tests: every Reader / Writer method both endians, the
-- sticky TRUNCATED error (never a throw), sub-readers without copies, Writer growth and patching, Bytes.span, the
-- MSB-first CRC-32 (MPEG-2 / bzip2 check values).
-- core/Bytes, Err, Crc32, Adler32 and Input tests.
local T = require("@tests/T")
local Bytes = require("@rosetta/core/Bytes")
local Err = require("@rosetta/core/Err")
@@ -10,7 +8,6 @@ local Input = require("@rosetta/core/Input")
local t = T.suite("bytes")
-- Writer -> Reader round trip of every type
do
local w = Bytes.writer(4) -- grows
w:u8(0xAB)
@@ -97,7 +94,6 @@ do
local nilv, e = r4:fail(Err.CORRUPT, "bad thing")
t:check(nilv == nil and e.code == Err.CORRUPT and tostring(e) == "CORRUPT at 0x0: bad thing", "fail(): " .. tostring(e))
t:check(not r4:need(5) and r4.err == e, "need keeps the first error")
-- every method on an empty reader: no throw
local empty = Bytes.reader(buffer.create(0))
for _, m in { "u8", "i8", "u16le", "u16be", "i16le", "i16be", "u24le", "u24be", "u32le", "u32be", "i32le", "i32be", "u64le", "u64be", "i64le", "i64be", "f16le", "f16be", "f32le", "f32be", "f64le", "f64be", "cstring" } do
local ok, v = pcall((Bytes.Reader :: any)[m], empty)
@@ -113,7 +109,6 @@ do
t:check(ok, "string / bytes / slice / skip / align on an empty reader")
end
-- ranges, sub-readers, peek, match
do
local buf = buffer.fromstring("0123456789")
local r = Bytes.reader(buf, 2, 5) -- "23456"
@@ -141,7 +136,6 @@ do
t:check(a:align(4) and a:tell() == 4, "align")
end
-- checksums
do
t:eq(Crc32.string("123456789"), 0xCBF43926, "crc32 check value")
t:eq(Crc32.of(buffer.fromstring("xx123456789yy"), 2, 9), 0xCBF43926, "crc32 range")
@@ -151,7 +145,6 @@ do
t:eq(Adler32.string("pedia", Adler32.string("Wiki")), 0x11E60398, "adler32 continuation")
end
-- Input (without a host)
do
local b = buffer.create(3)
t:check(Input.resolve(b) == b, "a buffer passes through")
@@ -173,7 +166,6 @@ do
t:eq(buffer.tostring(db :: buffer), "img.png", "opts.data forces data")
end
-- Err
do
local e = Err.new(Err.CORRUPT, "bad", 16)
t:check(Err.is(e) and not Err.is({}) and not Err.is("x"), "Err.is")
@@ -182,7 +174,6 @@ do
t:check(w.code == Err.CORRUPT and w.format == "gif", "wrap a string")
end
-- Bytes.span: codec argument checking
do
local b, o, n = Bytes.span("x", "hello", 1, 10)
t:check(type(b) == "buffer" and o == 1 and n == 4, "span clamps the length")
-1
View File
@@ -15,7 +15,6 @@ local VECTORS = {
for _, v in VECTORS do
t:eq(Md5.of(buffer.fromstring(v[1])), v[2], "md5 of " .. string.format("%q", v[1]))
end
-- incremental: every split point of a 130-byte message, three pieces
local msg = string.rep("The quick brown fox jumps over the lazy dog. ", 3)
local want = Md5.of(buffer.fromstring(msg))
for cut = 0, #msg, 7 do