Skip to content

Commit

Permalink
✅ Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Dec 11, 2024
1 parent dc9f09a commit de06e5c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lua/prompt/style.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ local prompt = require "prompt"
if table.unpack == nil then table.unpack = unpack end

---wakatime
---@param cmd string
---@param cmd string | nil
---@return string
local function wakatime(cmd)
cmd = cmd or "wakatime-cli --write --plugin=repl-lua-wakatime " ..
"--entity-type=app --entity=lua --alternate-language=lua --project=%s &"
cmd = cmd or ("wakatime-cli --write --plugin=repl-lua-wakatime " ..
"--entity-type=app --entity=lua --alternate-language=lua --project=%s &")
local s, _ = cmd:find("%s")
if s ~= nil then
local project = io.popen("git rev-parse --show-toplevel 2> /dev/null"):read()
Expand Down Expand Up @@ -72,9 +72,9 @@ local function get_icon()
end

---get version
---@param name string
---@param logo string
---@param format string
---@param name string | nil
---@param logo string | nil
---@param format string | nil
---@return string
local function get_version(name, logo, format)
name = name or prompt.name
Expand All @@ -86,7 +86,7 @@ local function get_version(name, logo, format)
end

---get time
---@param format string
---@param format string | nil
---@return string
local function get_time(format)
format = format or "%H:%M:%S"
Expand All @@ -106,17 +106,17 @@ end
---generate ps1.
-- `sections` is an array whose element is like `{ "white", "blue", get_cwd }`
-- and its order determine the order of prompt sections.
---@param char string
---@param char string | nil
---@param sections {(1: integer, 2: integar, 3: string | function(): string) | string}[]
---@return function(): string
local function generate_ps1(char, sections)
char = char or ""
sections = sections or {
---@diagnostic disable: missing-parameter
{ "", "", wakatime },
{ "black", "yellow", get_icon() }, { "blue", "black", get_version() },
{ "white", "blue", get_cwd }, { "black", "white", get_time }
}
---@diagnostic disable: missing-parameter
{ "", "", wakatime },
{ "black", "yellow", get_icon() }, { "blue", "black", get_version() },
{ "white", "blue", get_cwd }, { "black", "white", get_time }
}
local sep = ""
local format = " %s "
return function()
Expand Down
1 change: 1 addition & 0 deletions lua/prompt/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,5 @@ function M.source_configs(configs)
end
end

---@export
return M
4 changes: 4 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ mkShell {
buildInputs = [
(luajit.withPackages (
p: with p; [
ansicolors
luafilesystem
luaprompt

busted
ldoc
]
))
Expand Down
9 changes: 9 additions & 0 deletions spec/test_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local style = require "prompt.style"

-- luacheck: ignore 113
---@diagnostic disable: undefined-global
describe("test", function()
it("tests style", function()
assert.are.equal(style.get_version("Lua", "logo"), "logo " .. _VERSION)
end)
end)

0 comments on commit de06e5c

Please sign in to comment.