diff options
| author | Jim Porter | 2022-03-27 22:28:40 -0700 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-05-01 20:41:18 +0200 |
| commit | ade1424a975aabaa208010c6fdd3c8b7c51242ff (patch) | |
| tree | f4c2e874ed3b1f5684f6e72e7f41401b9b3bd22c /test | |
| parent | 788694d026b401715330576633a98542623978ff (diff) | |
| download | emacs-ade1424a975aabaa208010c6fdd3c8b7c51242ff.tar.gz emacs-ade1424a975aabaa208010c6fdd3c8b7c51242ff.zip | |
Use a common set of string delimiters for all Eshell predicates/modifiers
* lisp/eshell/em-pred.el (eshell-pred-delimiter-pairs): New variable.
(eshell-get-comparison-modifier-argument)
(eshell-get-numeric-modifier-argument)
(eshell-get-delimited-modifier-argument): New functions...
(eshell-pred-user-or-group, eshell-pred-file-time)
(eshell-pred-file-links, eshell-pred-file-size)
(eshell-pred-substitute, eshell-join-memebers, eshell-split-members):
... and use them here.
(eshell-include-members): Pass 'mod-char' and use
'eshell-get-delimited-modifier-argument'.
(eshell-pred-file-type, eshell-pred-file-mode): Use 'when-let'.
(eshell-modifier-alist): Pass modifier char to
'eshell-include-members'.
* test/lisp/eshell/em-pred-tests.el
(em-pred-test/predicate-delimiters): New test.
(em-pred-test/predicate-uid, em-pred-test/predicate-gid,
em-pred-test/modifier-include, em-pred-test/modifier-exclude): Remove
cases covered by 'em-pred-test/predicate-delimiters'.
(em-pred-test/modifier-substitute): Add test cases for new delimiter
styles.
* doc/misc/eshell.texi (Argument Predication and Modification):
Explain how string parameters are delimited.
(Argument Modifiers): Document some special delimiter behavior with
the 's/PATTERN/REPLACE/' modifier (bug#55204).
* etc/NEWS: Announce this change, and move the
'eshell-eval-using-options' entry to the Eshell section.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/eshell/em-pred-tests.el | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/test/lisp/eshell/em-pred-tests.el b/test/lisp/eshell/em-pred-tests.el index 7f88ac44755..4d2af392923 100644 --- a/test/lisp/eshell/em-pred-tests.el +++ b/test/lisp/eshell/em-pred-tests.el | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | (require 'ert) | 26 | (require 'ert) |
| 27 | (require 'esh-mode) | 27 | (require 'esh-mode) |
| 28 | (require 'eshell) | 28 | (require 'eshell) |
| 29 | (require 'em-pred) | ||
| 29 | 30 | ||
| 30 | (require 'eshell-tests-helpers | 31 | (require 'eshell-tests-helpers |
| 31 | (expand-file-name "eshell-tests-helpers" | 32 | (expand-file-name "eshell-tests-helpers" |
| @@ -254,8 +255,6 @@ read, write, and execute predicates to query the file's modes." | |||
| 254 | (cl-letf (((symbol-function 'eshell-user-id) | 255 | (cl-letf (((symbol-function 'eshell-user-id) |
| 255 | (lambda (name) (seq-position user-names name)))) | 256 | (lambda (name) (seq-position user-names name)))) |
| 256 | (should (equal (eshell-eval-predicate files "u'one'") | 257 | (should (equal (eshell-eval-predicate files "u'one'") |
| 257 | '("/fake/uid=1"))) | ||
| 258 | (should (equal (eshell-eval-predicate files "u{one}") | ||
| 259 | '("/fake/uid=1"))))))) | 258 | '("/fake/uid=1"))))))) |
| 260 | 259 | ||
| 261 | (ert-deftest em-pred-test/predicate-gid () | 260 | (ert-deftest em-pred-test/predicate-gid () |
| @@ -268,8 +267,6 @@ read, write, and execute predicates to query the file's modes." | |||
| 268 | (cl-letf (((symbol-function 'eshell-group-id) | 267 | (cl-letf (((symbol-function 'eshell-group-id) |
| 269 | (lambda (name) (seq-position group-names name)))) | 268 | (lambda (name) (seq-position group-names name)))) |
| 270 | (should (equal (eshell-eval-predicate files "g'one'") | 269 | (should (equal (eshell-eval-predicate files "g'one'") |
| 271 | '("/fake/gid=1"))) | ||
| 272 | (should (equal (eshell-eval-predicate files "g{one}") | ||
| 273 | '("/fake/gid=1"))))))) | 270 | '("/fake/gid=1"))))))) |
| 274 | 271 | ||
| 275 | (defmacro em-pred-test--time-deftest (name file-attribute predicate | 272 | (defmacro em-pred-test--time-deftest (name file-attribute predicate |
| @@ -430,6 +427,8 @@ PREDICATE is the predicate used to query that attribute." | |||
| 430 | "Test that \":s/PAT/REP/\" replaces PAT with REP once." | 427 | "Test that \":s/PAT/REP/\" replaces PAT with REP once." |
| 431 | (should (equal (eshell-eval-predicate "bar" ":s/a/*/") "b*r")) | 428 | (should (equal (eshell-eval-predicate "bar" ":s/a/*/") "b*r")) |
| 432 | (should (equal (eshell-eval-predicate "bar" ":s|a|*|") "b*r")) | 429 | (should (equal (eshell-eval-predicate "bar" ":s|a|*|") "b*r")) |
| 430 | (should (equal (eshell-eval-predicate "bar" ":s{a}{*}") "b*r")) | ||
| 431 | (should (equal (eshell-eval-predicate "bar" ":s{a}'*'") "b*r")) | ||
| 433 | (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":s/[ao]/*/") | 432 | (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":s/[ao]/*/") |
| 434 | '("f*o" "b*r" "b*z"))) | 433 | '("f*o" "b*r" "b*z"))) |
| 435 | (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":s|[ao]|*|") | 434 | (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":s|[ao]|*|") |
| @@ -450,23 +449,15 @@ PREDICATE is the predicate used to query that attribute." | |||
| 450 | (ert-deftest em-pred-test/modifier-include () | 449 | (ert-deftest em-pred-test/modifier-include () |
| 451 | "Test that \":i/PAT/\" filters elements to include only ones matching PAT." | 450 | "Test that \":i/PAT/\" filters elements to include only ones matching PAT." |
| 452 | (should (equal (eshell-eval-predicate "foo" ":i/a/") nil)) | 451 | (should (equal (eshell-eval-predicate "foo" ":i/a/") nil)) |
| 453 | (should (equal (eshell-eval-predicate "foo" ":i|a|") nil)) | ||
| 454 | (should (equal (eshell-eval-predicate "bar" ":i/a/") "bar")) | 452 | (should (equal (eshell-eval-predicate "bar" ":i/a/") "bar")) |
| 455 | (should (equal (eshell-eval-predicate "bar" ":i|a|") "bar")) | ||
| 456 | (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":i/a/") | 453 | (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":i/a/") |
| 457 | '("bar" "baz"))) | ||
| 458 | (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":i|a|") | ||
| 459 | '("bar" "baz")))) | 454 | '("bar" "baz")))) |
| 460 | 455 | ||
| 461 | (ert-deftest em-pred-test/modifier-exclude () | 456 | (ert-deftest em-pred-test/modifier-exclude () |
| 462 | "Test that \":x/PAT/\" filters elements to exclude any matching PAT." | 457 | "Test that \":x/PAT/\" filters elements to exclude any matching PAT." |
| 463 | (should (equal (eshell-eval-predicate "foo" ":x/a/") "foo")) | 458 | (should (equal (eshell-eval-predicate "foo" ":x/a/") "foo")) |
| 464 | (should (equal (eshell-eval-predicate "foo" ":x|a|") "foo")) | ||
| 465 | (should (equal (eshell-eval-predicate "bar" ":x/a/") nil)) | 459 | (should (equal (eshell-eval-predicate "bar" ":x/a/") nil)) |
| 466 | (should (equal (eshell-eval-predicate "bar" ":x|a|") nil)) | ||
| 467 | (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":x/a/") | 460 | (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":x/a/") |
| 468 | '("foo"))) | ||
| 469 | (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":x|a|") | ||
| 470 | '("foo")))) | 461 | '("foo")))) |
| 471 | 462 | ||
| 472 | (ert-deftest em-pred-test/modifier-split () | 463 | (ert-deftest em-pred-test/modifier-split () |
| @@ -516,7 +507,7 @@ PREDICATE is the predicate used to query that attribute." | |||
| 516 | '("baz" "bar" "foo")))) | 507 | '("baz" "bar" "foo")))) |
| 517 | 508 | ||
| 518 | 509 | ||
| 519 | ;; Combinations | 510 | ;; Miscellaneous |
| 520 | 511 | ||
| 521 | (ert-deftest em-pred-test/combine-predicate-and-modifier () | 512 | (ert-deftest em-pred-test/combine-predicate-and-modifier () |
| 522 | "Test combination of predicates and modifiers." | 513 | "Test combination of predicates and modifiers." |
| @@ -526,4 +517,20 @@ PREDICATE is the predicate used to query that attribute." | |||
| 526 | (should (equal (eshell-eval-predicate files ".:e:u") | 517 | (should (equal (eshell-eval-predicate files ".:e:u") |
| 527 | '("el" "txt")))))) | 518 | '("el" "txt")))))) |
| 528 | 519 | ||
| 520 | (ert-deftest em-pred-test/predicate-delimiters () | ||
| 521 | "Test various delimiter pairs with predicates and modifiers." | ||
| 522 | (dolist (delims eshell-pred-delimiter-pairs) | ||
| 523 | (eshell-with-file-attributes-from-name | ||
| 524 | (let ((files '("/fake/uid=1" "/fake/uid=2")) | ||
| 525 | (user-names '("root" "one" "two"))) | ||
| 526 | (cl-letf (((symbol-function 'eshell-user-id) | ||
| 527 | (lambda (name) (seq-position user-names name)))) | ||
| 528 | (should (equal (eshell-eval-predicate | ||
| 529 | files (format "u%cone%c" (car delims) (cdr delims))) | ||
| 530 | '("/fake/uid=1")))))) | ||
| 531 | (should (equal (eshell-eval-predicate | ||
| 532 | '("foo" "bar" "baz") | ||
| 533 | (format ":j%c-%c" (car delims) (cdr delims))) | ||
| 534 | "foo-bar-baz")))) | ||
| 535 | |||
| 529 | ;; em-pred-tests.el ends here | 536 | ;; em-pred-tests.el ends here |