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")