@@ -66,7 +66,7 @@ func TestHookCommand_GeneratesValidShellScripts(t *testing.T) {
6666 "function wtp" ,
6767 "if test \" $argv[1]\" = \" cd\" " ,
6868 "command wtp cd" ,
69- "cd $target_dir" ,
69+ "cd \" $target_dir\" " ,
7070 },
7171 },
7272 }
@@ -106,23 +106,46 @@ func TestHookScripts_HandleEdgeCases(t *testing.T) {
106106 name string
107107 shell string
108108 requiredLogic []string
109+ notContains []string
109110 }{
110111 {
111- name : "bash hook handles empty argument " ,
112+ name : "bash hook supports no-arg cd " ,
112113 shell : "bash" ,
113114 requiredLogic : []string {
114- "if [[ -z \" $2\" ]]" , // Empty argument check
115- "echo \" Usage:" , // Error message
116- "return 1" , // Error exit
115+ "if [[ -z \" $2\" ]]" , // No-arg branch
116+ "target_dir=$(command wtp cd" , // Uses `wtp cd` default behavior
117+ "target_dir=$(command wtp cd \" $2" , // Uses explicit worktree name when present
118+ },
119+ notContains : []string {
120+ "Usage: wtp cd <worktree>" ,
121+ "echo \" Usage:" ,
122+ },
123+ },
124+ {
125+ name : "zsh hook supports no-arg cd" ,
126+ shell : "zsh" ,
127+ requiredLogic : []string {
128+ "if [[ -z \" $2\" ]]" , // No-arg branch
129+ "target_dir=$(command wtp cd" , // Uses `wtp cd` default behavior
130+ "target_dir=$(command wtp cd \" $2" , // Uses explicit worktree name when present
131+ },
132+ notContains : []string {
133+ "Usage: wtp cd <worktree>" ,
134+ "echo \" Usage:" ,
117135 },
118136 },
119137 {
120- name : "fish hook handles empty argument " ,
138+ name : "fish hook supports no-arg cd " ,
121139 shell : "fish" ,
122140 requiredLogic : []string {
123- "if test -z \" $argv[2]\" " , // Empty argument check
124- "echo \" Usage:" , // Error message
125- "return 1" , // Error exit
141+ "if test -z \" $argv[2]\" " , // No-arg branch
142+ "set -l target_dir (command wtp cd" , // Uses `wtp cd` default behavior
143+ "command wtp cd $argv[2]" , // Uses explicit worktree name when present
144+ "cd \" $target_dir\" " , // Handles spaces safely
145+ },
146+ notContains : []string {
147+ "Usage: wtp cd <worktree>" ,
148+ "echo \" Usage:" ,
126149 },
127150 },
128151 }
@@ -134,6 +157,8 @@ func TestHookScripts_HandleEdgeCases(t *testing.T) {
134157 switch tt .shell {
135158 case "bash" :
136159 require .NoError (t , printBashHook (& buf ))
160+ case "zsh" :
161+ require .NoError (t , printZshHook (& buf ))
137162 case "fish" :
138163 require .NoError (t , printFishHook (& buf ))
139164 }
@@ -142,6 +167,9 @@ func TestHookScripts_HandleEdgeCases(t *testing.T) {
142167 for _ , logic := range tt .requiredLogic {
143168 assert .Contains (t , output , logic , "Hook must handle edge cases properly" )
144169 }
170+ for _ , unexpected := range tt .notContains {
171+ assert .NotContains (t , output , unexpected )
172+ }
145173 })
146174 }
147175}
0 commit comments