From 3757bab25c88cfb9d0c85ae9c86047b190a83b2d Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 10:51:47 -1000 Subject: Check the lexer modules the filter cannot use A module called lexer that is not Scintillua, a Scintillua older than 6.0 without detect(), lexers that cannot load lpeg and a lexer that returns no token list were all documented and none was tried. --- tests/extensions/test-syntax-highlight.lua | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'tests/extensions/test-syntax-highlight.lua') diff --git a/tests/extensions/test-syntax-highlight.lua b/tests/extensions/test-syntax-highlight.lua index d8e5224..90ef5b9 100644 --- a/tests/extensions/test-syntax-highlight.lua +++ b/tests/extensions/test-syntax-highlight.lua @@ -66,6 +66,46 @@ if mode == "nolexers" then h.equals("and the error log says none were found", h.error_log(), "[cgit] Unable to find the Scintillua lexers, so source is shown uncoloured\n") + -- The filter takes a module called lexer only when it is Scintillua, so + -- one that is something else is never used. A Scintillua older than 6.0 + -- has no detect() and colours nothing, and lexers that need a missing + -- lpeg say why in the log. Each loads the filter afresh with the module + -- it finds forced through package.preload. + local function load_with_lexer(loader) + package.loaded.lexer = nil + package.preload.lexer = loader + h.setenv("CGIT_SCINTILLUA_PATH", "/nonexistent") + h.load(script) + end + + local used = false + load_with_lexer(function() + return { detect = function() used = true end } + end) + out = render("hello.fake", "a ") + h.equals("a lexer module without load is passed over", out, "a <b>") + h.check("and never used", not used) + h.equals("and the error log stays empty", h.error_log(), "") + + load_with_lexer(function() + return { load = function() return { lex = function() return { "keyword", 2 } end } end } + end) + out = render("hello.fake", "a ") + h.equals("a Scintillua without detect colours nothing", out, "a <b>") + h.equals("and logs nothing", h.error_log(), "") + + h.preload_failure("lpeg") + load_with_lexer(function() + return require("lpeg") + end) + out = render("hello.fake", "a ") + h.equals("lexers that cannot load lpeg leave the source uncoloured", out, "a <b>") + local log = h.error_log() + local prefix = "[cgit] Unable to load the Scintillua lexers: " + h.equals("and the error log says why", log:sub(1, #prefix), prefix) + h.contains("naming lpeg", log, "lpeg deliberately unavailable") + h.equals("on one line", log:find("\n", 1, true), #log) + h.finish() end @@ -96,6 +136,9 @@ h.equals("a lexer stopping early leaves an escaped tail", out, "if") -- cgit 2.12.1