Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
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.
Diffstat (limited to 'tests/extensions')
| -rw-r--r-- | tests/extensions/fake-lexers/lexer.lua | 14 | |
| -rw-r--r-- | tests/extensions/test-syntax-highlight.lua | 43 |
2 files changed, 54 insertions, 3 deletions
diff --git a/tests/extensions/fake-lexers/lexer.lua b/tests/extensions/fake-lexers/lexer.lua index bb869de..c9d8cff 100644 --- a/tests/extensions/fake-lexers/lexer.lua +++ b/tests/extensions/fake-lexers/lexer.lua @@ -3,8 +3,9 @@ -- real collection installed. detect() answers for the suffixes it knows, -- matched by case as Scintillua's own does, or fake for a shebang naming it, -- and load() hands out the toy lexer of that name. Besides fake there is one --- that stops short and one that raises, and python, which detect() knows but --- load() cannot find, as a collection missing a lexer would answer. +-- that stops short, one that raises and one that returns no tokens at all, +-- and python, which detect() knows but load() cannot find, as a collection +-- missing a lexer would answer. local M = {} @@ -54,10 +55,15 @@ local function lex_raise(self, text) error("this lexer always raises") end +local function lex_nothing(self, text) + return nil +end + local lexers = { fake = { lex = lex_words }, short = { lex = lex_short }, badlex = { lex = lex_raise }, + nothing = { lex = lex_nothing }, } function M.load(name) @@ -68,7 +74,9 @@ function M.load(name) return lexer end -local suffixes = { fake = "fake", short = "short", badlex = "badlex", py = "python" } +local suffixes = { + fake = "fake", short = "short", badlex = "badlex", nothing = "nothing", py = "python", +} function M.detect(filename, line) if line ~= nil and line:match("^#!.*fake") then 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 <b>") + 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 <b>") + 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 <b>") + 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, "<span class='hl- out = render("boom.badlex", "some <code>") h.equals("a lexer that raises falls back to escaped text", out, "some <code>") +out = render("empty.nothing", "some <code>") +h.equals("a lexer that returns no tokens falls back to escaped text", out, "some <code>") + out = render("HELLO.FAKE", "if 42") h.contains("an extension in capitals finds its lexer", out, "<span class='hl-keyword'>if</span>") |
