aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAugusto Stoffel2022-09-08 11:09:42 +0200
committerLars Ingebrigtsen2022-09-14 21:58:04 +0200
commita9941269683fe50673d0aa81feefb7a9d3d8a6b9 (patch)
tree566c9ecd3afb90b58607c71ad794cee14ba7b823 /test
parent05971d2b8d47e69e9585d0d6066b8a607555aa48 (diff)
downloademacs-a9941269683fe50673d0aa81feefb7a9d3d8a6b9.tar.gz
emacs-a9941269683fe50673d0aa81feefb7a9d3d8a6b9.zip
pcomplete: Generate completions from --help messages
* lisp/pcomplete.el (pcomplete-from-help): New function (and hash table) to get pcomplete candidates from help messages. (pcomplete-here-using-help): Helper function to define pcomplete for simple commands (pcomplete-completions-at-point): Provide annotation-function and company-docsig properties. * lisp/pcmpl-git.el: New file, provides pcomplete for Git. * lisp/pcmpl-gnu.el: Add pcomplete for awk, gpg and gdb, emacs and emacsclient. * lisp/pcmpl-linux.el: Add pcomplete for systemctl and journalctl. * lisp/pcmpl-rpm.el: Add pcomplete for dnf. * lisp/pcmpl-unix.el: Add pcomplete for sudo and most commands found in GNU Coreutils. * lisp/pcmpl-x.el: Add pcomplete for tex, pdftex, latex, pdflatex, rigrep and rclone. * test/lisp/pcomplete-tests.el (pcomplete-test-parse-gpg-help, pcomplete-test-parse-git-help): Tests for the new functions.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/pcomplete-tests.el100
1 files changed, 100 insertions, 0 deletions
diff --git a/test/lisp/pcomplete-tests.el b/test/lisp/pcomplete-tests.el
new file mode 100644
index 00000000000..00a82502f30
--- /dev/null
+++ b/test/lisp/pcomplete-tests.el
@@ -0,0 +1,100 @@
1;;; pcomplete-tests.el --- Tests for pcomplete.el -*- lexical-binding: t -*-
2
3;; Copyright (C) 2022 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Commentary:
21
22;;; Code:
23
24(require 'ert)
25(require 'pcomplete)
26
27(ert-deftest pcomplete-test-parse-gpg-help ()
28 (cl-letf ((pcomplete-from-help (make-hash-table :test #'equal))
29 ((symbol-function 'call-process)
30 (lambda (&rest _) (insert "\
31gpg (GnuPG) 2.3.7
32
33Commands:
34
35 -s, --sign make a signature
36 --clear-sign make a clear text signature
37 -b, --detach-sign make a detached signature
38 --tofu-policy VALUE set the TOFU policy for a key
39
40Options to specify keys:
41 -r, --recipient USER-ID encrypt for USER-ID
42 -u, --local-user USER-ID use USER-ID to sign or decrypt
43
44(See the man page for a complete listing of all commands and options)
45
46Examples:
47
48 -se -r Bob [file] sign and encrypt for user Bob
49 --clear-sign [file] make a clear text signature
50"))))
51 (should
52 (equal-including-properties
53 (pcomplete-from-help "gpg --help" :narrow-end "^ -se")
54 '(#("-s" 0 1 (pcomplete-help "make a signature"))
55 #("--sign" 0 1 (pcomplete-help "make a signature"))
56 #("--clear-sign" 0 1 (pcomplete-help "make a clear text signature"))
57 #("-b" 0 1 (pcomplete-help "make a detached signature"))
58 #("--detach-sign" 0 1 (pcomplete-help "make a detached signature"))
59 #("--tofu-policy" 0 1
60 (pcomplete-help "set the TOFU policy for a key" pcomplete-annotation " VALUE"))
61 #("-r" 0 1 (pcomplete-help "encrypt for USER-ID"))
62 #("--recipient" 0 1
63 (pcomplete-help "encrypt for USER-ID" pcomplete-annotation " USER-ID"))
64 #("-u" 0 1
65 (pcomplete-help "use USER-ID to sign or decrypt"))
66 #("--local-user" 0 1
67 (pcomplete-help "use USER-ID to sign or decrypt" pcomplete-annotation " USER-ID")))))))
68
69(ert-deftest pcomplete-test-parse-git-help ()
70 (cl-letf ((pcomplete-from-help (make-hash-table :test #'equal))
71 ((symbol-function 'call-process)
72 (lambda (&rest _) (insert "\
73usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
74 [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
75 [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
76 [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
77 [--super-prefix=<path>] [--config-env=<name>=<envvar>]
78 <command> [<args>]
79"))))
80 (should
81 (equal-including-properties
82 (pcomplete-from-help "git help"
83 :margin "\\(\\[\\)-"
84 :separator " | "
85 :description "\\`")
86 '("-v" "--version" "-h" "--help"
87 #("-C" 0 1 (pcomplete-annotation " <path>"))
88 #("-c" 0 1 (pcomplete-annotation " <name>"))
89 #("--exec-path" 0 1 (pcomplete-annotation "[=<path>]"))
90 "--html-path" "--man-path" "--info-path"
91 "-p" "--paginate" "-P" "--no-pager"
92 "--no-replace-objects" "--bare"
93 #("--git-dir=" 0 1 (pcomplete-annotation "<path>"))
94 #("--work-tree=" 0 1 (pcomplete-annotation "<path>"))
95 #("--namespace=" 0 1 (pcomplete-annotation "<name>"))
96 #("--super-prefix=" 0 1 (pcomplete-annotation "<path>"))
97 #("--config-env=" 0 1 (pcomplete-annotation "<name>")))))))
98
99(provide 'pcomplete-tests)
100;;; pcomplete-tests.el ends here