Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Drop the highlighter's extension fallback
The table of extensions and the second lookup served only a Scintillua with no detect(), which now leaves every file uncoloured but escaped. The fake detect() names a lexer after the file's suffix, so every test lexer is reached through it.
Diffstat (limited to '')
-rw-r--r--tests/extensions/fake-lexers/lexer.lua14
-rw-r--r--tests/extensions/test-syntax-highlight.lua5
2 files changed, 5 insertions, 14 deletions
diff --git a/tests/extensions/fake-lexers/lexer.lua b/tests/extensions/fake-lexers/lexer.lua
index ea7768e..dd7545f 100644
--- a/tests/extensions/fake-lexers/lexer.lua
+++ b/tests/extensions/fake-lexers/lexer.lua
@@ -1,10 +1,9 @@
-- A miniature stand-in for the Scintillua lexer module, just enough for the
-- syntax-highlight checks to drive every path through the filter without the
--- real collection installed. load() hands out one of the toy lexers below by
--- name and detect() recognises a single filename suffix or a shebang naming
--- fake, so a check can tell the detection path apart from the extension path
--- by which lexer ends up running. Anything the filter treats as optional, a lexer that will not
--- load or one that raises while lexing, has a name here too.
+-- real collection installed. detect() names a lexer after the filename's
+-- suffix, 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 any other name fails to load.
local M = {}
@@ -69,13 +68,10 @@ function M.load(name)
end
function M.detect(filename, line)
- if filename:match("%.viadetect$") then
- return "fake"
- end
if line ~= nil and line:match("^#!.*fake") then
return "fake"
end
- return nil
+ return filename:match("%.([^.]+)$")
end
return M
diff --git a/tests/extensions/test-syntax-highlight.lua b/tests/extensions/test-syntax-highlight.lua
index 50c7bc8..f9f99a8 100644
--- a/tests/extensions/test-syntax-highlight.lua
+++ b/tests/extensions/test-syntax-highlight.lua
@@ -70,11 +70,6 @@ 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 &lt;code&gt;")
--- 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, "<span class='hl-keyword'>if</span>")
-
out = render("post-receive", "#!/usr/bin/fake\nif")
h.contains("a shebang picks the lexer of a file with no extension", out,
"<span class='hl-keyword'>if</span>")