unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 917c08b9114c11b20ffe2032128be0f358070139 5355 bytes (raw)
name: test/lisp/apropos-tests.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
 
;;; apropos-tests.el --- Tests for apropos.el  -*- lexical-binding: t; -*-

;; Copyright (C) 2020-2022 Free Software Foundation, Inc.

;; Author: Simen Heggestøyl <simenheg@gmail.com>
;; Keywords:

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;;

;;; Code:

(require 'apropos)
(require 'ert)

(ert-deftest apropos-tests-words-to-regexp-1 ()
  (let ((re (apropos-words-to-regexp '("foo" "bar") "baz")))
    (should (string-match-p re "foobazbar"))
    (should (string-match-p re "barbazfoo"))
    (should-not (string-match-p re "foo-bar"))
    (should-not (string-match-p re "foobazbazbar"))))

(ert-deftest apropos-tests-words-to-regexp-2 ()
  (let ((re (apropos-words-to-regexp '("foo" "bar" "baz") "-")))
    (should-not (string-match-p re "foo"))
    (should-not (string-match-p re "foobar"))
    (should (string-match-p re "foo-bar"))
    (should (string-match-p re "foo-baz"))))

(ert-deftest apropos-tests-parse-pattern-1 ()
  (apropos-parse-pattern '("foo"))
  (should (string-match-p apropos-regexp "foo"))
  (should (string-match-p apropos-regexp "foo-bar"))
  (should (string-match-p apropos-regexp "bar-foo"))
  (should (string-match-p apropos-regexp "foo-foo"))
  (should-not (string-match-p apropos-regexp "bar")))

(ert-deftest apropos-tests-parse-pattern-2 ()
  (apropos-parse-pattern '("foo" "bar"))
  (should (string-match-p apropos-regexp "foo-bar"))
  (should (string-match-p apropos-regexp "bar-foo"))
  (should-not (string-match-p apropos-regexp "foo"))
  (should-not (string-match-p apropos-regexp "bar"))
  (should-not (string-match-p apropos-regexp "baz"))
  (should-not (string-match-p apropos-regexp "foo-foo"))
  (should-not (string-match-p apropos-regexp "bar-bar")))

(ert-deftest apropos-tests-parse-pattern-3 ()
  (apropos-parse-pattern '("foo" "bar" "baz"))
  (should (string-match-p apropos-regexp "foo-bar"))
  (should (string-match-p apropos-regexp "foo-baz"))
  (should (string-match-p apropos-regexp "bar-foo"))
  (should (string-match-p apropos-regexp "bar-baz"))
  (should (string-match-p apropos-regexp "baz-foo"))
  (should (string-match-p apropos-regexp "baz-bar"))
  (should-not (string-match-p apropos-regexp "foo"))
  (should-not (string-match-p apropos-regexp "bar"))
  (should-not (string-match-p apropos-regexp "baz"))
  (should-not (string-match-p apropos-regexp "foo-foo"))
  (should-not (string-match-p apropos-regexp "bar-bar"))
  (should-not (string-match-p apropos-regexp "baz-baz")))

(ert-deftest apropos-tests-parse-pattern-single-regexp ()
  (apropos-parse-pattern "foo+bar")
  (should-not (string-match-p apropos-regexp "fobar"))
  (should (string-match-p apropos-regexp "foobar"))
  (should (string-match-p apropos-regexp "fooobar")))

(ert-deftest apropos-tests-parse-pattern-synonyms ()
  (let ((apropos-synonyms '(("find" "open" "edit"))))
    (apropos-parse-pattern '("open"))
    (should (string-match-p apropos-regexp "find-file"))
    (should (string-match-p apropos-regexp "open-file"))
    (should (string-match-p apropos-regexp "edit-file"))))

(ert-deftest apropos-tests-calc-scores ()
  (let ((str "Return apropos score for string STR."))
    (should (equal (apropos-calc-scores str '("apr")) '(7)))
    (should (equal (apropos-calc-scores str '("apr" "str")) '(25 7)))
    (should (equal (apropos-calc-scores str '("appr" "str")) '(25)))
    (should-not (apropos-calc-scores str '("appr" "strr")))))

(ert-deftest apropos-tests-score-str ()
  (apropos-parse-pattern '("foo" "bar"))
  (should (< (apropos-score-str "baz")
             (apropos-score-str "foo baz")
             (apropos-score-str "foo bar baz"))))

(ert-deftest apropos-tests-score-doc ()
  (apropos-parse-pattern '("foo" "bar"))
  (should (< (apropos-score-doc "baz")
             (apropos-score-doc "foo baz")
             (apropos-score-doc "foo bar baz"))))

(ert-deftest apropos-tests-score-symbol ()
  (apropos-parse-pattern '("foo" "bar"))
  (should (< (apropos-score-symbol 'baz)
             (apropos-score-symbol 'foo-baz)
             (apropos-score-symbol 'foo-bar-baz))))

(ert-deftest apropos-tests-true-hit ()
  (should-not (apropos-true-hit "foo" '("foo" "bar")))
  (should (apropos-true-hit "foo bar" '("foo" "bar")))
  (should (apropos-true-hit "foo bar baz" '("foo" "bar"))))

(ert-deftest apropos-tests-format-plist ()
  (let ((foo (make-symbol "foo")))
    (setplist foo '(a 1 b (2 3) c nil))
    (apropos-parse-pattern '("b"))
    (should (equal (apropos-format-plist foo ", ")
                   "a 1, b (2 3), c nil"))
    (should (equal (apropos-format-plist foo ", " t)
                   "b (2 3)"))
    (apropos-parse-pattern '("d"))
    (should-not (apropos-format-plist foo ", " t))))

(provide 'apropos-tests)
;;; apropos-tests.el ends here

debug log:

solving 917c08b911 ...
found 917c08b911 in https://git.savannah.gnu.org/cgit/emacs.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).