testDirectoryHandlingWithQuotes tests handling directories with spaces and quotes
(t *testing.T, curTestDir, dir1 string)
| 252 | |
| 253 | // testDirectoryHandlingWithQuotes tests handling directories with spaces and quotes |
| 254 | func testDirectoryHandlingWithQuotes(t *testing.T, curTestDir, dir1 string) { |
| 255 | t.Run("Directory names with spaces and quotes", func(t *testing.T) { |
| 256 | // Create test directories with spaces and special characters |
| 257 | dirWithSpaces := filepath.Join(curTestDir, "dir with spaces") |
| 258 | dirWithQuotes := filepath.Join(curTestDir, "dir'with'quotes") |
| 259 | |
| 260 | // Windows doesn't allow double quotes in directory names |
| 261 | var dirWithSpecialChars, dirWithMixed string |
| 262 | var directoriesToCreate []string |
| 263 | |
| 264 | if runtime.GOOS == "windows" { |
| 265 | // On Windows, use alternative characters that don't conflict with filesystem restrictions |
| 266 | dirWithSpecialChars = filepath.Join(curTestDir, `dir[with]quotes`) |
| 267 | dirWithMixed = filepath.Join(curTestDir, `dir with 'mixed' [quotes]`) |
| 268 | directoriesToCreate = []string{dirWithSpaces, dirWithQuotes, dirWithSpecialChars, dirWithMixed} |
| 269 | } else { |
| 270 | // On Unix-like systems, double quotes are allowed in directory names |
| 271 | dirWithSpecialChars = filepath.Join(curTestDir, `dir"with"quotes`) |
| 272 | dirWithMixed = filepath.Join(curTestDir, `dir with 'mixed' "quotes"`) |
| 273 | directoriesToCreate = []string{dirWithSpaces, dirWithQuotes, dirWithSpecialChars, dirWithMixed} |
| 274 | } |
| 275 | |
| 276 | utils.SetupDirectories(t, directoriesToCreate...) |
| 277 | |
| 278 | t.Run("cd with double quotes", func(t *testing.T) { |
| 279 | m := defaultTestModel(dir1) |
| 280 | TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.OpenSPFPrompt[0])) |
| 281 | |
| 282 | TeaUpdate(m, utils.TeaRuneKeyMsg(prompt.CdCommand+` "`+dirWithSpaces+`"`)) |
| 283 | TeaUpdate(m, tea.KeyPressMsg{Code: tea.KeyEnter}) |
| 284 | assert.True(t, m.promptModal.LastActionSucceeded(), "cd with double quotes should work") |
| 285 | assert.Equal(t, dirWithSpaces, m.getFocusedFilePanel().Location) |
| 286 | }) |
| 287 | |
| 288 | t.Run("cd with single quotes", func(t *testing.T) { |
| 289 | m := defaultTestModel(dir1) |
| 290 | TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.OpenSPFPrompt[0])) |
| 291 | |
| 292 | TeaUpdate(m, utils.TeaRuneKeyMsg(prompt.CdCommand+` '`+dirWithSpaces+`'`)) |
| 293 | TeaUpdate(m, tea.KeyPressMsg{Code: tea.KeyEnter}) |
| 294 | assert.True(t, m.promptModal.LastActionSucceeded(), "cd with single quotes should work") |
| 295 | assert.Equal(t, dirWithSpaces, m.getFocusedFilePanel().Location) |
| 296 | }) |
| 297 | |
| 298 | t.Run("cd with single quotes in path using double quotes", func(t *testing.T) { |
| 299 | m := defaultTestModel(dir1) |
| 300 | TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.OpenSPFPrompt[0])) |
| 301 | |
| 302 | TeaUpdate(m, utils.TeaRuneKeyMsg(prompt.CdCommand+` "`+dirWithQuotes+`"`)) |
| 303 | TeaUpdate(m, tea.KeyPressMsg{Code: tea.KeyEnter}) |
| 304 | assert.True(t, m.promptModal.LastActionSucceeded(), "cd with single quotes in path should work") |
| 305 | assert.Equal(t, dirWithQuotes, m.getFocusedFilePanel().Location) |
| 306 | }) |
| 307 | |
| 308 | t.Run("cd with double quotes in path using single quotes", func(t *testing.T) { |
| 309 | m := defaultTestModel(dir1) |
| 310 | TeaUpdate(m, utils.TeaRuneKeyMsg(common.Hotkeys.OpenSPFPrompt[0])) |
| 311 |
no test coverage detected