diff options
Diffstat (limited to '_selfcheck.lua')
| -rw-r--r-- | _selfcheck.lua | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/_selfcheck.lua b/_selfcheck.lua new file mode 100644 index 0000000..29f36de --- /dev/null +++ b/_selfcheck.lua @@ -0,0 +1,82 @@ +-- Self-check for themes.popular. Run with: panto lua _selfcheck.lua + +local here = debug.getinfo(1, "S").source:match("^@(.*)/[^/]+$") or "." +package.path = here .. "/?.lua;" .. package.path + +local roles = { + "dim", "assistant", "user", "tool", "footer", "tool_text", + "tool_pending", "tool_success", "tool_error", "compaction_header", + "thinking_header", "cursor", "err", "welcome", "waiting_peak", + "waiting_near", "waiting_far", "err_diff", "add_diff", "thinking", + "compaction", "user_bg", "tool_pending_bg", "tool_success_bg", + "tool_error_bg", "diff_remove_bg", "diff_add_bg", "user_text", + "tool_header", "canvas_fg", "canvas_bg", "syntax_base", + "syntax_comment", "syntax_string", "syntax_number", "syntax_keyword", + "syntax_function", "syntax_type", "syntax_variable", "syntax_tag", +} + +local names = { + "Tokyo Night", "Catppuccin Mocha", "Gruvbox Dark", "Solarized Light", + "Solarized Dark", "Nord", "Dracula", "Tokyo Storm", "Tokyo Moon", + "Tokyo Day", "Catppuccin Latte", "Catppuccin Frappe", + "Catppuccin Macchiato", "Gruvbox Dark Hard", "Gruvbox Dark Soft", + "Gruvbox Light", "Gruvbox Light Hard", "Gruvbox Light Soft", + "Dracula Soft", "Kanagawa Wave", "Kanagawa Dragon", "Kanagawa Lotus", +} + +local function copy(t) + local out = {} + for k, v in pairs(t) do out[k] = v end + return out +end + +local registered = {} +package.loaded["panto"] = { + ext = { + style = function(name, values) + assert(type(name) == "string") + assert(type(values) == "table", "registration values for " .. name) + local old = registered[name] + if old then + for k, v in pairs(values) do + assert(old[k] == v, "conflicting re-registration for " .. name .. ": " .. k) + end + else + registered[name] = copy(values) + end + end, + }, +} + +local entry = require("panto-popular-themes.init") +assert(entry.name == "themes.popular", "entry name") +assert(type(entry.activate) == "function", "entry activate") +entry.activate() + +local count = 0 +for name in pairs(registered) do count = count + 1 end +assert(count == 22, "expected 22 themes, got " .. count) +for _, name in ipairs(names) do + local values = registered[name] + assert(values, "missing theme " .. name) + for _, role in ipairs(roles) do + assert(type(values[role]) == "string", name .. " missing role " .. role) + end + assert(values.reset == "\27[0m", name .. " reset") +end + +local function eq(name, role, expected) + assert(registered[name][role] == expected, + name .. "." .. role .. " was " .. tostring(registered[name][role]) .. + ", expected " .. expected) +end + +eq("Tokyo Night", "tool", "\27[38;2;122;162;247m") +eq("Tokyo Night", "diff_add_bg", "\27[48;2;36;62;74m") +eq("Solarized Light", "diff_add_bg", "\27[48;2;229;227;181m") +eq("Kanagawa Lotus", "canvas_bg", "\27[48;2;242;236;188m") +eq("Kanagawa Lotus", "syntax_tag", "\27[38;2;102;147;191m") + +eq("Kanagawa Wave", "reset", "\27[0m") + +print("selfcheck: OK") |
