diff options
| author | Simen Heggestøyl | 2020-04-18 18:36:49 +0200 |
|---|---|---|
| committer | Simen Heggestøyl | 2020-04-18 18:43:23 +0200 |
| commit | 45d42f81621743a96f209102464432ef2f230b0f (patch) | |
| tree | d2671b98e9455f85ff03449585260e50ac5bd813 /test | |
| parent | 4819bea6900348f923e0de58995ec41760993b6c (diff) | |
| download | emacs-45d42f81621743a96f209102464432ef2f230b0f.tar.gz emacs-45d42f81621743a96f209102464432ef2f230b0f.zip | |
Use lexical-binding in apropos.el and add tests
* lisp/apropos.el: Use lexical-binding and remove redundant
:group args.
(apropos-words-to-regexp, apropos): Tweak docstrings.
(apropos-value-internal): Replace '(if x (progn y))' with
'(when x y)'.
(apropos-format-plist): Add docstring and replace '(if x (progn y))'
with '(when x y)'.
* test/lisp/apropos-tests.el: New file with tests for apropos.el.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/apropos-tests.el | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/test/lisp/apropos-tests.el b/test/lisp/apropos-tests.el new file mode 100644 index 00000000000..4c5522d14c2 --- /dev/null +++ b/test/lisp/apropos-tests.el | |||
| @@ -0,0 +1,133 @@ | |||
| 1 | ;;; apropos-tests.el --- Tests for apropos.el -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2020 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Simen Heggestøyl <simenheg@gmail.com> | ||
| 6 | ;; Keywords: | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 13 | ;; (at your option) any later version. | ||
| 14 | |||
| 15 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; | ||
| 26 | |||
| 27 | ;;; Code: | ||
| 28 | |||
| 29 | (require 'apropos) | ||
| 30 | (require 'ert) | ||
| 31 | |||
| 32 | (ert-deftest apropos-tests-words-to-regexp-1 () | ||
| 33 | (let ((re (apropos-words-to-regexp '("foo" "bar") "baz"))) | ||
| 34 | (should (string-match-p re "foobazbar")) | ||
| 35 | (should (string-match-p re "barbazfoo")) | ||
| 36 | (should-not (string-match-p re "foo-bar")) | ||
| 37 | (should-not (string-match-p re "foobazbazbar")))) | ||
| 38 | |||
| 39 | (ert-deftest apropos-tests-words-to-regexp-2 () | ||
| 40 | (let ((re (apropos-words-to-regexp '("foo" "bar" "baz") "-"))) | ||
| 41 | (should-not (string-match-p re "foo")) | ||
| 42 | (should-not (string-match-p re "foobar")) | ||
| 43 | (should (string-match-p re "foo-bar")) | ||
| 44 | (should (string-match-p re "foo-baz")))) | ||
| 45 | |||
| 46 | (ert-deftest apropos-tests-parse-pattern-1 () | ||
| 47 | (apropos-parse-pattern '("foo")) | ||
| 48 | (should (string-match-p apropos-regexp "foo")) | ||
| 49 | (should (string-match-p apropos-regexp "foo-bar")) | ||
| 50 | (should (string-match-p apropos-regexp "bar-foo")) | ||
| 51 | (should (string-match-p apropos-regexp "foo-foo")) | ||
| 52 | (should-not (string-match-p apropos-regexp "bar"))) | ||
| 53 | |||
| 54 | (ert-deftest apropos-tests-parse-pattern-2 () | ||
| 55 | (apropos-parse-pattern '("foo" "bar")) | ||
| 56 | (should (string-match-p apropos-regexp "foo-bar")) | ||
| 57 | (should (string-match-p apropos-regexp "bar-foo")) | ||
| 58 | (should-not (string-match-p apropos-regexp "foo")) | ||
| 59 | (should-not (string-match-p apropos-regexp "bar")) | ||
| 60 | (should-not (string-match-p apropos-regexp "baz")) | ||
| 61 | (should-not (string-match-p apropos-regexp "foo-foo")) | ||
| 62 | (should-not (string-match-p apropos-regexp "bar-bar"))) | ||
| 63 | |||
| 64 | (ert-deftest apropos-tests-parse-pattern-3 () | ||
| 65 | (apropos-parse-pattern '("foo" "bar" "baz")) | ||
| 66 | (should (string-match-p apropos-regexp "foo-bar")) | ||
| 67 | (should (string-match-p apropos-regexp "foo-baz")) | ||
| 68 | (should (string-match-p apropos-regexp "bar-foo")) | ||
| 69 | (should (string-match-p apropos-regexp "bar-baz")) | ||
| 70 | (should (string-match-p apropos-regexp "baz-foo")) | ||
| 71 | (should (string-match-p apropos-regexp "baz-bar")) | ||
| 72 | (should-not (string-match-p apropos-regexp "foo")) | ||
| 73 | (should-not (string-match-p apropos-regexp "bar")) | ||
| 74 | (should-not (string-match-p apropos-regexp "baz")) | ||
| 75 | (should-not (string-match-p apropos-regexp "foo-foo")) | ||
| 76 | (should-not (string-match-p apropos-regexp "bar-bar")) | ||
| 77 | (should-not (string-match-p apropos-regexp "baz-baz"))) | ||
| 78 | |||
| 79 | (ert-deftest apropos-tests-parse-pattern-single-regexp () | ||
| 80 | (apropos-parse-pattern "foo+bar") | ||
| 81 | (should-not (string-match-p apropos-regexp "fobar")) | ||
| 82 | (should (string-match-p apropos-regexp "foobar")) | ||
| 83 | (should (string-match-p apropos-regexp "fooobar"))) | ||
| 84 | |||
| 85 | (ert-deftest apropos-tests-parse-pattern-synonyms () | ||
| 86 | (let ((apropos-synonyms '(("find" "open" "edit")))) | ||
| 87 | (apropos-parse-pattern '("open")) | ||
| 88 | (should (string-match-p apropos-regexp "find-file")) | ||
| 89 | (should (string-match-p apropos-regexp "open-file")) | ||
| 90 | (should (string-match-p apropos-regexp "edit-file")))) | ||
| 91 | |||
| 92 | (ert-deftest apropos-tests-calc-scores () | ||
| 93 | (let ((str "Return apropos score for string STR.")) | ||
| 94 | (should (equal (apropos-calc-scores str '("apr")) '(7))) | ||
| 95 | (should (equal (apropos-calc-scores str '("apr" "str")) '(25 7))) | ||
| 96 | (should (equal (apropos-calc-scores str '("appr" "str")) '(25))) | ||
| 97 | (should-not (apropos-calc-scores str '("appr" "strr"))))) | ||
| 98 | |||
| 99 | (ert-deftest apropos-tests-score-str () | ||
| 100 | (apropos-parse-pattern '("foo" "bar")) | ||
| 101 | (should (< (apropos-score-str "baz") | ||
| 102 | (apropos-score-str "foo baz") | ||
| 103 | (apropos-score-str "foo bar baz")))) | ||
| 104 | |||
| 105 | (ert-deftest apropos-tests-score-doc () | ||
| 106 | (apropos-parse-pattern '("foo" "bar")) | ||
| 107 | (should (< (apropos-score-doc "baz") | ||
| 108 | (apropos-score-doc "foo baz") | ||
| 109 | (apropos-score-doc "foo bar baz")))) | ||
| 110 | |||
| 111 | (ert-deftest apropos-tests-score-symbol () | ||
| 112 | (apropos-parse-pattern '("foo" "bar")) | ||
| 113 | (should (< (apropos-score-symbol 'baz) | ||
| 114 | (apropos-score-symbol 'foo-baz) | ||
| 115 | (apropos-score-symbol 'foo-bar-baz)))) | ||
| 116 | |||
| 117 | (ert-deftest apropos-tests-true-hit () | ||
| 118 | (should-not (apropos-true-hit "foo" '("foo" "bar"))) | ||
| 119 | (should (apropos-true-hit "foo bar" '("foo" "bar"))) | ||
| 120 | (should (apropos-true-hit "foo bar baz" '("foo" "bar")))) | ||
| 121 | |||
| 122 | (ert-deftest apropos-tests-format-plist () | ||
| 123 | (setplist 'foo '(a 1 b (2 3) c nil)) | ||
| 124 | (apropos-parse-pattern '("b")) | ||
| 125 | (should (equal (apropos-format-plist 'foo ", ") | ||
| 126 | "a 1, b (2 3), c nil")) | ||
| 127 | (should (equal (apropos-format-plist 'foo ", " t) | ||
| 128 | "b (2 3)")) | ||
| 129 | (apropos-parse-pattern '("d")) | ||
| 130 | (should-not (apropos-format-plist 'foo ", " t))) | ||
| 131 | |||
| 132 | (provide 'apropos-tests) | ||
| 133 | ;;; apropos-tests.el ends here | ||