tests/playlist, tests/subtitle: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:49:12 -05:00
1 parent e0ab895027
commit 928ac9b39f
6 files changed
+10 -44

No files matched your search

+3 -16
View File
@@ -1,8 +1,5 @@
-- playlist/m3u tests (+ the PLS parts of the ported suite): M3U / M3U8 (EXTINF, comments, BOM, CRLF / CR,
-- Windows-1252, relative / absolute / local locations), PLS, HLS master and media playlists, detection, serialize round
-- trips, bad input; Python-written playlists (tools/fixtures/playlist.py) decode to their entries, and our M3U8 output
-- decodes back; the api; the fuzz pass. Ported from playlist-luau tests/playlist.luau. Fixtures:
-- tools/fixtures/playlist.py.
-- playlist/m3u tests: M3U / M3U8, PLS, HLS master and media playlists, against Python-written playlists.
-- Fixtures: tools/fixtures/playlist.py.
local T = require("@tests/T")
local M3u = require("@rosetta/playlist/m3u")
local Pls = require("@rosetta/playlist/pls")
@@ -23,7 +20,6 @@ local function has(list: { string }, pattern: string): boolean
return false
end
-- the playlist-luau API on top of the two formats (the ported tests below use it)
local Playlist = {}
function Playlist.detect(text: string): string
if type(text) ~= "string" then
@@ -42,7 +38,7 @@ function Playlist.parse(text: any, baseUrl: string?): any
local kind = Playlist.detect(text)
local mod = if kind == "pls" then Pls else M3u
local pl = mod.decode(Bytes.reader(buffer.fromstring(text)), { baseUrl = baseUrl }) :: any
pl.kind = pl.format -- the old field
pl.kind = pl.format
return pl
end
function Playlist.serialize(entries: any, opts: any?): string
@@ -102,7 +98,6 @@ do
eq(pl3.entries[1].url, "C:\\Music\\a.mp3", "windows base")
eq(pl3.entries[2].url, "C:\\Music\\sub\\b.mp3", "windows base sub")
eq(pl3.entries[1].playable, false, "windows base unplayable")
-- file: base
local pl4 = Playlist.parse("a.mp3", "file:///C:/Music/list.m3u")
eq(pl4.entries[1].url, "file:///C:/Music/a.mp3", "file base")
eq(pl4.entries[1].reason, "local path", "file base local")
@@ -123,7 +118,6 @@ do
eq(pl3.entries[1].url, "http://x/Bj%C3%B6rk.mp3", "utf-8 url encoded")
end
-- PLS
do
local text = "[playlist]\r\nNumberOfEntries=3\r\nFile2=http://s.example:8000/live\r\nTitle2=(#1) Some Radio\r\nLength2=-1\r\n"
.. "File1=music/a.mp3\r\nTitle1=Artist - Song\r\nLength1=200\r\n; comment\r\nfile10 = http://x/z.mp3\r\nVersion=2\r\n"
@@ -235,7 +229,6 @@ do
eq(none.entries[1].playable, true, "METHOD=NONE is clear")
end
-- detection
do
eq(Playlist.detect("[playlist]\nFile1=a"), "pls", "detect pls")
eq(Playlist.detect("\239\187\191 [PLAYLIST]\r\n"), "pls", "detect pls with BOM / spaces")
@@ -245,7 +238,6 @@ do
eq(Playlist.detect("a.mp3"), "m3u", "detect plain")
end
-- serialize: M3U8, round trip
do
local entries = {
{ url = "http://x/a.mp3", title = "A - B", duration = 61.6 },
@@ -265,7 +257,6 @@ do
eq(back.entries[2].title, nil, "round trip no title")
eq(back.entries[3].duration, nil, "round trip unknown duration")
eq(Playlist.serialize({}), "#EXTM3U\n", "serialize empty")
-- parse -> serialize -> parse keeps everything of a real playlist
local pl = Playlist.parse("#EXTM3U\n#EXTINF:100,X - Y\nhttp://h/1.mp3\n#EXTINF:-1,Live\nhttp://h/live\n")
local again = Playlist.parse(Playlist.serialize(pl.entries))
for i, e in pl.entries do
@@ -275,7 +266,6 @@ do
end
end
-- bad input never throws
do
local inputs: { any } = { "", "\n\n\n", "#EXTM3U", "#EXTINF:abc,\n", "[playlist]\n=\nFile=\nFilex1=y", "#EXT-X-STREAM-INF:\n",
"#EXT-X-STREAM-INF:BANDWIDTH=\"unterminated\n", "#EXT-X-BYTERANGE:x\n#EXT-X-TARGETDURATION:\n", "\255\254\0\0", 42, nil }
@@ -288,7 +278,6 @@ do
eq(has(Playlist.parse(42 :: any).warnings, "expected a string"), true, "non-string warning")
local ok = pcall(Playlist.serialize, { 1, "x", { url = 5 } } :: any)
eq(ok, true, "serialize skips junk")
-- random bytes
local state = 7
for _ = 1, 300 do
local t = table.create(80)
@@ -305,7 +294,6 @@ do
end
-- Python-written playlists
for _, c in Cases do
local pl = M3u.decode(Bytes.reader(buffer.fromstring(c.m3u))) :: any
eq(#pl.entries, #c.entries, c.name .. ": entries")
@@ -326,7 +314,6 @@ for _, c in Cases do
end
t:note("%d Python-written M3U8 files decode to their entries", #Cases)
-- the contract and the api
do
eq(M3u.name, "m3u", "name")
eq(M3u.category, "playlist", "category")
+2 -6
View File
@@ -1,7 +1,5 @@
-- 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.
-- playlist/pls tests: Python-written PLS files decode to their entries; writer round trips.
-- Fixtures: tools/fixtures/playlist.py.
local T = require("@tests/T")
local Pls = require("@rosetta/playlist/pls")
local Bytes = require("@rosetta/core/Bytes")
@@ -44,13 +42,11 @@ do
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")
+1 -7
View File
@@ -1,7 +1,4 @@
-- playlist/xspf tests: XSPF files written by Python's xml.etree.ElementTree (tools/fixtures/playlist.py) decode to
-- their entries; every track field, multiple locations, xml:base, relative / local locations, a prefixed namespace;
-- the writer round-trips (and escapes; its output was also checked by hand with ElementTree); errors (malformed XML,
-- another root); the api; the fuzz pass.
-- playlist/xspf tests: XSPF files written by Python's xml.etree.ElementTree decode to their entries.
-- Fixtures: tools/fixtures/playlist.py.
local T = require("@tests/T")
local Xspf = require("@rosetta/playlist/xspf")
@@ -57,12 +54,10 @@ do
t:eq(pl.entries[2].url, "http://other.example/b.mp3", "xml:base on a track")
t:check(not pl.entries[3].playable and pl.entries[3].reason == "local path", "local path")
t:check(#pl.warnings >= 2, "warnings for the missing location and the local path")
-- writer: escaping, extra fields, a plain entry list
local out = buffer.tostring(Xspf.encode({ { url = "http://x/a?b=1&c=2", title = "<A & B>", duration = 2.5, creator = "C" } } :: any) :: buffer)
t:check(string.find(out, "http://x/a?b=1&amp;c=2", 1, true) ~= nil and string.find(out, "&lt;A &amp; B&gt;", 1, true) ~= nil, "escaping")
local back = decode(out)
t:check(back.entries[1].url == "http://x/a?b=1&c=2" and back.entries[1].title == "<A & B>" and back.entries[1].duration == 2.5 and back.entries[1].creator == "C", "writer round trip")
-- errors
local _, e1 = decode("<playlist><trackList>")
t:check(e1 and Err.is(e1), "malformed XML: " .. tostring(e1))
local _, e2 = decode("<html/>")
@@ -70,7 +65,6 @@ do
t:check(select(2, Xspf.encode(5 :: any)) ~= nil, "encode a number")
t:eq(Xspf.sniff(Bytes.reader(buffer.fromstring(Cases[1].xspf))), 0.95, "sniff")
t:eq(Xspf.sniff(Bytes.reader(buffer.fromstring("<playlist/>"))), 0, "sniff without the namespace")
-- the api
t:eq(F.detect(Cases[1].xspf), "xspf", "F.detect")
local la = F.playlist.load(Cases[1].xspf)
t:check(la and la.format == "xspf" and #la.entries == #Cases[1].entries, "F.playlist.load")