diff options
| author | Jim Porter | 2022-07-06 21:59:11 -0700 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-07-12 15:11:00 +0200 |
| commit | 18d83b94528c503f2cd6d0a89f2c5db2d5d48165 (patch) | |
| tree | 6af1fbbb66e6958a053dab32c5c63f740ed1a2d2 /test | |
| parent | ba1923f1f1bba69bc13620042a00e315946ba82a (diff) | |
| download | emacs-18d83b94528c503f2cd6d0a89f2c5db2d5d48165.tar.gz emacs-18d83b94528c503f2cd6d0a89f2c5db2d5d48165.zip | |
Ensure Eshell variable aliases properly handle indexing
* lisp/eshell/em-dirs.el (eshell-dirs-initialize): Properly handle
indexing for variable aliases.
* lisp/eshell/esh-var (eshell-variable-aliases-list): Properly handle
indexing for variable aliases, and add SIMPLE-FUNCTION entry for
aliases.
(eshell-get-variable): Update how variable alias functions are called.
* test/lisp/eshell/em-alias-tests.el
(em-alias-test/alias-arg-vars-indices)
(em-alias-test/alias-arg-vars-split-indices)
(em-alias-test/alias-all-args-var-split-indices):
* test/lisp/eshell/em-dirs-tests.el (em-dirs-test/pwd-var-indices)
(em-dirs-test/oldpwd-var-indices)
(em-dirs-test/directory-ring-var-indices):
* test/lisp/eshell/esh-var-tests.el
(esh-var-test/inside-emacs-var-split-indices)
(esh-var-test/last-result-var-split-indices): New tests.
(esh-var-test/last-arg-var-split-indices): Expand test to check
conversion behavior inside double quotes (bug#56509).
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/eshell/em-alias-tests.el | 23 | ||||
| -rw-r--r-- | test/lisp/eshell/em-dirs-tests.el | 28 | ||||
| -rw-r--r-- | test/lisp/eshell/esh-var-tests.el | 22 |
3 files changed, 71 insertions, 2 deletions
diff --git a/test/lisp/eshell/em-alias-tests.el b/test/lisp/eshell/em-alias-tests.el index 762f125a786..497159e3460 100644 --- a/test/lisp/eshell/em-alias-tests.el +++ b/test/lisp/eshell/em-alias-tests.el | |||
| @@ -47,6 +47,23 @@ | |||
| 47 | (eshell-insert-command "alias show-args 'printnl $0 \"$1 $2\"'") | 47 | (eshell-insert-command "alias show-args 'printnl $0 \"$1 $2\"'") |
| 48 | (eshell-command-result-p "show-args one two" "show-args\none two\n"))) | 48 | (eshell-command-result-p "show-args one two" "show-args\none two\n"))) |
| 49 | 49 | ||
| 50 | (ert-deftest em-alias-test/alias-arg-vars-indices () | ||
| 51 | "Test alias with $1, $2, ... variables using indices" | ||
| 52 | (with-temp-eshell | ||
| 53 | (eshell-insert-command "alias funny-sum '+ $1[0] $2[1]'") | ||
| 54 | (eshell-command-result-p "funny-sum (list 1 2) (list 3 4)" | ||
| 55 | "5\n"))) | ||
| 56 | |||
| 57 | (ert-deftest em-alias-test/alias-arg-vars-split-indices () | ||
| 58 | "Test alias with $0, $1, ... variables using split indices" | ||
| 59 | (with-temp-eshell | ||
| 60 | (eshell-insert-command "alias my-prefix 'echo $0[- 0]'") | ||
| 61 | (eshell-command-result-p "my-prefix" | ||
| 62 | "my\n") | ||
| 63 | (eshell-insert-command "alias funny-sum '+ $1[: 0] $2[: 1]'") | ||
| 64 | (eshell-command-result-p "funny-sum 1:2 3:4" | ||
| 65 | "5\n"))) | ||
| 66 | |||
| 50 | (ert-deftest em-alias-test/alias-all-args-var () | 67 | (ert-deftest em-alias-test/alias-all-args-var () |
| 51 | "Test alias with the $* variable" | 68 | "Test alias with the $* variable" |
| 52 | (with-temp-eshell | 69 | (with-temp-eshell |
| @@ -61,4 +78,10 @@ | |||
| 61 | (eshell-insert-command "alias add-pair '+ $*[0] $*[1]'") | 78 | (eshell-insert-command "alias add-pair '+ $*[0] $*[1]'") |
| 62 | (eshell-command-result-p "add-pair 1 2" "3\n"))) | 79 | (eshell-command-result-p "add-pair 1 2" "3\n"))) |
| 63 | 80 | ||
| 81 | (ert-deftest em-alias-test/alias-all-args-var-split-indices () | ||
| 82 | "Test alias with the $* variable using split indices" | ||
| 83 | (with-temp-eshell | ||
| 84 | (eshell-insert-command "alias add-funny-pair '+ $*[0][: 0] $*[1][: 1]'") | ||
| 85 | (eshell-command-result-p "add-funny-pair 1:2 3:4" "5\n"))) | ||
| 86 | |||
| 64 | ;; em-alias-tests.el ends here | 87 | ;; em-alias-tests.el ends here |
diff --git a/test/lisp/eshell/em-dirs-tests.el b/test/lisp/eshell/em-dirs-tests.el index 69480051e49..8e96cc07471 100644 --- a/test/lisp/eshell/em-dirs-tests.el +++ b/test/lisp/eshell/em-dirs-tests.el | |||
| @@ -40,6 +40,14 @@ | |||
| 40 | (should (equal (eshell-test-command-result "echo $PWD") | 40 | (should (equal (eshell-test-command-result "echo $PWD") |
| 41 | (expand-file-name default-directory))))) | 41 | (expand-file-name default-directory))))) |
| 42 | 42 | ||
| 43 | (ert-deftest em-dirs-test/pwd-var-indices () | ||
| 44 | "Test using the $PWD variable with indices." | ||
| 45 | (let ((default-directory "/some/path/here")) | ||
| 46 | (should (equal (eshell-test-command-result "echo $PWD[/ 1]") | ||
| 47 | "some")) | ||
| 48 | (should (equal (eshell-test-command-result "echo $PWD[/ 1 3]") | ||
| 49 | '("some" "here"))))) | ||
| 50 | |||
| 43 | (ert-deftest em-dirs-test/short-pwd-var () | 51 | (ert-deftest em-dirs-test/short-pwd-var () |
| 44 | "Test using the $+ (current directory) variable." | 52 | "Test using the $+ (current directory) variable." |
| 45 | (let ((default-directory "/some/path")) | 53 | (let ((default-directory "/some/path")) |
| @@ -56,6 +64,16 @@ | |||
| 56 | (eshell-command-result-p "echo $OLDPWD" | 64 | (eshell-command-result-p "echo $OLDPWD" |
| 57 | "/some/path\n")))) | 65 | "/some/path\n")))) |
| 58 | 66 | ||
| 67 | (ert-deftest em-dirs-test/oldpwd-var-indices () | ||
| 68 | "Test using the $OLDPWD variable with indices." | ||
| 69 | (let (eshell-last-dir-ring-file-name) | ||
| 70 | (with-temp-eshell | ||
| 71 | (ring-insert eshell-last-dir-ring "/some/path/here") | ||
| 72 | (eshell-command-result-p "echo $OLDPWD[/ 1]" | ||
| 73 | "some\n") | ||
| 74 | (eshell-command-result-p "echo $OLDPWD[/ 1 3]" | ||
| 75 | "(\"some\" \"here\")\n")))) | ||
| 76 | |||
| 59 | (ert-deftest em-dirs-test/directory-ring-var () | 77 | (ert-deftest em-dirs-test/directory-ring-var () |
| 60 | "Test using the $- (directory ring) variable." | 78 | "Test using the $- (directory ring) variable." |
| 61 | (let (eshell-last-dir-ring-file-name) | 79 | (let (eshell-last-dir-ring-file-name) |
| @@ -71,4 +89,14 @@ | |||
| 71 | (eshell-command-result-p "echo $-[1]" | 89 | (eshell-command-result-p "echo $-[1]" |
| 72 | "/some/path\n")))) | 90 | "/some/path\n")))) |
| 73 | 91 | ||
| 92 | (ert-deftest em-dirs-test/directory-ring-var-indices () | ||
| 93 | "Test using the $- (directory ring) variable with multiple indices." | ||
| 94 | (let (eshell-last-dir-ring-file-name) | ||
| 95 | (with-temp-eshell | ||
| 96 | (ring-insert eshell-last-dir-ring "/some/path/here") | ||
| 97 | (eshell-command-result-p "echo $-[0][/ 1]" | ||
| 98 | "some\n") | ||
| 99 | (eshell-command-result-p "echo $-[1][/ 1 3]" | ||
| 100 | "(\"some\" \"here\")\n")))) | ||
| 101 | |||
| 74 | ;; em-dirs-tests.el ends here | 102 | ;; em-dirs-tests.el ends here |
diff --git a/test/lisp/eshell/esh-var-tests.el b/test/lisp/eshell/esh-var-tests.el index 955190aee0b..54e701a6aab 100644 --- a/test/lisp/eshell/esh-var-tests.el +++ b/test/lisp/eshell/esh-var-tests.el | |||
| @@ -494,6 +494,12 @@ inside double-quotes" | |||
| 494 | (format "INSIDE_EMACS=%s,eshell" | 494 | (format "INSIDE_EMACS=%s,eshell" |
| 495 | emacs-version)))) | 495 | emacs-version)))) |
| 496 | 496 | ||
| 497 | (ert-deftest esh-var-test/inside-emacs-var-split-indices () | ||
| 498 | "Test using \"INSIDE_EMACS\" with split indices" | ||
| 499 | (with-temp-eshell | ||
| 500 | (eshell-command-result-p "echo $INSIDE_EMACS[, 1]" | ||
| 501 | "eshell"))) | ||
| 502 | |||
| 497 | (ert-deftest esh-var-test/last-result-var () | 503 | (ert-deftest esh-var-test/last-result-var () |
| 498 | "Test using the \"last result\" ($$) variable" | 504 | "Test using the \"last result\" ($$) variable" |
| 499 | (with-temp-eshell | 505 | (with-temp-eshell |
| @@ -506,6 +512,16 @@ inside double-quotes" | |||
| 506 | (eshell-command-result-p "+ 1 2; + $$ $$" | 512 | (eshell-command-result-p "+ 1 2; + $$ $$" |
| 507 | "3\n6\n"))) | 513 | "3\n6\n"))) |
| 508 | 514 | ||
| 515 | (ert-deftest esh-var-test/last-result-var-split-indices () | ||
| 516 | "Test using the \"last result\" ($$) variable with split indices" | ||
| 517 | (with-temp-eshell | ||
| 518 | (eshell-command-result-p | ||
| 519 | "string-join (list \"01\" \"02\") :; + $$[: 1] 3" | ||
| 520 | "01:02\n5\n") | ||
| 521 | (eshell-command-result-p | ||
| 522 | "string-join (list \"01\" \"02\") :; echo \"$$[: 1]\"" | ||
| 523 | "01:02\n02\n"))) | ||
| 524 | |||
| 509 | (ert-deftest esh-var-test/last-arg-var () | 525 | (ert-deftest esh-var-test/last-arg-var () |
| 510 | "Test using the \"last arg\" ($_) variable" | 526 | "Test using the \"last arg\" ($_) variable" |
| 511 | (with-temp-eshell | 527 | (with-temp-eshell |
| @@ -523,7 +539,9 @@ inside double-quotes" | |||
| 523 | (ert-deftest esh-var-test/last-arg-var-split-indices () | 539 | (ert-deftest esh-var-test/last-arg-var-split-indices () |
| 524 | "Test using the \"last arg\" ($_) variable with split indices" | 540 | "Test using the \"last arg\" ($_) variable with split indices" |
| 525 | (with-temp-eshell | 541 | (with-temp-eshell |
| 526 | (eshell-command-result-p "concat 01:02 03:04; echo $_[0][: 1]" | 542 | (eshell-command-result-p "concat 01:02 03:04; + $_[0][: 1] 5" |
| 527 | "01:0203:04\n2\n"))) | 543 | "01:0203:04\n7\n") |
| 544 | (eshell-command-result-p "concat 01:02 03:04; echo \"$_[0][: 1]\"" | ||
| 545 | "01:0203:04\n02\n"))) | ||
| 528 | 546 | ||
| 529 | ;; esh-var-tests.el ends here | 547 | ;; esh-var-tests.el ends here |