@@ -11,43 +11,43 @@ describe('terminal module', function()
1111 local git
1212 local vim_cmd_calls = {}
1313 local win_ids = {}
14-
14+
1515 before_each (function ()
1616 -- Reset tracking variables
1717 vim_cmd_calls = {}
1818 win_ids = {}
19-
19+
2020 -- Mock vim functions
2121 _G .vim = _G .vim or {}
2222 _G .vim .api = _G .vim .api or {}
2323 _G .vim .fn = _G .vim .fn or {}
2424 _G .vim .bo = _G .vim .bo or {}
2525 _G .vim .o = _G .vim .o or { lines = 100 }
26-
26+
2727 -- Mock vim.cmd
2828 _G .vim .cmd = function (cmd )
2929 table.insert (vim_cmd_calls , cmd )
3030 return true
3131 end
32-
32+
3333 -- Mock vim.api.nvim_buf_is_valid
3434 _G .vim .api .nvim_buf_is_valid = function (bufnr )
3535 return bufnr ~= nil
3636 end
37-
37+
3838 -- Mock vim.fn.win_findbuf
3939 _G .vim .fn .win_findbuf = function (bufnr )
4040 return win_ids
4141 end
42-
42+
4343 -- Mock vim.fn.bufnr
4444 _G .vim .fn .bufnr = function (pattern )
45- if pattern == " % " then
45+ if pattern == ' % ' then
4646 return 42
4747 end
4848 return 42
4949 end
50-
50+
5151 -- Mock vim.api.nvim_win_close
5252 _G .vim .api .nvim_win_close = function (win_id , force )
5353 -- Remove the window from win_ids
@@ -59,12 +59,12 @@ describe('terminal module', function()
5959 end
6060 return true
6161 end
62-
62+
6363 -- Mock vim.api.nvim_get_mode
6464 _G .vim .api .nvim_get_mode = function ()
6565 return { mode = ' n' }
6666 end
67-
67+
6868 -- Setup test objects
6969 config = {
7070 command = ' claude' ,
@@ -73,113 +73,113 @@ describe('terminal module', function()
7373 height_ratio = 0.5 ,
7474 enter_insert = true ,
7575 hide_numbers = true ,
76- hide_signcolumn = true
76+ hide_signcolumn = true ,
7777 },
7878 git = {
79- use_git_root = true
80- }
79+ use_git_root = true ,
80+ },
8181 }
82-
82+
8383 claude_code = {
8484 claude_code = {
8585 bufnr = nil ,
86- saved_updatetime = nil
87- }
86+ saved_updatetime = nil ,
87+ },
8888 }
89-
89+
9090 git = {
9191 get_git_root = function ()
9292 return ' /test/git/root'
93- end
93+ end ,
9494 }
9595 end )
96-
96+
9797 describe (' toggle' , function ()
9898 it (' should open terminal window when Claude Code is not running' , function ()
9999 -- Claude Code is not running (bufnr is nil)
100100 claude_code .claude_code .bufnr = nil
101-
101+
102102 -- Call toggle
103103 terminal .toggle (claude_code , config , git )
104-
104+
105105 -- Check that commands were called to create window
106106 local botright_cmd_found = false
107107 local resize_cmd_found = false
108108 local terminal_cmd_found = false
109-
109+
110110 for _ , cmd in ipairs (vim_cmd_calls ) do
111111 if cmd == ' botright split' then
112112 botright_cmd_found = true
113113 elseif cmd :match (' ^resize %d+$' ) then
114114 resize_cmd_found = true
115- elseif cmd :match (' ^terminal claude ' ) then
115+ elseif cmd :match (' ^terminal' ) then
116116 terminal_cmd_found = true
117117 end
118118 end
119-
120- assert .is_true (botright_cmd_found , " Botright split command should be called" )
121- assert .is_true (resize_cmd_found , " Resize command should be called" )
122- assert .is_true (terminal_cmd_found , " Terminal command should be called" )
123-
119+
120+ assert .is_true (botright_cmd_found , ' Botright split command should be called' )
121+ assert .is_true (resize_cmd_found , ' Resize command should be called' )
122+ assert .is_true (terminal_cmd_found , ' Terminal command should be called' )
123+
124124 -- Buffer number should be set
125- assert .is_not_nil (claude_code .claude_code .bufnr , " Claude Code buffer number should be set" )
125+ assert .is_not_nil (claude_code .claude_code .bufnr , ' Claude Code buffer number should be set' )
126126 end )
127-
127+
128128 it (' should use git root when configured' , function ()
129129 -- Claude Code is not running (bufnr is nil)
130130 claude_code .claude_code .bufnr = nil
131-
131+
132132 -- Set git config to use root
133133 config .git .use_git_root = true
134-
134+
135135 -- Call toggle
136136 terminal .toggle (claude_code , config , git )
137-
137+
138138 -- Check that git root was used in terminal command
139139 local git_root_cmd_found = false
140-
140+
141141 for _ , cmd in ipairs (vim_cmd_calls ) do
142- if cmd :match (' terminal claude %-%-cwd /test/git/root' ) then
142+ if cmd :match (' terminal pushd /test/git/root && ' .. config . command .. ' && popd ' ) then
143143 git_root_cmd_found = true
144144 break
145145 end
146146 end
147-
148- assert .is_true (git_root_cmd_found , " Terminal command should include git root" )
147+
148+ assert .is_true (git_root_cmd_found , ' Terminal command should include git root' )
149149 end )
150-
150+
151151 it (' should close window when Claude Code is visible' , function ()
152152 -- Claude Code is running and visible
153153 claude_code .claude_code .bufnr = 42
154- win_ids = {100 , 101 } -- Windows displaying the buffer
155-
154+ win_ids = { 100 , 101 } -- Windows displaying the buffer
155+
156156 -- Create a function to clear the win_ids array
157157 _G .vim .api .nvim_win_close = function (win_id , force )
158158 -- Remove all windows from win_ids
159159 win_ids = {}
160160 return true
161161 end
162-
162+
163163 -- Call toggle
164164 terminal .toggle (claude_code , config , git )
165-
165+
166166 -- Check that the windows were closed
167- assert .are .equal (0 , # win_ids , " Windows should be closed" )
167+ assert .are .equal (0 , # win_ids , ' Windows should be closed' )
168168 end )
169-
169+
170170 it (' should reopen window when Claude Code exists but is hidden' , function ()
171171 -- Claude Code is running but not visible
172172 claude_code .claude_code .bufnr = 42
173173 win_ids = {} -- No windows displaying the buffer
174-
174+
175175 -- Call toggle
176176 terminal .toggle (claude_code , config , git )
177-
177+
178178 -- Check that commands were called to reopen window
179179 local botright_cmd_found = false
180180 local resize_cmd_found = false
181181 local buffer_cmd_found = false
182-
182+
183183 for _ , cmd in ipairs (vim_cmd_calls ) do
184184 if cmd == ' botright split' then
185185 botright_cmd_found = true
@@ -189,42 +189,42 @@ describe('terminal module', function()
189189 buffer_cmd_found = true
190190 end
191191 end
192-
193- assert .is_true (botright_cmd_found , " Botright split command should be called" )
194- assert .is_true (resize_cmd_found , " Resize command should be called" )
195- assert .is_true (buffer_cmd_found , " Buffer command should be called with correct buffer number" )
192+
193+ assert .is_true (botright_cmd_found , ' Botright split command should be called' )
194+ assert .is_true (resize_cmd_found , ' Resize command should be called' )
195+ assert .is_true (buffer_cmd_found , ' Buffer command should be called with correct buffer number' )
196196 end )
197197 end )
198-
198+
199199 describe (' force_insert_mode' , function ()
200200 it (' should check insert mode conditions in terminal buffer' , function ()
201201 -- For this test, we'll just verify that the function can be called without error
202202 local success , _ = pcall (function ()
203203 -- Setup minimal mock
204204 local mock_claude_code = {
205205 claude_code = {
206- bufnr = 1
207- }
206+ bufnr = 1 ,
207+ },
208208 }
209209 terminal .force_insert_mode (mock_claude_code )
210210 end )
211-
212- assert .is_true (success , " Force insert mode function should run without error" )
211+
212+ assert .is_true (success , ' Force insert mode function should run without error' )
213213 end )
214-
214+
215215 it (' should handle non-terminal buffers correctly' , function ()
216216 -- For this test, we'll just verify that the function can be called without error
217217 local success , _ = pcall (function ()
218218 -- Setup minimal mock that's different from terminal buffer
219219 local mock_claude_code = {
220220 claude_code = {
221- bufnr = 2
222- }
221+ bufnr = 2 ,
222+ },
223223 }
224224 terminal .force_insert_mode (mock_claude_code )
225225 end )
226-
227- assert .is_true (success , " Force insert mode function should run without error" )
226+
227+ assert .is_true (success , ' Force insert mode function should run without error' )
228228 end )
229229 end )
230- end )
230+ end )
0 commit comments