aboutsummaryrefslogtreecommitdiffstats
path: root/lua/alpha
diff options
context:
space:
mode:
authorAriel D'Alessandro <dalessandro.ariel@gmail.com>2023-09-01 14:00:10 +0200
committerAriel D'Alessandro <dalessandro.ariel@gmail.com>2023-09-01 14:00:10 +0200
commit96c4f3ca9c9836ff926ec5969d29007e725ee68b (patch)
treea3669f45e80ebc8644506c476125515f810edf2e /lua/alpha
parentf4fe416201cc9d1cba5dfa3fec0879601fb85ae7 (diff)
downloadnvim-conf-96c4f3ca9c9836ff926ec5969d29007e725ee68b.tar.gz
nvim-conf-96c4f3ca9c9836ff926ec5969d29007e725ee68b.zip
change test strategies
Diffstat (limited to 'lua/alpha')
-rw-r--r--lua/alpha/test_menu.lua4
-rw-r--r--lua/alpha/test_strategy.lua65
2 files changed, 68 insertions, 1 deletions
diff --git a/lua/alpha/test_menu.lua b/lua/alpha/test_menu.lua
index 5b3e5a5..afe3a9e 100644
--- a/lua/alpha/test_menu.lua
+++ b/lua/alpha/test_menu.lua
@@ -2,7 +2,8 @@ local hydra = require "hydra"
local hint = [[
Vim Tests
- _n_: Near test _f_: Current file _s_: Test Suit ^
+ _n_: Near test _h_: Harpoon ^
+ _f_: Current file _s_: Test Suit ^
_l_: Test Last _g_: Visit
_w_: Watch last Test _p_: stop watch
^ ^ _<Esc>_ ^
@@ -37,6 +38,7 @@ hydra {
body = "<leader>t",
heads = {
{ "n", ":TestNearest<CR>" },
+ { "h", ":TestNearest -strategy=harpoon<CR>" },
{ "f", ":TestFile<CR>" },
{ "s", ":TestSuit<CR>" },
{ "l", ":TestLast<CR>" },
diff --git a/lua/alpha/test_strategy.lua b/lua/alpha/test_strategy.lua
new file mode 100644
index 0000000..46aae3c
--- /dev/null
+++ b/lua/alpha/test_strategy.lua
@@ -0,0 +1,65 @@
+local Job = require "plenary.job"
+
+local function splitString(input_string)
+ local parts = {}
+ local in_quote = false
+ local part_start = 1
+
+ for i = 1, #input_string do
+ local char = input_string:sub(i, i)
+
+ if char == "'" then
+ in_quote = not in_quote
+ elseif char == " " and not in_quote then
+ local part = input_string:sub(part_start, i - 1)
+ -- Remove surrounding quotes if they exist
+ if part:sub(1, 1) == "'" and part:sub(-1) == "'" then
+ part = part:sub(2, -2)
+ end
+ table.insert(parts, part)
+ part_start = i + 1
+ end
+ end
+
+ -- Add the last part (and remove surrounding quotes if they exist)
+ local part = input_string:sub(part_start)
+ if part:sub(1, 1) == "'" and part:sub(-1) == "'" then
+ part = part:sub(2, -2)
+ end
+ table.insert(parts, part)
+
+ return parts
+end
+
+local function myStrategy(cmd)
+ --convert cmd from string to table
+ if type(cmd) == "string" then
+ -- do not split quoted parts of the string
+ cmd = splitString(cmd)
+ end
+
+ -- get first element of cmd and remove from the cmd
+ local cmd_name = table.remove(cmd, 1)
+
+ ---@diagnostic disable-next-line: missing-fields
+ Job:new({
+ command = cmd_name,
+ args = cmd,
+ on_exit = function(j, return_val)
+ -- in case of result val 0 show success message
+ if return_val == 0 then
+ vim.notify("Test run successfully", vim.log.levels.INFO, { title = "Test" })
+ return
+ end
+ local result = j:stderr_result()
+ -- join result in a single string
+ result = table.concat(result, "\n")
+ -- escape / characters
+ result = result:gsub("/", "\\/")
+ vim.notify(result, vim.log.levels.ERROR, { title = "Test" })
+ end,
+ }):start()
+end
+
+vim.g["test#custom_strategies"] = { myStrategy = myStrategy }
+vim.g["test#strategy"] = "myStrategy"