forked from coder/claudecode.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.lua
More file actions
217 lines (203 loc) · 5.09 KB
/
config_test.lua
File metadata and controls
217 lines (203 loc) · 5.09 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
-- Simple config module tests that don't rely on the vim API
_G.vim = { ---@type vim_global_api
schedule_wrap = function(fn)
return fn
end,
deepcopy = function(t)
-- Basic deepcopy implementation for testing purposes
local copy = {}
for k, v in pairs(t) do
if type(v) == "table" then
copy[k] = _G.vim.deepcopy(v)
else
copy[k] = v
end
end
return copy
end,
notify = function(_, _, _) end,
log = {
levels = {
NONE = 0,
ERROR = 1,
WARN = 2,
INFO = 3,
DEBUG = 4,
TRACE = 5,
},
},
o = { ---@type vim_options_table
columns = 80,
lines = 24,
},
bo = setmetatable({}, { -- Mock for vim.bo and vim.bo[bufnr]
__index = function(t, k)
if type(k) == "number" then
if not t[k] then
t[k] = {} ---@type vim_buffer_options_table
end
return t[k]
end
return nil
end,
__newindex = function(t, k, v)
if type(k) == "number" then
-- For mock simplicity, allows direct setting for vim.bo[bufnr].opt = val or similar assignments.
if not t[k] then
t[k] = {}
end
rawset(t[k], v) -- Assuming v is the option name if k is bufnr, this is simplified
else
rawset(t, k, v)
end
end,
}), ---@type vim_bo_proxy
diagnostic = { ---@type vim_diagnostic_module
get = function()
return {}
end,
-- Add other vim.diagnostic functions as needed for these tests
},
empty_dict = function()
return {}
end,
tbl_deep_extend = function(behavior, ...)
local result = {}
local tables = { ... }
for _, tbl in ipairs(tables) do
for k, v in pairs(tbl) do
if type(v) == "table" and type(result[k]) == "table" then
result[k] = _G.vim.tbl_deep_extend(behavior, result[k], v)
else
result[k] = v
end
end
end
return result
end,
cmd = function() end, ---@type fun(command: string):nil
api = {}, ---@type table
fn = { ---@type vim_fn_table
mode = function()
return "n"
end,
delete = function(_, _)
return 0
end,
filereadable = function(_)
return 1
end,
fnamemodify = function(fname, _)
return fname
end,
expand = function(s, _)
return s
end,
getcwd = function()
return "/mock/cwd"
end,
mkdir = function(_, _, _)
return 1
end,
buflisted = function(_)
return 1
end,
bufname = function(_)
return "mockbuffer"
end,
bufnr = function(_)
return 1
end,
win_getid = function()
return 1
end,
win_gotoid = function(_)
return true
end,
line = function(_)
return 1
end,
col = function(_)
return 1
end,
virtcol = function(_)
return 1
end,
getpos = function(_)
return { 0, 1, 1, 0 }
end,
setpos = function(_, _)
return true
end,
tempname = function()
return "/tmp/mocktemp"
end,
globpath = function(_, _)
return ""
end,
termopen = function(_, _)
return 0
end,
stdpath = function(_)
return "/mock/stdpath"
end,
json_encode = function(_)
return "{}"
end,
json_decode = function(_)
return {}
end,
},
fs = { remove = function() end }, ---@type vim_fs_module
}
describe("Config module", function()
local config
setup(function()
-- Reset the module to ensure a clean state for each test
package.loaded["claudecode.config"] = nil
config = require("claudecode.config")
end)
it("should have default values", function()
assert(type(config.defaults) == "table")
assert(type(config.defaults.port_range) == "table")
assert(type(config.defaults.port_range.min) == "number")
assert(type(config.defaults.port_range.max) == "number")
assert(type(config.defaults.auto_start) == "boolean")
assert(type(config.defaults.log_level) == "string")
assert(type(config.defaults.track_selection) == "boolean")
end)
it("should validate valid configuration", function()
local valid_config = {
port_range = { min = 10000, max = 65535 },
auto_start = true,
terminal_cmd = "toggleterm",
log_level = "debug",
track_selection = false,
visual_demotion_delay_ms = 50,
connection_wait_delay = 200,
connection_timeout = 10000,
queue_timeout = 5000,
diff_opts = {
auto_close_on_accept = true,
show_diff_stats = true,
vertical_split = true,
open_in_current_tab = true,
},
}
local success, _ = pcall(function()
return config.validate(valid_config)
end)
assert(success == true)
end)
it("should merge user config with defaults", function()
local user_config = {
auto_start = true,
log_level = "debug",
}
local merged_config = config.apply(user_config)
assert(merged_config.auto_start == true)
assert("debug" == merged_config.log_level)
assert(config.defaults.port_range.min == merged_config.port_range.min)
assert(config.defaults.track_selection == merged_config.track_selection)
end)
end)