-- playlist/pls tests: Python-written PLS files (tools/fixtures/playlist.py) decode to their entries; keys in any case -- and order, gaps in the numbering, comments, NumberOfEntries mismatches, Windows-1252, relative locations; the -- writer round-trips (titles, unknown lengths, line breaks); the api; the fuzz pass. (The playlist-luau PLS cases run -- in tests/playlist/m3u.luau.) Fixtures: tools/fixtures/playlist.py. local T = require("@tests/T") local Pls = require("@formats/playlist/pls") local Bytes = require("@formats/core/Bytes") local F = require("@formats") local Cases = require("@tests/gen/playlist_cases") local t = T.suite("pls") local function decode(s: string, base: string?): any return Pls.decode(Bytes.reader(buffer.fromstring(s)), { baseUrl = base }) end for _, c in Cases do local pl = decode(c.pls) t:eq(#pl.entries, #c.entries, c.name .. ": entries") t:eq(#pl.warnings, 0, c.name .. ": no warnings") for i, e in c.entries do local g = pl.entries[i] t:eq(g.url, e.url, c.name .. ": url " .. i) t:eq(g.title, e.title, c.name .. ": title " .. i) t:eq(g.duration, e.duration, c.name .. ": duration " .. i) t:check(g.playable, c.name .. ": playable " .. i) end local back = decode(buffer.tostring(Pls.encode(pl) :: buffer)) t:eq(#back.entries, #pl.entries, c.name .. ": round trip count") for i, e in pl.entries do local g = back.entries[i] t:check(g.url == e.url and g.title == e.title and g.duration == e.duration, c.name .. ": round trip " .. i) end end t:note("%d Python-written PLS files decode to their entries and round-trip", #Cases) do local pl = decode("; comment\n[PlayList]\nversion=2\nTITLE2=Second\nfile2=b.mp3\nFile10=http://x/ten.mp3\nLength2=7\nFile1=a.mp3\nnumberofentries=4\n", "http://h/dir/list.pls") t:eq(#pl.entries, 3, "entries sorted by number") t:eq(pl.entries[1].url, "http://h/dir/a.mp3", "relative resolved") t:check(pl.entries[2].title == "Second" and pl.entries[2].duration == 7, "case-insensitive keys") t:eq(pl.entries[3].url, "http://x/ten.mp3", "gap in numbering") t:check(string.find(pl.warnings[1], "NumberOfEntries=4", 1, true) ~= nil, "count mismatch warning") local cp = decode("[playlist]\nFile1=http://x/a.mp3\nTitle1=Bj\246rk\nNumberOfEntries=1\n") t:eq(cp.entries[1].title, "Bj\u{f6}rk", "Windows-1252 text") local loc = decode("[playlist]\nFile1=C:\\Music\\a.mp3\nNumberOfEntries=1\n") t:check(not loc.entries[1].playable and loc.entries[1].reason == "local path", "local path") -- the writer local out = buffer.tostring(Pls.encode({ { url = "http://a/1.mp3", title = "One\nTwo", duration = 61.6 }, { url = "http://a/2.mp3" }, { url = 5 } } :: any) :: buffer) t:eq(out, "[playlist]\nFile1=http://a/1.mp3\nTitle1=One Two\nLength1=62\nFile2=http://a/2.mp3\nLength2=-1\nNumberOfEntries=2\nVersion=2\n", "writer output") t:check(select(2, Pls.encode(5 :: any)) ~= nil, "encode a number") t:eq(Pls.sniff(Bytes.reader(buffer.fromstring("\239\187\191 [playlist]\r\nFile1=a"))), 0.95, "sniff") t:eq(Pls.sniff(Bytes.reader(buffer.fromstring("#EXTM3U"))), 0, "sniff m3u") -- the api t:eq(F.detect(Cases[1].pls), "pls", "F.detect") local a = F.playlist.load(Cases[1].pls) t:check(a and a.format == "pls", "F.playlist.load") local m = F.convert(Cases[1].pls, "m3u") t:check(m and string.sub(buffer.tostring(m), 1, 7) == "#EXTM3U", "F.convert pls -> m3u") end local samples = {} for _, c in Cases do table.insert(samples, c.pls) end t:fuzz("decode", function(b: buffer) return Pls.decode(Bytes.reader(b), { baseUrl = "http://h/a/" }) end, samples, { mutations = 20 }) t:done()