| 1 | # Line Editing Tests for fortsh |
| 2 | # Phase 2: Comprehensive cursor movement and text editing |
| 3 | |
| 4 | metadata: |
| 5 | category: "Line Editing" |
| 6 | description: "Comprehensive tests for cursor movement and text editing operations" |
| 7 | phase: 2 |
| 8 | |
| 9 | tests: |
| 10 | # ============================================================= |
| 11 | # BASIC INPUT |
| 12 | # ============================================================= |
| 13 | - name: "Simple echo command" |
| 14 | steps: |
| 15 | - send_line: "echo hello" |
| 16 | expect_output: "hello" |
| 17 | match_type: "contains" |
| 18 | |
| 19 | - name: "Echo with multiple arguments" |
| 20 | steps: |
| 21 | - send_line: "echo one two three" |
| 22 | expect_output: "one two three" |
| 23 | match_type: "contains" |
| 24 | |
| 25 | # Removed: Empty echo test causes timeout issues |
| 26 | |
| 27 | # ============================================================= |
| 28 | # CURSOR MOVEMENT - Arrow Keys |
| 29 | # ============================================================= |
| 30 | - name: "Left arrow moves cursor back" |
| 31 | steps: |
| 32 | - send: "echo test" |
| 33 | - send_key: "Left" |
| 34 | - send_key: "Left" |
| 35 | - send: "X" |
| 36 | - send_key: "Enter" |
| 37 | expect_output: "teXst" |
| 38 | match_type: "contains" |
| 39 | |
| 40 | - name: "Right arrow moves cursor forward" |
| 41 | steps: |
| 42 | - send: "echo test" |
| 43 | - send_key: "Left" |
| 44 | - send_key: "Left" |
| 45 | - send_key: "Left" |
| 46 | - send_key: "Right" |
| 47 | - send: "X" |
| 48 | - send_key: "Enter" |
| 49 | expect_output: "teXst" |
| 50 | match_type: "contains" |
| 51 | |
| 52 | - name: "Left arrow at beginning does nothing" |
| 53 | steps: |
| 54 | - send: "abcdef" |
| 55 | - send_key: "C-a" |
| 56 | - send_key: "Left" |
| 57 | - send_key: "Left" |
| 58 | - send: "X" |
| 59 | - send_key: "C-a" |
| 60 | - send: "echo " |
| 61 | - send_key: "Enter" |
| 62 | expect_output: "Xabcdef" |
| 63 | match_type: "contains" |
| 64 | |
| 65 | - name: "Right arrow at end does nothing" |
| 66 | steps: |
| 67 | - send: "abcdef" |
| 68 | - send_key: "Right" |
| 69 | - send_key: "Right" |
| 70 | - send: "X" |
| 71 | - send_key: "C-a" |
| 72 | - send: "echo " |
| 73 | - send_key: "Enter" |
| 74 | expect_output: "abcdefX" |
| 75 | match_type: "contains" |
| 76 | |
| 77 | # ============================================================= |
| 78 | # CURSOR MOVEMENT - Ctrl Keys |
| 79 | # ============================================================= |
| 80 | - name: "Ctrl+A moves to beginning of line" |
| 81 | steps: |
| 82 | - send: "hello world" |
| 83 | - send_key: "C-a" |
| 84 | - send: "echo " |
| 85 | - send_key: "Enter" |
| 86 | expect_output: "hello world" |
| 87 | match_type: "contains" |
| 88 | |
| 89 | - name: "Ctrl+E moves to end of line" |
| 90 | steps: |
| 91 | - send: "echo hel" |
| 92 | - send_key: "C-a" |
| 93 | - send_key: "C-e" |
| 94 | - send: "lo" |
| 95 | - send_key: "Enter" |
| 96 | expect_output: "hello" |
| 97 | match_type: "contains" |
| 98 | |
| 99 | - name: "Ctrl+B moves back one character" |
| 100 | steps: |
| 101 | - send: "echo test" |
| 102 | - send_key: "C-b" |
| 103 | - send_key: "C-b" |
| 104 | - send: "X" |
| 105 | - send_key: "Enter" |
| 106 | expect_output: "teXst" |
| 107 | match_type: "contains" |
| 108 | |
| 109 | # NOTE: Ctrl+F is bound to FZF file browser in fortsh, not forward-char |
| 110 | # Use Right arrow for forward character movement instead |
| 111 | - name: "Right arrow moves forward one character" |
| 112 | steps: |
| 113 | - send: "abcdef" |
| 114 | - send_key: "C-a" |
| 115 | - send_key: "Right" |
| 116 | - send_key: "Right" |
| 117 | - send: "X" |
| 118 | - send_key: "C-a" |
| 119 | - send: "echo " |
| 120 | - send_key: "Enter" |
| 121 | - wait: 0.3 |
| 122 | expect_output: "abXcdef" |
| 123 | match_type: "contains" |
| 124 | |
| 125 | - name: "Multiple Ctrl+B navigation" |
| 126 | steps: |
| 127 | - send: "abcdef" |
| 128 | - send_key: "C-b" |
| 129 | - send_key: "C-b" |
| 130 | - send_key: "C-b" |
| 131 | - send: "X" |
| 132 | - send_key: "C-a" |
| 133 | - send: "echo " |
| 134 | - send_key: "Enter" |
| 135 | expect_output: "abcXdef" |
| 136 | match_type: "contains" |
| 137 | |
| 138 | # ============================================================= |
| 139 | # CURSOR MOVEMENT - Home/End Keys |
| 140 | # ============================================================= |
| 141 | # NOTE: The Home key (ESC[H) is not explicitly handled in fortsh |
| 142 | # Ctrl+A already works for moving to beginning of line |
| 143 | - name: "Ctrl+A moves to beginning (Home alternative)" |
| 144 | steps: |
| 145 | - send: "abcdef" |
| 146 | - send_key: "C-a" |
| 147 | - send: "X" |
| 148 | - send_key: "C-a" |
| 149 | - send: "echo " |
| 150 | - send_key: "Enter" |
| 151 | - wait: 0.3 |
| 152 | expect_output: "Xabcdef" |
| 153 | match_type: "contains" |
| 154 | |
| 155 | - name: "End key moves to end" |
| 156 | steps: |
| 157 | - send: "abcdef" |
| 158 | - send_key: "Home" |
| 159 | - send_key: "End" |
| 160 | - send: "X" |
| 161 | - send_key: "C-a" |
| 162 | - send: "echo " |
| 163 | - send_key: "Enter" |
| 164 | expect_output: "abcdefX" |
| 165 | match_type: "contains" |
| 166 | |
| 167 | # ============================================================= |
| 168 | # CURSOR MOVEMENT - Word Movement |
| 169 | # ============================================================= |
| 170 | - name: "Alt+B moves back one word" |
| 171 | steps: |
| 172 | - send: "echo one two three" |
| 173 | - send_key: "M-b" |
| 174 | - send_key: "M-b" |
| 175 | - send: "X" |
| 176 | - send_key: "Enter" |
| 177 | expect_output: "one Xtwo three" |
| 178 | match_type: "contains" |
| 179 | |
| 180 | - name: "Alt+B from middle of word" |
| 181 | steps: |
| 182 | - send: "testing" |
| 183 | - send_key: "C-b" |
| 184 | - send_key: "C-b" |
| 185 | - send_key: "M-b" |
| 186 | - send: "X" |
| 187 | - send_key: "C-a" |
| 188 | - send: "echo " |
| 189 | - send_key: "Enter" |
| 190 | expect_output: "Xtesting" |
| 191 | match_type: "contains" |
| 192 | |
| 193 | # Alt+F moves to end of current word (bash/readline behavior) |
| 194 | - name: "Alt+F moves forward one word" |
| 195 | steps: |
| 196 | - send: "one two" |
| 197 | - send_key: "C-a" |
| 198 | - send_key: "M-f" |
| 199 | - send: "X" |
| 200 | - send_key: "C-a" |
| 201 | - send: "echo " |
| 202 | - send_key: "Enter" |
| 203 | - wait: 0.3 |
| 204 | expect_output: "oneX two" |
| 205 | match_type: "contains" |
| 206 | |
| 207 | # Three Alt+B from end of "a b c d" moves: d->c->b->a (to beginning) |
| 208 | - name: "Multiple Alt+B movements" |
| 209 | steps: |
| 210 | - send: "a b c d" |
| 211 | - send_key: "M-b" |
| 212 | - send_key: "M-b" |
| 213 | - send_key: "M-b" |
| 214 | - send: "X" |
| 215 | - send_key: "C-a" |
| 216 | - send: "echo " |
| 217 | - send_key: "Enter" |
| 218 | - wait: 0.3 |
| 219 | expect_output: "Xa b c d" |
| 220 | match_type: "contains" |
| 221 | |
| 222 | # ============================================================= |
| 223 | # TEXT DELETION - Backspace |
| 224 | # ============================================================= |
| 225 | - name: "Backspace deletes character before cursor" |
| 226 | steps: |
| 227 | - send: "echoo" |
| 228 | - send_key: "Backspace" |
| 229 | - send: " test" |
| 230 | - send_key: "Enter" |
| 231 | expect_output: "test" |
| 232 | match_type: "contains" |
| 233 | |
| 234 | - name: "Multiple backspaces" |
| 235 | steps: |
| 236 | - send: "echo helloXXX" |
| 237 | - send_key: "Backspace" |
| 238 | - send_key: "Backspace" |
| 239 | - send_key: "Backspace" |
| 240 | - send_key: "Enter" |
| 241 | expect_output: "hello" |
| 242 | match_type: "contains" |
| 243 | |
| 244 | - name: "Backspace at beginning does nothing" |
| 245 | steps: |
| 246 | - send: "abcdef" |
| 247 | - send_key: "C-a" |
| 248 | - send_key: "Backspace" |
| 249 | - send_key: "Backspace" |
| 250 | - send_key: "C-a" |
| 251 | - send: "echo " |
| 252 | - send_key: "Enter" |
| 253 | expect_output: "abcdef" |
| 254 | match_type: "contains" |
| 255 | |
| 256 | # ============================================================= |
| 257 | # TEXT DELETION - Delete Key |
| 258 | # ============================================================= |
| 259 | - name: "Delete key removes character under cursor" |
| 260 | steps: |
| 261 | - send: "Xabcdef" |
| 262 | - send_key: "C-a" |
| 263 | - send_key: "Delete" |
| 264 | - send_key: "C-a" |
| 265 | - send: "echo " |
| 266 | - send_key: "Enter" |
| 267 | expect_output: "abcdef" |
| 268 | match_type: "contains" |
| 269 | |
| 270 | - name: "Multiple deletes" |
| 271 | steps: |
| 272 | - send: "XXXabcdef" |
| 273 | - send_key: "C-a" |
| 274 | - send_key: "Delete" |
| 275 | - send_key: "Delete" |
| 276 | - send_key: "Delete" |
| 277 | - send_key: "C-a" |
| 278 | - send: "echo " |
| 279 | - send_key: "Enter" |
| 280 | expect_output: "abcdef" |
| 281 | match_type: "contains" |
| 282 | |
| 283 | - name: "Delete at end does nothing" |
| 284 | steps: |
| 285 | - send: "abcdef" |
| 286 | - send_key: "Delete" |
| 287 | - send_key: "Delete" |
| 288 | - send_key: "C-a" |
| 289 | - send: "echo " |
| 290 | - send_key: "Enter" |
| 291 | expect_output: "abcdef" |
| 292 | match_type: "contains" |
| 293 | |
| 294 | # ============================================================= |
| 295 | # TEXT DELETION - Ctrl+D |
| 296 | # ============================================================= |
| 297 | - name: "Ctrl+D deletes character under cursor" |
| 298 | steps: |
| 299 | - send: "Xabcdef" |
| 300 | - send_key: "C-a" |
| 301 | - send_key: "C-d" |
| 302 | - send_key: "C-a" |
| 303 | - send: "echo " |
| 304 | - send_key: "Enter" |
| 305 | expect_output: "abcdef" |
| 306 | match_type: "contains" |
| 307 | |
| 308 | # NOTE: Ctrl+D in fortsh only triggers EOF on empty line (doesn't forward-delete) |
| 309 | # Simpler test for delete in middle - use fresh_session for reliability |
| 310 | - name: "Delete in middle of line" |
| 311 | fresh_session: true |
| 312 | steps: |
| 313 | - send: "Xab" |
| 314 | - send_key: "C-a" |
| 315 | - send_key: "Delete" |
| 316 | - send_key: "C-a" |
| 317 | - send: "echo " |
| 318 | - send_key: "Enter" |
| 319 | - wait: 0.5 |
| 320 | expect_output: "ab" |
| 321 | match_type: "contains" |
| 322 | |
| 323 | # ============================================================= |
| 324 | # TEXT DELETION - Kill Commands |
| 325 | # ============================================================= |
| 326 | - name: "Ctrl+K kills to end of line" |
| 327 | steps: |
| 328 | - send: "echo test garbage" |
| 329 | - send_key: "C-a" |
| 330 | - send_keys: ["Right", "Right", "Right", "Right", "Right", "Right", "Right", "Right", "Right"] |
| 331 | - send_key: "C-k" |
| 332 | - send_key: "Enter" |
| 333 | expect_output: "test" |
| 334 | match_type: "contains" |
| 335 | |
| 336 | - name: "Ctrl+K at end of line kills nothing" |
| 337 | steps: |
| 338 | - send: "abcdef" |
| 339 | - send_key: "C-k" |
| 340 | - send_key: "C-a" |
| 341 | - send: "echo " |
| 342 | - send_key: "Enter" |
| 343 | expect_output: "abcdef" |
| 344 | match_type: "contains" |
| 345 | |
| 346 | - name: "Ctrl+U kills line before cursor" |
| 347 | steps: |
| 348 | - send: "garbage echo test" |
| 349 | - send_key: "C-a" |
| 350 | - send_keys: ["Right", "Right", "Right", "Right", "Right", "Right", "Right", "Right"] |
| 351 | - send_key: "C-u" |
| 352 | - send_key: "Enter" |
| 353 | expect_output: "test" |
| 354 | match_type: "contains" |
| 355 | |
| 356 | - name: "Ctrl+U at beginning kills nothing" |
| 357 | steps: |
| 358 | - send: "abcdef" |
| 359 | - send_key: "C-a" |
| 360 | - send_key: "C-u" |
| 361 | - send_key: "C-a" |
| 362 | - send: "echo " |
| 363 | - send_key: "Enter" |
| 364 | expect_output: "abcdef" |
| 365 | match_type: "contains" |
| 366 | |
| 367 | - name: "Ctrl+W kills word backward" |
| 368 | steps: |
| 369 | - send: "echo one two three" |
| 370 | - send_key: "C-w" |
| 371 | - send_key: "Enter" |
| 372 | expect_output: "one two" |
| 373 | match_type: "contains" |
| 374 | |
| 375 | - name: "Multiple Ctrl+W kills multiple words" |
| 376 | steps: |
| 377 | - send: "echo one two three" |
| 378 | - send_key: "C-w" |
| 379 | - send_key: "C-w" |
| 380 | - send_key: "Enter" |
| 381 | expect_output: "one" |
| 382 | match_type: "contains" |
| 383 | |
| 384 | - name: "Ctrl+W from middle of word" |
| 385 | steps: |
| 386 | - send: "testing" |
| 387 | - send_key: "C-b" |
| 388 | - send_key: "C-b" |
| 389 | - send_key: "C-w" |
| 390 | - send_key: "C-a" |
| 391 | - send: "echo " |
| 392 | - send_key: "Enter" |
| 393 | expect_output: "ing" |
| 394 | match_type: "contains" |
| 395 | |
| 396 | # ============================================================= |
| 397 | # KILL RING - Yank |
| 398 | # ============================================================= |
| 399 | - name: "Ctrl+Y yanks killed text" |
| 400 | steps: |
| 401 | - send: "echo one two three" |
| 402 | - send_key: "C-w" |
| 403 | - send_key: "C-y" |
| 404 | - send_key: "Enter" |
| 405 | expect_output: "one two three" |
| 406 | match_type: "contains" |
| 407 | |
| 408 | - name: "Ctrl+K then Ctrl+Y" |
| 409 | steps: |
| 410 | - send: "hello world" |
| 411 | - send_key: "C-a" |
| 412 | - send_key: "C-k" |
| 413 | - send: "echo " |
| 414 | - send_key: "C-y" |
| 415 | - send_key: "Enter" |
| 416 | expect_output: "hello world" |
| 417 | match_type: "contains" |
| 418 | |
| 419 | # Simpler Ctrl+U then Ctrl+Y test |
| 420 | - name: "Ctrl+U then Ctrl+Y" |
| 421 | fresh_session: true |
| 422 | steps: |
| 423 | - send: "hello world" |
| 424 | - send_key: "C-u" |
| 425 | - send_key: "C-y" |
| 426 | - send_key: "C-a" |
| 427 | - send: "echo " |
| 428 | - send_key: "Enter" |
| 429 | - wait: 0.5 |
| 430 | expect_output: "hello world" |
| 431 | match_type: "contains" |
| 432 | |
| 433 | # ============================================================= |
| 434 | # TRANSPOSE - Ctrl+T |
| 435 | # ============================================================= |
| 436 | # Ctrl+T transposes char before cursor with char at cursor |
| 437 | # With cursor at position 1 (on 'a'), swaps 'b' and 'a' -> "abcd" |
| 438 | - name: "Ctrl+T transposes characters" |
| 439 | steps: |
| 440 | - send: "bacd" |
| 441 | - send_key: "C-a" |
| 442 | - send_key: "Right" |
| 443 | - send_key: "C-t" |
| 444 | - send_key: "C-a" |
| 445 | - send: "echo " |
| 446 | - send_key: "Enter" |
| 447 | - wait: 0.3 |
| 448 | expect_output: "abcd" |
| 449 | match_type: "contains" |
| 450 | |
| 451 | - name: "Ctrl+T at end transposes last two" |
| 452 | steps: |
| 453 | - send: "abdc" |
| 454 | - send_key: "C-t" |
| 455 | - send_key: "C-a" |
| 456 | - send: "echo " |
| 457 | - send_key: "Enter" |
| 458 | expect_output: "abcd" |
| 459 | match_type: "contains" |
| 460 | |
| 461 | # ============================================================= |
| 462 | # SPECIAL CHARACTERS |
| 463 | # ============================================================= |
| 464 | - name: "Quotes preserve spaces" |
| 465 | steps: |
| 466 | - send_line: "echo 'hello world'" |
| 467 | expect_output: "hello world" |
| 468 | match_type: "contains" |
| 469 | |
| 470 | - name: "Double quotes preserve spaces" |
| 471 | steps: |
| 472 | - send_line: 'echo "hello world"' |
| 473 | expect_output: "hello world" |
| 474 | match_type: "contains" |
| 475 | |
| 476 | - name: "Escaped characters" |
| 477 | steps: |
| 478 | - send_line: "echo hello\\ world" |
| 479 | expect_output: "hello world" |
| 480 | match_type: "contains" |
| 481 | |
| 482 | - name: "Tab character in quotes" |
| 483 | steps: |
| 484 | - send_line: "echo -e 'a\\tb'" |
| 485 | expect_output: "a\tb" |
| 486 | match_type: "contains" |
| 487 | |
| 488 | # ============================================================= |
| 489 | # UTF-8 MULTI-BYTE CHARACTERS |
| 490 | # ============================================================= |
| 491 | - name: "UTF-8 basic output" |
| 492 | steps: |
| 493 | - send_line: "echo 'Hello 世界'" |
| 494 | expect_output: "Hello 世界" |
| 495 | match_type: "contains" |
| 496 | |
| 497 | - name: "UTF-8 emoji output" |
| 498 | steps: |
| 499 | - send_line: "echo '🚀 rocket'" |
| 500 | expect_output: "🚀 rocket" |
| 501 | match_type: "contains" |
| 502 | |
| 503 | - name: "UTF-8 mixed content" |
| 504 | steps: |
| 505 | - send_line: "echo 'café résumé'" |
| 506 | expect_output: "café résumé" |
| 507 | match_type: "contains" |
| 508 | |
| 509 | - name: "Backspace over UTF-8 character" |
| 510 | steps: |
| 511 | - send: "echo 日本X" |
| 512 | - send_key: "Backspace" |
| 513 | - send_key: "Enter" |
| 514 | expect_output: "日本" |
| 515 | match_type: "contains" |
| 516 | |
| 517 | - name: "Cursor movement with CJK characters" |
| 518 | steps: |
| 519 | - send: "echo 中文" |
| 520 | - send_key: "C-b" |
| 521 | - send: "X" |
| 522 | - send_key: "Enter" |
| 523 | expect_output: "中X文" |
| 524 | match_type: "contains" |
| 525 | |
| 526 | - name: "Delete UTF-8 character" |
| 527 | steps: |
| 528 | - send: "日本国" |
| 529 | - send_key: "C-a" |
| 530 | - send_key: "C-d" |
| 531 | - send_key: "C-a" |
| 532 | - send: "echo " |
| 533 | - send_key: "Enter" |
| 534 | expect_output: "本国" |
| 535 | match_type: "contains" |
| 536 | |
| 537 | # ============================================================= |
| 538 | # EDGE CASES |
| 539 | # ============================================================= |
| 540 | - name: "Very long line input" |
| 541 | steps: |
| 542 | - send_line: "echo aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" |
| 543 | expect_output: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" |
| 544 | match_type: "contains" |
| 545 | |
| 546 | - name: "Line with only spaces" |
| 547 | steps: |
| 548 | - send_line: "echo ' '" |
| 549 | expect_output: " " |
| 550 | match_type: "contains" |
| 551 |