import test from "node:test"; import assert from "node:assert/strict"; import { normalizeSubLangs, SUB_LANGS_MAX_LENGTH, subLangsProblem } from "./channelConfig"; // Configure's caption languages (subLangs): what yt-dlp's --sub-langs can use // is saved; what would fail every caption download is refused at the save. test("subLangsProblem accepts yt-dlp's forms: regexes, all, exclusions, spaces around entries", () => { for (const ok of ["en.*", "en.*,live_chat", "all,-live_chat", "en,es,fr", "en-US", "en(-GB)?", " en.* , es ", ""]) { assert.equal(subLangsProblem(ok), null, ok); } assert.equal(normalizeSubLangs(" en.* , es "), "en.*,es"); }); test("subLangsProblem refuses an empty entry, a space inside an entry, a bare dash, a bad regex, an over-long value", () => { assert.match(subLangsProblem("en,,es") ?? "", /has an empty entry/); assert.match(subLangsProblem("en,") ?? "", /has an empty entry/); assert.match(subLangsProblem("en us") ?? "", /entry "en us" has a space in it/); assert.match(subLangsProblem("en,-") ?? "", /entry "-" excludes nothing/); assert.match(subLangsProblem("en(") ?? "", /entry "en\(" is not a valid regular expression/); assert.match(subLangsProblem("-[") ?? "", /entry "-\[" is not a valid regular expression/); assert.match(subLangsProblem("e".repeat(SUB_LANGS_MAX_LENGTH + 1)) ?? "", /at most 200/); });