tests/playlist, tests/subtitle: comments: specs only
This commit is contained in:
1 parent
e0ab895027
commit
928ac9b39f
6 files changed
+10
-44
No files matched your search
+3
-16
@@ -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")
|
||||
|
||||
@@ -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 +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&c=2", 1, true) ~= nil and string.find(out, "<A & B>", 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")
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
-- subtitle/ass tests: ffmpeg's ASS output of a random script (times to the centisecond, text through the override
|
||||
-- markup), hand-written ASS (styles, comments, commas in text, overrides, [Fonts]) and SSA v4 files against ffmpeg's
|
||||
-- SRT conversion of them, styles as data, round trips through the encoder, the contract and the fuzz pass.
|
||||
-- subtitle/ass tests: ffmpeg's ASS output and hand-written ASS / SSA files against ffmpeg's SRT conversion.
|
||||
-- Fixtures: tools/fixtures/subtitles.py.
|
||||
local T = require("@tests/T")
|
||||
local Ass = require("@rosetta/subtitle/ass")
|
||||
@@ -87,7 +85,6 @@ for _, s in { a, ssa, subs } do
|
||||
end
|
||||
end
|
||||
t:eq(buffer.tostring(Ass.encode(a) :: buffer), Fx.hand[2].data, "hand ASS written back byte for byte")
|
||||
-- cues from another format: markup converted, a Default style made
|
||||
do
|
||||
local out = Ass.encode({ kind = "subtitles", cues = { { start = 1, stop = 2.5, text = "<i>it</i> and <b>bold</b>\nline <font color=\"red\">x</font>" } }, styles = {}, meta = {} } :: any) :: buffer
|
||||
local back = Ass.decode(Bytes.reader(out))
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
-- subtitle/srt tests: a random SRT script against ffmpeg (its own parse via its srt muxer: times to the millisecond,
|
||||
-- text), ffmpeg's conversions of WebVTT / ASS / SSA files to SRT, odd layouts (no index, blank lines in text, CRLF,
|
||||
-- BOM, dot decimals, coordinates), round trips through the encoder, the contract and the fuzz pass.
|
||||
-- subtitle/srt tests: a random SRT script and ffmpeg's WebVTT / ASS / SSA conversions against ffmpeg.
|
||||
-- Fixtures: tools/fixtures/subtitles.py.
|
||||
local T = require("@tests/T")
|
||||
local Srt = require("@rosetta/subtitle/srt")
|
||||
@@ -35,7 +33,6 @@ t:eq(Srt.name, "srt", "name")
|
||||
t:eq(Srt.category, "subtitle", "category")
|
||||
t:check(Srt.caps.decode and Srt.caps.encode, "caps")
|
||||
|
||||
-- the random script and ffmpeg's re-mux of it
|
||||
local subs, err = decode(Fx.srt)
|
||||
t:check(subs, "decode: " .. tostring(err))
|
||||
same(subs, Fx.cues, "random")
|
||||
@@ -48,7 +45,6 @@ for _, h in Fx.hand do
|
||||
same(decode(h.ffmpeg_srt), h.cues, "ffmpeg " .. h.name .. " -> srt")
|
||||
end
|
||||
|
||||
-- odd layouts
|
||||
do
|
||||
local s = "\239\187\1911\r\n00:00:01.5 --> 00:00:02,25 X1:10 X2:20 Y1:5 Y2:6\r\nfirst\r\n\r\nsecond paragraph\r\n\r\n\r\n00:00:03,000 --> 00:00:04,000\r\nno index\r\n2\r\n00:00:05,000-->00:00:06,000\r\n"
|
||||
local r = decode(s)
|
||||
@@ -66,7 +62,6 @@ do
|
||||
t:eq(again.cues[1].settings, r.cues[1].settings, "odd: round trip keeps the coordinates")
|
||||
end
|
||||
|
||||
-- round trips (LF and CRLF)
|
||||
for _, crlf in { false, true } do
|
||||
local out = Srt.encode(subs, { crlf = crlf }) :: buffer
|
||||
local back = Srt.decode(Bytes.reader(out))
|
||||
@@ -82,7 +77,6 @@ for _, crlf in { false, true } do
|
||||
end
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
local _, e = decode("just some text\nno timings")
|
||||
t:check(e and e.code == Err.CORRUPT, "no cues: " .. tostring(e))
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
-- subtitle/vtt tests: ffmpeg's WebVTT output of a random script (times, text), a hand-written file with a header,
|
||||
-- STYLE / REGION / NOTE blocks, ids, settings and hour timestamps against ffmpeg's SRT conversion of it, round trips
|
||||
-- through the encoder, the contract and the fuzz pass. Fixtures: tools/fixtures/subtitles.py.
|
||||
-- subtitle/vtt tests: ffmpeg's WebVTT output and a hand-written file against ffmpeg's SRT conversion.
|
||||
-- Fixtures: tools/fixtures/subtitles.py.
|
||||
local T = require("@tests/T")
|
||||
local Vtt = require("@rosetta/subtitle/vtt")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -76,7 +75,6 @@ do
|
||||
local back = decode(buffer.tostring(Vtt.encode(v) :: buffer))
|
||||
t:eq(back.meta.css[1], v.meta.css[1], "rt css")
|
||||
t:eq(back.meta.regions[1], v.meta.regions[1], "rt region")
|
||||
-- text that WebVTT cannot hold
|
||||
local w = Vtt.encode({ kind = "subtitles", cues = { { start = 0, stop = 1, text = "a\n\nb --> c" } }, styles = {}, meta = {} } :: any) :: buffer
|
||||
local wb = Vtt.decode(Bytes.reader(w))
|
||||
t:eq(wb.cues[1].text, "a\nb --> c", "blank lines dropped, arrow escaped")
|
||||
|
||||
Reference in new issue
Block a user