diff options
| author | F. Jason Park | 2023-04-30 07:12:56 -0700 |
|---|---|---|
| committer | F. Jason Park | 2023-05-05 17:18:01 -0700 |
| commit | 35dd1ade7f1e583f736e6f707343402fe868daec (patch) | |
| tree | bc1a0022b297fd89c0acea30172e95ed5a9f0f98 /test | |
| parent | 3a5a6fce957468be5ef0a8ac76fec8507c3e4e99 (diff) | |
| download | emacs-35dd1ade7f1e583f736e6f707343402fe868daec.tar.gz emacs-35dd1ade7f1e583f736e6f707343402fe868daec.zip | |
Preprocess prompt input linewise in ERC
* etc/ERC-NEWS: Mention revised role of `erc-pre-send-functions'
relative to line splitting.
* lisp/erc/erc-common.el (erc-input): Add new slot `refoldp' to allow
`erc-pre-send-functions' members to indicate that splitting should
occur a second time after all members have had their say.
(erc--input-split): Specify some defaults for overridden slots and
explicitly declare some types for good measure.
* lisp/erc/erc-goodies.el (erc-noncommands-mode,
erc-noncommands-enable, erc-noncommands-disable): Replace
`erc-pre-send-functions' with `erc--input-review-functions'.
* lisp/erc/erc-ring.el (erc-ring-enable, erc-ring-disable,
erc-ring-mode): Subscribe to `erc--input-review-functions' instead of
`erc-pre-send-functions' for `erc--add-to-input-ring'.
* lisp/erc/erc.el (erc-pre-send-functions): Note some nuances
regarding line splitting in doc string and note that a new slot is
available.
(erc--pre-send-split-functions, erc--input-review-functions): Rename
former to latter, while also obsoleting. Remove large comment. Add
new default member `erc--run-input-validation-checks'.
(erc-send-modify-hook): Replace the obsolete `erc-send-pre-hook' and
`erc-send-this' with `erc-pre-send-functions' in doc string.
(erc--check-prompt-input-for-excess-lines): Don't trim trailing
blanks. Rework to also report overages in characters as well as
lines.
(erc--run-input-validation-hooks): New function to adapt an
`erc--input-split' object to `erc--check-prompt-input-functions'.
(erc-send-current-line): Run `erc--input-review-functions' in place of
the validation hooks they've subsumed. Call `erc--send-input-lines'
instead of the now retired but not deprecated `erc-send-input'.
(erc--run-send-hooks, erc--send-input-lines): New functions that
together form an alternate version of `erc-send-input'. They operate
on input linewise but make accommodations for older interfaces.
* test/lisp/erc/erc-tests.el (erc-ring-previous-command): Replace
`erc-pre-send-functions' with `erc--input-review-functions'.
(erc-tests--with-process-input-spy): Shadow
`erc--input-review-functions'.
(erc-check-prompt-input-for-excess-lines): Don't expect trailing
blanks to be trimmed.
(erc--run-send-hooks): New test. (Bug#62947)
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/erc/erc-tests.el | 101 |
1 files changed, 96 insertions, 5 deletions
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index b6702617aeb..be5a566a268 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el | |||
| @@ -942,8 +942,8 @@ | |||
| 942 | (should-not (local-variable-if-set-p 'erc-send-completed-hook)) | 942 | (should-not (local-variable-if-set-p 'erc-send-completed-hook)) |
| 943 | (set (make-local-variable 'erc-send-completed-hook) nil) ; skip t (globals) | 943 | (set (make-local-variable 'erc-send-completed-hook) nil) ; skip t (globals) |
| 944 | ;; Just in case erc-ring-mode is already on | 944 | ;; Just in case erc-ring-mode is already on |
| 945 | (setq-local erc-pre-send-functions nil) | 945 | (setq-local erc--input-review-functions nil) |
| 946 | (add-hook 'erc-pre-send-functions #'erc-add-to-input-ring) | 946 | (add-hook 'erc--input-review-functions #'erc-add-to-input-ring) |
| 947 | ;; | 947 | ;; |
| 948 | (cl-letf (((symbol-function 'erc-process-input-line) | 948 | (cl-letf (((symbol-function 'erc-process-input-line) |
| 949 | (lambda (&rest _) | 949 | (lambda (&rest _) |
| @@ -1156,7 +1156,9 @@ | |||
| 1156 | 1156 | ||
| 1157 | (defun erc-tests--with-process-input-spy (test) | 1157 | (defun erc-tests--with-process-input-spy (test) |
| 1158 | (with-current-buffer (get-buffer-create "FakeNet") | 1158 | (with-current-buffer (get-buffer-create "FakeNet") |
| 1159 | (let* ((erc-pre-send-functions | 1159 | (let* ((erc--input-review-functions |
| 1160 | (remove #'erc-add-to-input-ring erc--input-review-functions)) | ||
| 1161 | (erc-pre-send-functions | ||
| 1160 | (remove #'erc-add-to-input-ring erc-pre-send-functions)) ; for now | 1162 | (remove #'erc-add-to-input-ring erc-pre-send-functions)) ; for now |
| 1161 | (inhibit-message noninteractive) | 1163 | (inhibit-message noninteractive) |
| 1162 | (erc-server-current-nick "tester") | 1164 | (erc-server-current-nick "tester") |
| @@ -1314,13 +1316,14 @@ | |||
| 1314 | (ert-info ("With `erc-inhibit-multiline-input' as t (2)") | 1316 | (ert-info ("With `erc-inhibit-multiline-input' as t (2)") |
| 1315 | (let ((erc-inhibit-multiline-input t)) | 1317 | (let ((erc-inhibit-multiline-input t)) |
| 1316 | (should-not (erc--check-prompt-input-for-excess-lines "" '("a"))) | 1318 | (should-not (erc--check-prompt-input-for-excess-lines "" '("a"))) |
| 1317 | (should-not (erc--check-prompt-input-for-excess-lines "" '("a" ""))) | 1319 | ;; Does not trim trailing blanks. |
| 1320 | (should (erc--check-prompt-input-for-excess-lines "" '("a" ""))) | ||
| 1318 | (should (erc--check-prompt-input-for-excess-lines "" '("a" "b"))))) | 1321 | (should (erc--check-prompt-input-for-excess-lines "" '("a" "b"))))) |
| 1319 | 1322 | ||
| 1320 | (ert-info ("With `erc-inhibit-multiline-input' as 3") | 1323 | (ert-info ("With `erc-inhibit-multiline-input' as 3") |
| 1321 | (let ((erc-inhibit-multiline-input 3)) | 1324 | (let ((erc-inhibit-multiline-input 3)) |
| 1322 | (should-not (erc--check-prompt-input-for-excess-lines "" '("a" "b"))) | 1325 | (should-not (erc--check-prompt-input-for-excess-lines "" '("a" "b"))) |
| 1323 | (should-not (erc--check-prompt-input-for-excess-lines "" '("a" "b" ""))) | 1326 | (should (erc--check-prompt-input-for-excess-lines "" '("a" "b" ""))) |
| 1324 | (should (erc--check-prompt-input-for-excess-lines "" '("a" "b" "c"))))) | 1327 | (should (erc--check-prompt-input-for-excess-lines "" '("a" "b" "c"))))) |
| 1325 | 1328 | ||
| 1326 | (ert-info ("With `erc-ask-about-multiline-input'") | 1329 | (ert-info ("With `erc-ask-about-multiline-input'") |
| @@ -1399,6 +1402,94 @@ | |||
| 1399 | 1402 | ||
| 1400 | (should-not calls)))))) | 1403 | (should-not calls)))))) |
| 1401 | 1404 | ||
| 1405 | |||
| 1406 | ;; The behavior of `erc-pre-send-functions' differs between versions | ||
| 1407 | ;; in how hook members see and influence a trailing newline that's | ||
| 1408 | ;; part of the original prompt submission: | ||
| 1409 | ;; | ||
| 1410 | ;; 5.4: both seen and sent | ||
| 1411 | ;; 5.5: seen but not sent* | ||
| 1412 | ;; 5.6: neither seen nor sent* | ||
| 1413 | ;; | ||
| 1414 | ;; * requires `erc-send-whitespace-lines' for hook to run | ||
| 1415 | ;; | ||
| 1416 | ;; Two aspects that have remained consistent are | ||
| 1417 | ;; | ||
| 1418 | ;; - a final nonempty line in any submission is always sent | ||
| 1419 | ;; - a trailing newline appended by a hook member is always sent | ||
| 1420 | ;; | ||
| 1421 | ;; The last bullet would seem to contradict the "not sent" behavior of | ||
| 1422 | ;; 5.5 and 5.6, but what's actually happening is that exactly one | ||
| 1423 | ;; trailing newline is culled, so anything added always goes through. | ||
| 1424 | ;; Also, in ERC 5.6, all empty lines are actually padded, but this is | ||
| 1425 | ;; merely incidental WRT the above. | ||
| 1426 | ;; | ||
| 1427 | ;; Note that this test doesn't run any input-prep hooks and thus can't | ||
| 1428 | ;; account for the "seen" dimension noted above. | ||
| 1429 | |||
| 1430 | (ert-deftest erc--run-send-hooks () | ||
| 1431 | (with-suppressed-warnings ((obsolete erc-send-this) | ||
| 1432 | (obsolete erc-send-pre-hook)) | ||
| 1433 | (should erc-insert-this) | ||
| 1434 | (should erc-send-this) ; populates `erc--input-split-sendp' | ||
| 1435 | |||
| 1436 | (let (erc-pre-send-functions erc-send-pre-hook) | ||
| 1437 | |||
| 1438 | (ert-info ("String preserved, lines rewritten, empties padded") | ||
| 1439 | (setq erc-pre-send-functions | ||
| 1440 | (lambda (o) (setf (erc-input-string o) "bar\n\nbaz\n"))) | ||
| 1441 | (should (pcase (erc--run-send-hooks (make-erc--input-split | ||
| 1442 | :string "foo" :lines '("foo"))) | ||
| 1443 | ((cl-struct erc--input-split | ||
| 1444 | (string "foo") (sendp 't) (insertp 't) | ||
| 1445 | (lines '("bar" " " "baz" " ")) (cmdp 'nil)) | ||
| 1446 | t)))) | ||
| 1447 | |||
| 1448 | (ert-info ("Multiline commands rejected") | ||
| 1449 | (should-error (erc--run-send-hooks (make-erc--input-split | ||
| 1450 | :string "/mycmd foo" | ||
| 1451 | :lines '("/mycmd foo") | ||
| 1452 | :cmdp t)))) | ||
| 1453 | |||
| 1454 | (ert-info ("Single-line commands pass") | ||
| 1455 | (setq erc-pre-send-functions | ||
| 1456 | (lambda (o) (setf (erc-input-sendp o) nil | ||
| 1457 | (erc-input-string o) "/mycmd bar"))) | ||
| 1458 | (should (pcase (erc--run-send-hooks (make-erc--input-split | ||
| 1459 | :string "/mycmd foo" | ||
| 1460 | :lines '("/mycmd foo") | ||
| 1461 | :cmdp t)) | ||
| 1462 | ((cl-struct erc--input-split | ||
| 1463 | (string "/mycmd foo") (sendp 'nil) (insertp 't) | ||
| 1464 | (lines '("/mycmd bar")) (cmdp 't)) | ||
| 1465 | t)))) | ||
| 1466 | |||
| 1467 | (ert-info ("Legacy hook respected, special vars confined") | ||
| 1468 | (setq erc-send-pre-hook (lambda (_) (setq erc-send-this nil)) | ||
| 1469 | erc-pre-send-functions (lambda (o) ; propagates | ||
| 1470 | (should-not (erc-input-sendp o)))) | ||
| 1471 | (should (pcase (erc--run-send-hooks (make-erc--input-split | ||
| 1472 | :string "foo" :lines '("foo"))) | ||
| 1473 | ((cl-struct erc--input-split | ||
| 1474 | (string "foo") (sendp 'nil) (insertp 't) | ||
| 1475 | (lines '("foo")) (cmdp 'nil)) | ||
| 1476 | t))) | ||
| 1477 | (should erc-send-this)) | ||
| 1478 | |||
| 1479 | (ert-info ("Request to resplit honored") | ||
| 1480 | (setq erc-send-pre-hook nil | ||
| 1481 | erc-pre-send-functions | ||
| 1482 | (lambda (o) (setf (erc-input-string o) "foo bar baz" | ||
| 1483 | (erc-input-refoldp o) t))) | ||
| 1484 | (let ((erc-split-line-length 8)) | ||
| 1485 | (should | ||
| 1486 | (pcase (erc--run-send-hooks (make-erc--input-split | ||
| 1487 | :string "foo" :lines '("foo"))) | ||
| 1488 | ((cl-struct erc--input-split | ||
| 1489 | (string "foo") (sendp 't) (insertp 't) | ||
| 1490 | (lines '("foo bar " "baz")) (cmdp 'nil)) | ||
| 1491 | t)))))))) | ||
| 1492 | |||
| 1402 | ;; Note: if adding an erc-backend-tests.el, please relocate this there. | 1493 | ;; Note: if adding an erc-backend-tests.el, please relocate this there. |
| 1403 | 1494 | ||
| 1404 | (ert-deftest erc-message () | 1495 | (ert-deftest erc-message () |