@@ -133,28 +133,22 @@ pub fn list_worktrees_with_ui(manager: &GitWorktreeManager, _ui: &dyn UserInterf
133133 Ok ( ( ) )
134134}
135135
136- #[ cfg( false ) ] // Temporarily disabled due to WorktreeInfo struct field changes
136+ #[ cfg( test ) ]
137137mod tests {
138138 use super :: * ;
139139 use std:: path:: PathBuf ;
140140
141141 #[ test]
142- #[ ignore = "WorktreeInfo struct fields need to be updated" ]
143142 fn test_format_worktree_display_basic ( ) {
144143 let worktree = WorktreeInfo {
145144 name : "feature" . to_string ( ) ,
146145 path : PathBuf :: from ( "/tmp/feature" ) ,
147- branch : Some ( "feature" . to_string ( ) ) ,
148- commit_info : None ,
149- head : "HEAD" . to_string ( ) ,
150- is_bare : false ,
151- is_detached : false ,
152- is_locked : false ,
153- lock_reason : None ,
146+ branch : "feature" . to_string ( ) ,
154147 is_current : false ,
155148 has_changes : false ,
156149 last_commit : None ,
157150 ahead_behind : None ,
151+ is_locked : false ,
158152 } ;
159153
160154 let display = format_worktree_display ( & worktree, false ) ;
@@ -166,17 +160,12 @@ mod tests {
166160 let worktree = WorktreeInfo {
167161 name : "main" . to_string ( ) ,
168162 path : PathBuf :: from ( "/tmp/main" ) ,
169- branch : Some ( "main" . to_string ( ) ) ,
170- commit_info : None ,
171- head : "HEAD" . to_string ( ) ,
172- is_bare : false ,
173- is_detached : false ,
174- is_locked : false ,
175- lock_reason : None ,
163+ branch : "main" . to_string ( ) ,
176164 is_current : true ,
177165 has_changes : false ,
178166 last_commit : None ,
179167 ahead_behind : None ,
168+ is_locked : false ,
180169 } ;
181170
182171 let display = format_worktree_display ( & worktree, false ) ;
@@ -188,17 +177,12 @@ mod tests {
188177 let worktree = WorktreeInfo {
189178 name : "locked" . to_string ( ) ,
190179 path : PathBuf :: from ( "/tmp/locked" ) ,
191- branch : Some ( "locked" . to_string ( ) ) ,
192- commit_info : None ,
193- head : "HEAD" . to_string ( ) ,
194- is_bare : false ,
195- is_detached : false ,
196- is_locked : true ,
197- lock_reason : Some ( "maintenance" . to_string ( ) ) ,
180+ branch : "locked" . to_string ( ) ,
198181 is_current : false ,
199182 has_changes : true ,
200183 last_commit : None ,
201184 ahead_behind : None ,
185+ is_locked : true ,
202186 } ;
203187
204188 let display = format_worktree_display ( & worktree, false ) ;
@@ -210,17 +194,12 @@ mod tests {
210194 let worktree = WorktreeInfo {
211195 name : "feature" . to_string ( ) ,
212196 path : PathBuf :: from ( "/tmp/feature" ) ,
213- branch : Some ( "feature" . to_string ( ) ) ,
214- commit_info : None ,
215- head : "HEAD" . to_string ( ) ,
216- is_bare : false ,
217- is_detached : false ,
218- is_locked : false ,
219- lock_reason : None ,
197+ branch : "feature" . to_string ( ) ,
220198 is_current : false ,
221199 has_changes : false ,
222200 last_commit : None ,
223201 ahead_behind : None ,
202+ is_locked : false ,
224203 } ;
225204
226205 let display = format_worktree_display ( & worktree, true ) ;
@@ -232,17 +211,12 @@ mod tests {
232211 let worktree = WorktreeInfo {
233212 name : "feature-auth" . to_string ( ) ,
234213 path : PathBuf :: from ( "/tmp/feature" ) ,
235- branch : Some ( "feature" . to_string ( ) ) ,
236- commit_info : None ,
237- head : "HEAD" . to_string ( ) ,
238- is_bare : false ,
239- is_detached : false ,
240- is_locked : false ,
241- lock_reason : None ,
214+ branch : "feature" . to_string ( ) ,
242215 is_current : false ,
243216 has_changes : false ,
244217 last_commit : None ,
245218 ahead_behind : None ,
219+ is_locked : false ,
246220 } ;
247221
248222 assert ! ( should_show_worktree( & worktree, false , Some ( "auth" ) ) ) ;
@@ -253,17 +227,12 @@ mod tests {
253227 let worktree = WorktreeInfo {
254228 name : "feature-ui" . to_string ( ) ,
255229 path : PathBuf :: from ( "/tmp/feature" ) ,
256- branch : Some ( "feature" . to_string ( ) ) ,
257- commit_info : None ,
258- head : "HEAD" . to_string ( ) ,
259- is_bare : false ,
260- is_detached : false ,
261- is_locked : false ,
262- lock_reason : None ,
230+ branch : "feature" . to_string ( ) ,
263231 is_current : false ,
264232 has_changes : false ,
265233 last_commit : None ,
266234 ahead_behind : None ,
235+ is_locked : false ,
267236 } ;
268237
269238 assert ! ( !should_show_worktree( & worktree, false , Some ( "auth" ) ) ) ;
@@ -274,17 +243,12 @@ mod tests {
274243 let worktree = WorktreeInfo {
275244 name : "clean" . to_string ( ) ,
276245 path : PathBuf :: from ( "/tmp/clean" ) ,
277- branch : Some ( "clean" . to_string ( ) ) ,
278- commit_info : None ,
279- head : "HEAD" . to_string ( ) ,
280- is_bare : false ,
281- is_detached : false ,
282- is_locked : false ,
283- lock_reason : None ,
246+ branch : "clean" . to_string ( ) ,
284247 is_current : false ,
285248 has_changes : false ,
286249 last_commit : None ,
287250 ahead_behind : None ,
251+ is_locked : false ,
288252 } ;
289253
290254 assert ! ( should_show_worktree( & worktree, true , None ) ) ;
@@ -295,36 +259,135 @@ mod tests {
295259 let clean_worktree = WorktreeInfo {
296260 name : "clean" . to_string ( ) ,
297261 path : PathBuf :: from ( "/tmp/clean" ) ,
298- branch : Some ( "clean" . to_string ( ) ) ,
299- commit_info : None ,
300- head : "HEAD" . to_string ( ) ,
301- is_bare : false ,
302- is_detached : false ,
303- is_locked : false ,
304- lock_reason : None ,
262+ branch : "clean" . to_string ( ) ,
305263 is_current : false ,
306264 has_changes : false ,
307265 last_commit : None ,
308266 ahead_behind : None ,
267+ is_locked : false ,
309268 } ;
310269
311270 let dirty_worktree = WorktreeInfo {
312271 name : "dirty" . to_string ( ) ,
313272 path : PathBuf :: from ( "/tmp/dirty" ) ,
314- branch : Some ( "dirty" . to_string ( ) ) ,
315- commit_info : None ,
316- head : "HEAD" . to_string ( ) ,
317- is_bare : false ,
318- is_detached : false ,
319- is_locked : false ,
320- lock_reason : None ,
273+ branch : "dirty" . to_string ( ) ,
321274 is_current : false ,
322275 has_changes : true ,
323276 last_commit : None ,
324277 ahead_behind : None ,
278+ is_locked : false ,
325279 } ;
326280
327281 assert ! ( !should_show_worktree( & clean_worktree, false , None ) ) ;
328282 assert ! ( should_show_worktree( & dirty_worktree, false , None ) ) ;
329283 }
284+
285+ // Add 5 new tests for better coverage
286+ #[ test]
287+ fn test_format_worktree_display_verbose_with_commit ( ) {
288+ let test_commit_id = "abc123def" ;
289+ let test_path = "/tmp/feature" ;
290+ let worktree = WorktreeInfo {
291+ name : "feature" . to_string ( ) ,
292+ path : PathBuf :: from ( test_path) ,
293+ branch : "feature" . to_string ( ) ,
294+ is_current : false ,
295+ has_changes : false ,
296+ last_commit : Some ( crate :: infrastructure:: git:: CommitInfo {
297+ id : test_commit_id. to_string ( ) ,
298+ message : "Add feature" . to_string ( ) ,
299+ author : "test@example.com" . to_string ( ) ,
300+ time : "2023-01-01" . to_string ( ) ,
301+ } ) ,
302+ ahead_behind : None ,
303+ is_locked : false ,
304+ } ;
305+
306+ let display = format_worktree_display ( & worktree, true ) ;
307+ assert ! ( display. contains( & format!( "[{test_commit_id}]" ) ) ) ;
308+ assert ! ( display. contains( & format!( "- {test_path}" ) ) ) ;
309+ }
310+
311+ #[ test]
312+ fn test_format_worktree_display_verbose_with_ahead_behind ( ) {
313+ let ahead_count = 2 ;
314+ let behind_count = 3 ;
315+ let worktree = WorktreeInfo {
316+ name : "feature" . to_string ( ) ,
317+ path : PathBuf :: from ( "/tmp/feature" ) ,
318+ branch : "feature" . to_string ( ) ,
319+ is_current : false ,
320+ has_changes : false ,
321+ last_commit : None ,
322+ ahead_behind : Some ( ( ahead_count, behind_count) ) ,
323+ is_locked : false ,
324+ } ;
325+
326+ let display = format_worktree_display ( & worktree, true ) ;
327+ assert ! ( display. contains( & format!( "↑{ahead_count} ↓{behind_count}" ) ) ) ;
328+ }
329+
330+ #[ test]
331+ fn test_format_worktree_display_all_flags ( ) {
332+ let worktree_name = "complex" ;
333+ let worktree = WorktreeInfo {
334+ name : worktree_name. to_string ( ) ,
335+ path : PathBuf :: from ( "/tmp/complex" ) ,
336+ branch : "complex" . to_string ( ) ,
337+ is_current : true ,
338+ has_changes : true ,
339+ last_commit : None ,
340+ ahead_behind : None ,
341+ is_locked : true ,
342+ } ;
343+
344+ let display = format_worktree_display ( & worktree, false ) ;
345+ assert_eq ! (
346+ display,
347+ format!( "{worktree_name} (current) (locked) (changes)" )
348+ ) ;
349+ }
350+
351+ #[ test]
352+ fn test_should_show_worktree_empty_filter ( ) {
353+ let worktree = WorktreeInfo {
354+ name : "any" . to_string ( ) ,
355+ path : PathBuf :: from ( "/tmp/any" ) ,
356+ branch : "any" . to_string ( ) ,
357+ is_current : false ,
358+ has_changes : false ,
359+ last_commit : None ,
360+ ahead_behind : None ,
361+ is_locked : false ,
362+ } ;
363+
364+ // Empty string filter should match anything
365+ assert ! ( should_show_worktree( & worktree, false , Some ( "" ) ) ) ;
366+ }
367+
368+ #[ test]
369+ fn test_should_show_worktree_partial_filter ( ) {
370+ let test_filters = vec ! [ "auth" , "feature" , "login" ] ;
371+ let no_match_filter = "ui" ;
372+ let worktree = WorktreeInfo {
373+ name : "feature-auth-login" . to_string ( ) ,
374+ path : PathBuf :: from ( "/tmp/feature" ) ,
375+ branch : "feature" . to_string ( ) ,
376+ is_current : false ,
377+ has_changes : false ,
378+ last_commit : None ,
379+ ahead_behind : None ,
380+ is_locked : false ,
381+ } ;
382+
383+ // Partial matches should work
384+ for filter in test_filters {
385+ assert ! ( should_show_worktree( & worktree, false , Some ( filter) ) ) ;
386+ }
387+ assert ! ( !should_show_worktree(
388+ & worktree,
389+ false ,
390+ Some ( no_match_filter)
391+ ) ) ;
392+ }
330393}
0 commit comments