forked from coder/claudecode.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbusted_setup.lua
More file actions
112 lines (105 loc) · 3.23 KB
/
busted_setup.lua
File metadata and controls
112 lines (105 loc) · 3.23 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
-- Test setup for busted
-- Create mock vim API if we're running tests outside of Neovim
if not _G.vim then
_G.vim = require("tests.mocks.vim")
end
-- Ensure vim global is accessible
_G.vim = _G.vim or {}
-- Setup test globals
_G.assert = require("luassert")
-- Helper function to verify expectations
_G.expect = function(value)
return {
to_be = function(expected)
assert.are.equal(expected, value)
end,
to_be_nil = function()
assert.is_nil(value)
end,
to_be_true = function()
assert.is_true(value)
end,
to_be_false = function()
assert.is_false(value)
end,
to_be_table = function()
assert.is_table(value)
end,
to_be_string = function()
assert.is_string(value)
end,
to_be_function = function()
assert.is_function(value)
end,
to_be_boolean = function()
assert.is_boolean(value)
end,
to_be_at_least = function(expected)
assert.is_true(value >= expected)
end,
to_have_key = function(key)
assert.is_table(value)
assert.not_nil(value[key])
end,
-- to_contain was here, moved to _G.assert_contains
not_to_be_nil = function()
assert.is_not_nil(value)
end,
-- not_to_contain was here, moved to _G.assert_not_contains
to_be_truthy = function()
assert.is_truthy(value)
end,
}
end
_G.assert_contains = function(actual_value, expected_pattern)
if type(actual_value) == "string" then
if type(expected_pattern) ~= "string" then
error(
"assert_contains expected a string pattern for a string actual_value, but expected_pattern was type: "
.. type(expected_pattern)
)
end
assert.is_true(
string.find(actual_value, expected_pattern, 1, true) ~= nil,
"Expected string '" .. actual_value .. "' to contain '" .. expected_pattern .. "'"
)
elseif type(actual_value) == "table" then
local found = false
for _, v in ipairs(actual_value) do
if v == expected_pattern then
found = true
break
end
end
assert.is_true(found, "Expected table to contain value: " .. tostring(expected_pattern))
else
error("assert_contains can only be used with string or table actual_values, got type: " .. type(actual_value))
end
end
_G.assert_not_contains = function(actual_value, expected_pattern)
if type(actual_value) == "string" then
if type(expected_pattern) ~= "string" then
error(
"assert_not_contains expected a string pattern for a string actual_value, but expected_pattern was type: "
.. type(expected_pattern)
)
end
assert.is_true(
string.find(actual_value, expected_pattern, 1, true) == nil,
"Expected string '" .. actual_value .. "' NOT to contain '" .. expected_pattern .. "'"
)
elseif type(actual_value) == "table" then
local found = false
for _, v in ipairs(actual_value) do
if v == expected_pattern then
found = true
break
end
end
assert.is_false(found, "Expected table NOT to contain value: " .. tostring(expected_pattern))
else
error("assert_not_contains can only be used with string or table actual_values, got type: " .. type(actual_value))
end
end
-- Return true to indicate setup was successful
return true