diff options
| author | Filipp Gunbin | 2022-05-03 12:35:34 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-05-03 12:35:34 +0200 |
| commit | 0b626ff8d6a29c452bc8bbbee79f5eff11d02548 (patch) | |
| tree | 93e617a9bfae56b0ec6b57a3884132c2eefb5590 /test | |
| parent | 0e8fc556b669cbb4794b76b8197519f808083dac (diff) | |
| download | emacs-0b626ff8d6a29c452bc8bbbee79f5eff11d02548.tar.gz emacs-0b626ff8d6a29c452bc8bbbee79f5eff11d02548.zip | |
Rewrite sql-interactive-remove-continuation-prompt
* lisp/progmodes/sql.el (sql-starts-with-prompt-re): Remove.
(sql-ends-with-prompt-re): Remove
(sql-interactive-remove-continuation-prompt): Delete prompts from
anywhere in the process output, not just at the beginning of current
string. Streamline logic, describe it in docstring.
* test/lisp/progmodes/sql-tests.el: Add tests
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/progmodes/sql-tests.el | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/test/lisp/progmodes/sql-tests.el b/test/lisp/progmodes/sql-tests.el index 7e36d845e2c..c644d115df6 100644 --- a/test/lisp/progmodes/sql-tests.el +++ b/test/lisp/progmodes/sql-tests.el | |||
| @@ -425,5 +425,85 @@ The ACTION will be tested after set-up of PRODUCT." | |||
| 425 | (let ((sql-password "password")) | 425 | (let ((sql-password "password")) |
| 426 | (should (equal "password" (sql-comint-automatic-password ""))))) | 426 | (should (equal "password" (sql-comint-automatic-password ""))))) |
| 427 | 427 | ||
| 428 | |||
| 429 | |||
| 430 | ;; Tests for sql-interactive-remove-continuation-prompt | ||
| 431 | |||
| 432 | (defmacro sql-tests-remove-cont-prompts-harness (&rest body) | ||
| 433 | "Set-up and tear-down for tests of | ||
| 434 | `sql-interactive-remove-continuation-prompt'." | ||
| 435 | (declare (indent 0)) | ||
| 436 | `(let ((comint-prompt-regexp "^ +\\.\\{3\\} ") | ||
| 437 | (sql-output-newline-count nil) | ||
| 438 | (sql-preoutput-hold nil)) | ||
| 439 | ,@body | ||
| 440 | (should (null sql-output-newline-count)) | ||
| 441 | (should (null sql-preoutput-hold)))) | ||
| 442 | |||
| 443 | (ert-deftest sql-tests-remove-cont-prompts-pass-through () | ||
| 444 | "Test that `sql-interactive-remove-continuation-prompt' just | ||
| 445 | passes the output line through when it doesn't expect prompts." | ||
| 446 | (sql-tests-remove-cont-prompts-harness | ||
| 447 | (should | ||
| 448 | (equal " ... " | ||
| 449 | (sql-interactive-remove-continuation-prompt | ||
| 450 | " ... "))))) | ||
| 451 | |||
| 452 | (ert-deftest sql-tests-remove-cont-prompts-anchored-successive () | ||
| 453 | "Test that `sql-interactive-remove-continuation-prompt' is able | ||
| 454 | to delete multiple prompts (anchored to bol) even if they appear | ||
| 455 | in a single line, but not more than `sql-output-newline-count'." | ||
| 456 | (sql-tests-remove-cont-prompts-harness | ||
| 457 | (setq sql-output-newline-count 2) | ||
| 458 | (should | ||
| 459 | (equal | ||
| 460 | ;; 2 of 3 prompts are deleted | ||
| 461 | "some output ... more output...\n\ | ||
| 462 | ... \n\ | ||
| 463 | output after prompt" | ||
| 464 | (sql-interactive-remove-continuation-prompt | ||
| 465 | "some output ... more output...\n\ | ||
| 466 | ... ... ... \n\ | ||
| 467 | output after prompt"))))) | ||
| 468 | |||
| 469 | (ert-deftest sql-tests-remove-cont-prompts-collect-chunked-output () | ||
| 470 | "Test that `sql-interactive-remove-continuation-prompt' properly | ||
| 471 | collects output when output arrives in chunks, with prompts | ||
| 472 | intermixed." | ||
| 473 | (sql-tests-remove-cont-prompts-harness | ||
| 474 | (setq sql-output-newline-count 2) | ||
| 475 | |||
| 476 | ;; Part of first prompt gets held. Complete line is passed | ||
| 477 | ;; through. | ||
| 478 | (should (equal "line1\n" | ||
| 479 | (sql-interactive-remove-continuation-prompt | ||
| 480 | "line1\n .."))) | ||
| 481 | (should (equal " .." sql-preoutput-hold)) | ||
| 482 | (should (equal 2 sql-output-newline-count)) | ||
| 483 | |||
| 484 | ;; First prompt is complete - remove it. Hold part of line2. | ||
| 485 | (should (equal "" | ||
| 486 | (sql-interactive-remove-continuation-prompt ". li"))) | ||
| 487 | (should (equal "li" sql-preoutput-hold)) | ||
| 488 | (should (equal 1 sql-output-newline-count)) | ||
| 489 | |||
| 490 | ;; Remove second prompt. Flush output & don't hold / process any | ||
| 491 | ;; output further on. | ||
| 492 | (should (equal "line2\nli" | ||
| 493 | (sql-interactive-remove-continuation-prompt "ne2\n ... li"))) | ||
| 494 | (should (null sql-preoutput-hold)) | ||
| 495 | (should (null sql-output-newline-count)) | ||
| 496 | (should (equal "line3\n ... " | ||
| 497 | (sql-interactive-remove-continuation-prompt "line3\n ... "))))) | ||
| 498 | |||
| 499 | (ert-deftest sql-tests-remove-cont-prompts-flush-held () | ||
| 500 | "Test that when we don't wait for prompts, | ||
| 501 | `sql-interactive-remove-continuation-prompt' just 'flushes' held | ||
| 502 | output, with no prompt processing." | ||
| 503 | (sql-tests-remove-cont-prompts-harness | ||
| 504 | (setq sql-preoutput-hold "line1\n ..") | ||
| 505 | (should (equal "line1\n ... line2 .." | ||
| 506 | (sql-interactive-remove-continuation-prompt ". line2 .."))))) | ||
| 507 | |||
| 428 | (provide 'sql-tests) | 508 | (provide 'sql-tests) |
| 429 | ;;; sql-tests.el ends here | 509 | ;;; sql-tests.el ends here |