-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_init.lua
More file actions
82 lines (66 loc) · 2.06 KB
/
test_init.lua
File metadata and controls
82 lines (66 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
local T = MiniTest.new_set()
T["setup()"] = function()
local gitlogdiff = require("gitlogdiff")
gitlogdiff.setup({ max_count = 100 })
MiniTest.expect.equality(gitlogdiff.config.max_count, 100)
end
T["actions"] = MiniTest.new_set()
local original_cmd = vim.cmd
T["actions"].before_each = function()
vim.cmd = function() end
end
T["actions"].after_each = function()
vim.cmd = original_cmd
end
T["actions"]["show_selected() diffs single commit correctly"] = function()
local actions = require("gitlogdiff.actions")
local cmds = {}
vim.cmd = function(cmd)
table.insert(cmds, cmd)
end
actions.show_selected({ "abc1234" }, { 1 })
MiniTest.expect.equality(cmds[1], "DiffviewOpen abc1234^..abc1234")
end
T["actions"]["show_selected() diffs two commits correctly"] = function()
local actions = require("gitlogdiff.actions")
local cmds = {}
vim.cmd = function(cmd)
table.insert(cmds, cmd)
end
actions.show_selected({ "newer123", "older456" }, { 1, 2 })
MiniTest.expect.equality(cmds[1], "DiffviewOpen older456^..newer123")
end
T["actions"]["show_selected() handles non-consecutive commits correctly"] = function()
local actions = require("gitlogdiff.actions")
local cmds = {}
vim.cmd = function(cmd)
table.insert(cmds, cmd)
end
actions.show_selected({ "newer123", "older789" }, { 1, 3 })
MiniTest.expect.equality(cmds[1], "DiffviewOpen older789^..newer123")
end
T["log"] = MiniTest.new_set()
T["log"]["get_commits() parses git log correctly"] = function()
local log = require("gitlogdiff.log")
local original_system = vim.system
local original_schedule = vim.schedule
vim.schedule = function(fn)
fn()
end
vim.system = function(args, _, cb)
cb({
code = 0,
stdout = "h1 2023-01-01 commit1\nh2 2023-01-02 commit2\n",
stderr = "",
})
return {}
end
local result = nil
log.get_commits(function(commits)
result = commits
end)
MiniTest.expect.equality(result, { "h1 2023-01-01 commit1", "h2 2023-01-02 commit2" })
vim.system = original_system
vim.schedule = original_schedule
end
return T