C2, the hierarchy (tools/move.py, every reference rewritten mechanically): - codecs/compress: Deflate Lzma Zstd Brotli Bzip2 Lzw; codecs/entropy: Huffman (from core) RangeCoder; codecs/image: Jpeg Dct Vp8 Vp8L Yuv Quantize Raster Blend Pixels; codecs/audio: Mdct Aac Alac Pcm Resample VorbisComment Tracker SoundFont Stream; codecs/video: H264 Mpeg1 Video; codecs/text: Json Xml Text Url; codecs/font: TrueType Cff; codecs/model: MeshFlatten Mat4. containers/ stays flat; core/ keeps Bytes Bits Err Crc32 Adler32 Base64 Md5 Input Sniff. - LAYERS lint: codecs must sit in a domain folder; gen_registry lists codecs by domain (docs/FORMATS.md). - Checked: build.py both targets, rojo build of build/roblox, the full suite on both runtimes. C3, generic code out of format folders: - containers/Chunks (new): the chunked-file walker (RIFF / RIFX / IFF / PNG / CAF layouts: endianness, size first, trailer, padding, lenient missing pad, open-ended ids, size hooks). containers/Riff walks with it (RF64 ds64 through the resize hook); image/png, audio/aiff and audio/caf list their chunk handlers over it. - codecs/audio/Stream (new): Stream.packets, the packet-decoder Decoder (read / seek with pre-roll / position, priming and end trimming) that aac, caf and m4a each carried (~70 lines each). - codecs/image/Pixels: image/bmp/Pixels promoted (+ rgb555); image/ico's DIB decoder uses its row loops instead of its own (the AND mask / alpha rule stay ICO's). - codecs/model/Mat4 (new): matrices / quaternions / TRS shared by FBX (Xform keeps only the FBX transform model), Collada (Math keeps only <lookat> / <skew>) and USD (its matrix helpers and general 4x4 inverse); Mat4.mul is Types.Scene.mul. The Collada normal matrix is now the inverse transpose (it was the inverse; same result for the fixtures' bind shapes). - README rewritten (install for Rojo and LÖVE / LuaJIT, quick start per category, F.* and F.ops, host notes: FORMATS_NO_JIT_TUNE, paths, layout); docs/STYLE.md: the codec domains, "what belongs in a format folder" with the shared building blocks and the DUP rule, conventions (WAVE order, lower-case tags, loops, the api hooks decodeImage / encodeImage / openAudio / plugins / resolve, the codecs/video/Video registry), Err.from, the type baseline. New tests: tests/containers/chunks, tests/codecs/mat4. Type baseline 93.
109 lines
5.1 KiB
Luau
109 lines
5.1 KiB
Luau
-- codecs/text/Url + codecs/text/Text tests: every example of RFC 3986 section 5.4 (normal and abnormal), dot-segment removal,
|
|
-- splitting, encoding and the location helpers (ported from playlist-luau tests/url.luau); random references against
|
|
-- Python's urllib.parse.urljoin; Url.locate / Url.base; Windows-1252 decoding against Python's cp1252 codec; lines,
|
|
-- BOM, trim; the fuzz pass. Fixtures: tools/fixtures/playlist.py.
|
|
local T = require("@tests/T")
|
|
local Url = require("@formats/codecs/text/Url")
|
|
local Text = require("@formats/codecs/text/Text")
|
|
local Ref = require("@tests/gen/playlist_url")
|
|
local Cp = require("@tests/gen/playlist_cp1252")
|
|
|
|
local t = T.suite("url")
|
|
local function eq(got: any, want: any, label: string)
|
|
t:eq(got, want, label)
|
|
end
|
|
|
|
local BASE = "http://a/b/c/d;p?q"
|
|
local cases = {
|
|
-- 5.4.1 normal
|
|
{ "g:h", "g:h" }, { "g", "http://a/b/c/g" }, { "./g", "http://a/b/c/g" }, { "g/", "http://a/b/c/g/" },
|
|
{ "/g", "http://a/g" }, { "//g", "http://g" }, { "?y", "http://a/b/c/d;p?y" }, { "g?y", "http://a/b/c/g?y" },
|
|
{ "#s", "http://a/b/c/d;p?q#s" }, { "g#s", "http://a/b/c/g#s" }, { "g?y#s", "http://a/b/c/g?y#s" },
|
|
{ ";x", "http://a/b/c/;x" }, { "g;x", "http://a/b/c/g;x" }, { "g;x?y#s", "http://a/b/c/g;x?y#s" },
|
|
{ "", "http://a/b/c/d;p?q" }, { ".", "http://a/b/c/" }, { "./", "http://a/b/c/" }, { "..", "http://a/b/" },
|
|
{ "../", "http://a/b/" }, { "../g", "http://a/b/g" }, { "../..", "http://a/" }, { "../../", "http://a/" },
|
|
{ "../../g", "http://a/g" },
|
|
-- 5.4.2 abnormal
|
|
{ "../../../g", "http://a/g" }, { "../../../../g", "http://a/g" }, { "/./g", "http://a/g" },
|
|
{ "/../g", "http://a/g" }, { "g.", "http://a/b/c/g." }, { ".g", "http://a/b/c/.g" }, { "g..", "http://a/b/c/g.." },
|
|
{ "..g", "http://a/b/c/..g" }, { "./../g", "http://a/b/g" }, { "./g/.", "http://a/b/c/g/" },
|
|
{ "g/./h", "http://a/b/c/g/h" }, { "g/../h", "http://a/b/c/h" }, { "g;x=1/./y", "http://a/b/c/g;x=1/y" },
|
|
{ "g;x=1/../y", "http://a/b/c/y" }, { "g?y/./x", "http://a/b/c/g?y/./x" }, { "g?y/../x", "http://a/b/c/g?y/../x" },
|
|
{ "g#s/./x", "http://a/b/c/g#s/./x" }, { "g#s/../x", "http://a/b/c/g#s/../x" }, { "http:g", "http:g" },
|
|
}
|
|
for _, c in cases do
|
|
eq(Url.resolve(c[1], BASE), c[2], "resolve " .. c[1])
|
|
end
|
|
-- base with an empty path
|
|
eq(Url.resolve("g", "http://a"), "http://a/g", "empty base path")
|
|
eq(Url.resolve("g", "http://a?x"), "http://a/g", "empty base path with query")
|
|
|
|
eq(Url.removeDotSegments("/a/b/c/./../../g"), "/a/g", "remove_dot_segments 1")
|
|
eq(Url.removeDotSegments("mid/content=5/../6"), "mid/6", "remove_dot_segments 2")
|
|
|
|
local p = Url.split("https://user@host:8080/p/a.mp3?x=1&y#frag")
|
|
eq(p.scheme, "https", "split scheme")
|
|
eq(p.authority, "user@host:8080", "split authority")
|
|
eq(p.path, "/p/a.mp3", "split path")
|
|
eq(p.query, "x=1&y", "split query")
|
|
eq(p.fragment, "frag", "split fragment")
|
|
eq(Url.join(p), "https://user@host:8080/p/a.mp3?x=1&y#frag", "join")
|
|
local q = Url.split("a/b")
|
|
eq(q.scheme, nil, "relative has no scheme")
|
|
eq(q.authority, nil, "relative has no authority")
|
|
|
|
eq(Url.encodeUnsafe("a b/ü%20?x=\"1\"#f"), "a%20b/%C3%BC%20?x=%221%22#f", "encodeUnsafe")
|
|
eq(Url.isWindowsPath("C:\\Music\\a.mp3"), true, "windows drive")
|
|
eq(Url.isWindowsPath("d:/x.mp3"), true, "windows drive with slash")
|
|
eq(Url.isWindowsPath("\\\\server\\share\\a.mp3"), true, "UNC")
|
|
eq(Url.isWindowsPath("http://x/a"), false, "http is not windows")
|
|
eq(Url.scheme("C:\\a.mp3"), nil, "a drive letter is not a scheme")
|
|
eq(Url.scheme("HTTPS://x"), "https", "scheme lower-cased")
|
|
eq(Url.scheme("music/a.mp3"), nil, "relative has no scheme")
|
|
|
|
|
|
-- Python's urljoin
|
|
for _, c in Ref do
|
|
eq(Url.resolve(c[1], c[2]), c[3], "urljoin " .. c[1] .. " against " .. c[2])
|
|
end
|
|
t:note("%d random references resolve as urllib.parse.urljoin", #Ref)
|
|
|
|
-- locate / base
|
|
do
|
|
local w = {}
|
|
local base, scheme = Url.base("https://h/a/list.m3u", w)
|
|
t:check(base == "https://h/a/list.m3u" and scheme == "https", "base")
|
|
local l = Url.locate(" b c.mp3 ", base, scheme)
|
|
t:check(l.url == "https://h/a/b%20c.mp3" and l.playable, "locate relative")
|
|
t:check(Url.locate("C:\\x.mp3", base, scheme).reason == "local path", "locate windows")
|
|
t:check(Url.locate("ftp://x/y", base, scheme).reason == "scheme ftp", "locate ftp")
|
|
local nb, ns = Url.base("lists/x.m3u", w)
|
|
t:check(nb == nil and ns == nil and #w == 1, "a relative base is ignored with a warning")
|
|
t:check(select(2, Url.base("C:\\Music\\l.m3u")) == "windows", "windows base")
|
|
end
|
|
|
|
-- Text
|
|
do
|
|
for _, c in Cp do
|
|
eq(Text.toUtf8("x" .. string.char(c[1]) .. "y"), "x" .. c[2] .. "y", string.format("cp1252 0x%02x", c[1]))
|
|
end
|
|
local w = {}
|
|
Text.toUtf8("\150", w)
|
|
t:check(#w == 1, "cp1252 warning")
|
|
eq(Text.toUtf8("\239\187\191abc"), "abc", "BOM stripped")
|
|
eq(Text.toUtf8("h\u{e9}"), "h\u{e9}", "UTF-8 kept")
|
|
local ls = Text.lines("a\r\nb\rc\nd")
|
|
t:check(#ls == 4 and ls[1] == "a" and ls[2] == "b" and ls[3] == "c" and ls[4] == "d", "lines")
|
|
eq(Text.trim(" x y \t"), "x y", "trim")
|
|
end
|
|
|
|
t:fuzz("resolve + locate", function(b: buffer)
|
|
local s = buffer.tostring(b)
|
|
Url.resolve(s, "http://a/b/c/d;p?q")
|
|
Url.resolve("g/../h", s)
|
|
Url.locate(s, "http://h/", "http")
|
|
return Text.lines(Text.toUtf8(s))
|
|
end, { "http://a/b/../c?x#y", "C:\\a\\b.mp3", "\239\187\191#EXTM3U\r\n" }, { mutations = 30 })
|
|
|
|
t:done()
|