forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.lua
More file actions
90 lines (85 loc) · 2.17 KB
/
utils.lua
File metadata and controls
90 lines (85 loc) · 2.17 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
83
84
85
86
87
88
89
90
local M = {
expect_match = MiniTest.new_expectation(
-- Expectation subject
"string matching",
-- Predicate
---@param str string|number
---@param pattern string|number
function(str, pattern)
return str:find(pattern) ~= nil
end,
-- Fail context
---@param str string|number
---@param pattern string|number
function(str, pattern)
return string.format("Pattern: %s\nObserved string: %s", vim.inspect(pattern), str)
end
),
expect_no_match = MiniTest.new_expectation(
-- Expectation subject
"no string matching",
-- Predicate
---@param str string|number
---@param pattern string|number
function(str, pattern)
return str:find(pattern) == nil
end,
-- Fail context
---@param str string|number
---@param pattern string|number
function(str, pattern)
return string.format("Pattern: %s\nObserved string: %s", vim.inspect(pattern), str)
end
),
expect_not_empty = MiniTest.new_expectation(
-- Expectation subject
"not empty",
-- Predicate
---@param val any|nil
function(val)
if val == nil or val == vim.NIL then
return false
end
if type(val) == "string" then
return val ~= ""
elseif type(val) == "table" then
return val ~= {}
end
return true
end,
-- Fail context
---@param _ any|nil
function(_)
return "Expected value to be not empty"
end
),
expect_empty = MiniTest.new_expectation(
-- Expectation subject
"empty",
-- Predicate
---@param val any|nil
function(val)
if val == nil or val == vim.NIL then
return true
end
if type(val) == "string" then
return val == ""
elseif type(val) == "table" then
return val == {}
end
return false
end,
-- Fail context
---@param val any|nil
function(val)
return "Expected value to be empty\nObserved value: " .. vim.inspect(val)
end
),
set_lines = function(child, lines)
child.api.nvim_buf_set_lines(0, 0, -1, true, lines)
end,
get_lines = function(child)
return child.api.nvim_buf_get_lines(0, 0, -1, true)
end,
}
return M