-- Unit checks for custom/extensions/syntax-highlight.lua, run under a -- standalone Lua by t0502-syntax-highlight.sh with the script path as the -- first argument. The filter remembers whether the lexers loaded for the -- life of the interpreter, so the two sides of that split are two runs of -- this file. In highlight mode the shell points CGIT_SCINTILLUA_PATH at the -- fake-lexers directory beside this file and every path through a working -- lexer is checked, and in nolexers mode it points at an empty directory so -- the escaped fallback is what everything renders through. local test_directory = arg[0]:match("^(.*)/") or "." local h = dofile(test_directory .. "/harness.lua") local script = arg[1] local mode = arg[2] or "highlight" h.load(script) local function render(filename, text) return h.run({ filename }, { text }) end if mode == "nolexers" then local out, ret = render("hello.fake", "if 42") h.equals("without lexers source is served escaped", out, "if 42") h.equals("close answers zero", ret, 0) out = render("hello.fake", "a & c") h.equals("the fallback escapes markup", out, "a <b> & c") -- Large output leaves in slices, and a byte lost at a boundary would -- put the line numbers beside it out of step, so the whole escaped -- blob has to come back intact across several slices. out = render("big.fake", string.rep("x", 30000)) h.equals("slicing loses nothing at the boundaries", out, string.rep("x<y>", 30000)) h.finish() end local out, ret = render("hello.fake", "if 42 'hi' & zz") h.contains("keywords are wrapped in their class", out, "if") h.contains("numbers are wrapped in their class", out, "42") h.contains("a dotted tag maps by its first component", out, "'hi'") h.contains("bytes between tokens are escaped", out, " & ") h.contains("later tokens still highlight", out, "zz") h.equals("close answers zero", ret, 0) out = h.run({ "split.fake" }, { "i", "f" }) h.equals("writes are joined before lexing", out, "if") -- The short lexer tags four bytes and stops, and every byte after it still -- has to reach the page. out = render("cut.short", "abcd") h.equals("a lexer stopping early leaves an escaped tail", out, "abcd<ef>") out = render("boom.badlex", "some ") h.equals("a lexer that raises falls back to escaped text", out, "some <code>") -- The viadetect lexer name only resolves through detect(), so highlighted -- output proves the detection path ran ahead of the extension path. out = render("script.viadetect", "if") h.equals("filename detection picks the lexer", out, "if") out = render("tool.py", "import ") h.equals("an extension with no lexer serves escaped text", out, "import <x>") out = render("noextension", "words ") h.equals("a file with no extension serves escaped text", out, "words <here>") out = render("big.fake", string.rep("a", 512 * 1024 + 1)) h.excludes("an oversized blob skips the lexing pass", out, "