diff options
Diffstat (limited to 'tests')
-rw-r--r--tests/extensions/fake-lexers/lexer.lua33
-rw-r--r--tests/extensions/test-syntax-highlight.lua4
2 files changed, 21 insertions, 16 deletions
diff --git a/tests/extensions/fake-lexers/lexer.lua b/tests/extensions/fake-lexers/lexer.lua
index 0632744..ea7768e 100644
--- a/tests/extensions/fake-lexers/lexer.lua
+++ b/tests/extensions/fake-lexers/lexer.lua
@@ -11,29 +11,30 @@ local M = {}
-- Tokens come back the way Scintillua returns them, one flat list of a tag
-- name and the position just past the token it names. Letter runs are
-- keywords, digit runs are numbers, a single quoted run carries a dotted tag
--- so the dotted first component lookup gets exercised, and any other byte is
--- whitespace, which maps to no css class.
+-- so the dotted first component lookup gets exercised, a run after a colon or
+-- a dollar sign takes one of the tags only the css lexer uses, and any other
+-- byte is whitespace, which maps to no css class.
+local patterns = {
+ { "^:%a+", "pseudoclass" },
+ { "^%$%a+", "property" },
+ { "^%a+", "keyword" },
+ { "^%d+", "number" },
+ { "^'[^']*'", "string.double" },
+}
+
local function lex_words(self, text)
local tokens = {}
local pos = 1
while pos <= #text do
- local start, stop = text:find("^%a+", pos)
- if not start then
- start, stop = text:find("^%d+", pos)
+ local tag, stop = "whitespace", pos
+ for _, pattern in ipairs(patterns) do
+ local start, finish = text:find(pattern[1], pos)
if start then
- tokens[#tokens + 1] = "number"
- else
- start, stop = text:find("^'[^']*'", pos)
- if start then
- tokens[#tokens + 1] = "string.double"
- else
- stop = pos
- tokens[#tokens + 1] = "whitespace"
- end
+ tag, stop = pattern[2], finish
+ break
end
- else
- tokens[#tokens + 1] = "keyword"
end
+ tokens[#tokens + 1] = tag
tokens[#tokens + 1] = stop + 1
pos = stop + 1
end
diff --git a/tests/extensions/test-syntax-highlight.lua b/tests/extensions/test-syntax-highlight.lua
index f831b01..50c7bc8 100644
--- a/tests/extensions/test-syntax-highlight.lua
+++ b/tests/extensions/test-syntax-highlight.lua
@@ -55,6 +55,10 @@ h.contains("bytes between tokens are escaped", out, " &amp; ")
h.contains("later tokens still highlight", out, "<span class='hl-keyword'>zz</span>")
h.equals("close answers zero", ret, 0)
+out = render("hello.fake", "$color :hover")
+h.contains("a css property takes the number class", out, "<span class='hl-number'>$color</span>")
+h.contains("a css pseudo-class takes the function class", out, "<span class='hl-func'>:hover</span>")
+
out = h.run({ "split.fake" }, { "i", "f" })
h.equals("writes are joined before lexing", out, "<span class='hl-keyword'>if</span>")