summaryrefslogtreecommitdiff
path: root/test/lisp/eshell/em-pred-tests.el
diff options
context:
space:
mode:
authorJim Porter <jporterbugs@gmail.com>2022-03-27 22:28:40 -0700
committerLars Ingebrigtsen <larsi@gnus.org>2022-05-01 20:41:18 +0200
commitade1424a975aabaa208010c6fdd3c8b7c51242ff (patch)
treef4c2e874ed3b1f5684f6e72e7f41401b9b3bd22c /test/lisp/eshell/em-pred-tests.el
parent788694d026b401715330576633a98542623978ff (diff)
downloademacs-ade1424a975aabaa208010c6fdd3c8b7c51242ff.tar.gz
emacs-ade1424a975aabaa208010c6fdd3c8b7c51242ff.tar.bz2
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/lisp/eshell/em-pred-tests.el')
-rw-r--r--test/lisp/eshell/em-pred-tests.el33
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 @@
(require 'ert)
(require 'esh-mode)
(require 'eshell)
+(require 'em-pred)
(require 'eshell-tests-helpers
(expand-file-name "eshell-tests-helpers"
@@ -254,8 +255,6 @@ read, write, and execute predicates to query the file's modes."
(cl-letf (((symbol-function 'eshell-user-id)
(lambda (name) (seq-position user-names name))))
(should (equal (eshell-eval-predicate files "u'one'")
- '("/fake/uid=1")))
- (should (equal (eshell-eval-predicate files "u{one}")
'("/fake/uid=1")))))))
(ert-deftest em-pred-test/predicate-gid ()
@@ -268,8 +267,6 @@ read, write, and execute predicates to query the file's modes."
(cl-letf (((symbol-function 'eshell-group-id)
(lambda (name) (seq-position group-names name))))
(should (equal (eshell-eval-predicate files "g'one'")
- '("/fake/gid=1")))
- (should (equal (eshell-eval-predicate files "g{one}")
'("/fake/gid=1")))))))
(defmacro em-pred-test--time-deftest (name file-attribute predicate
@@ -430,6 +427,8 @@ PREDICATE is the predicate used to query that attribute."
"Test that \":s/PAT/REP/\" replaces PAT with REP once."
(should (equal (eshell-eval-predicate "bar" ":s/a/*/") "b*r"))
(should (equal (eshell-eval-predicate "bar" ":s|a|*|") "b*r"))
+ (should (equal (eshell-eval-predicate "bar" ":s{a}{*}") "b*r"))
+ (should (equal (eshell-eval-predicate "bar" ":s{a}'*'") "b*r"))
(should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":s/[ao]/*/")
'("f*o" "b*r" "b*z")))
(should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":s|[ao]|*|")
@@ -450,23 +449,15 @@ PREDICATE is the predicate used to query that attribute."
(ert-deftest em-pred-test/modifier-include ()
"Test that \":i/PAT/\" filters elements to include only ones matching PAT."
(should (equal (eshell-eval-predicate "foo" ":i/a/") nil))
- (should (equal (eshell-eval-predicate "foo" ":i|a|") nil))
(should (equal (eshell-eval-predicate "bar" ":i/a/") "bar"))
- (should (equal (eshell-eval-predicate "bar" ":i|a|") "bar"))
(should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":i/a/")
- '("bar" "baz")))
- (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":i|a|")
'("bar" "baz"))))
(ert-deftest em-pred-test/modifier-exclude ()
"Test that \":x/PAT/\" filters elements to exclude any matching PAT."
(should (equal (eshell-eval-predicate "foo" ":x/a/") "foo"))
- (should (equal (eshell-eval-predicate "foo" ":x|a|") "foo"))
(should (equal (eshell-eval-predicate "bar" ":x/a/") nil))
- (should (equal (eshell-eval-predicate "bar" ":x|a|") nil))
(should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":x/a/")
- '("foo")))
- (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":x|a|")
'("foo"))))
(ert-deftest em-pred-test/modifier-split ()
@@ -516,7 +507,7 @@ PREDICATE is the predicate used to query that attribute."
'("baz" "bar" "foo"))))
-;; Combinations
+;; Miscellaneous
(ert-deftest em-pred-test/combine-predicate-and-modifier ()
"Test combination of predicates and modifiers."
@@ -526,4 +517,20 @@ PREDICATE is the predicate used to query that attribute."
(should (equal (eshell-eval-predicate files ".:e:u")
'("el" "txt"))))))
+(ert-deftest em-pred-test/predicate-delimiters ()
+ "Test various delimiter pairs with predicates and modifiers."
+ (dolist (delims eshell-pred-delimiter-pairs)
+ (eshell-with-file-attributes-from-name
+ (let ((files '("/fake/uid=1" "/fake/uid=2"))
+ (user-names '("root" "one" "two")))
+ (cl-letf (((symbol-function 'eshell-user-id)
+ (lambda (name) (seq-position user-names name))))
+ (should (equal (eshell-eval-predicate
+ files (format "u%cone%c" (car delims) (cdr delims)))
+ '("/fake/uid=1"))))))
+ (should (equal (eshell-eval-predicate
+ '("foo" "bar" "baz")
+ (format ":j%c-%c" (car delims) (cdr delims)))
+ "foo-bar-baz"))))
+
;; em-pred-tests.el ends here