Commit | Line | Data |
---|---|---|
1398a54d MY |
1 | ;;; imenu-tests.el --- Test suite for imenu. |
2 | ||
ba318903 | 3 | ;; Copyright (C) 2013-2014 Free Software Foundation, Inc. |
1398a54d MY |
4 | |
5 | ;; Author: Masatake YAMATO <yamato@redhat.com> | |
6 | ;; Keywords: tools convenience | |
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 <http://www.gnu.org/licenses/>. | |
22 | ||
23 | ;;; Code: | |
24 | ||
771b2fc3 | 25 | (require 'ert) |
1398a54d MY |
26 | (require 'imenu) |
27 | ||
28 | ;; (imenu-simple-scan-deftest-gather-strings-from-list | |
29 | ;; '(nil t 'a (0 . "x") ("c" . "d") ("a" 0 "b") )) | |
30 | ;; => ("b" "a" "d" "c" "x") | |
31 | (defun imenu-simple-scan-deftest-gather-strings-from-list(input) | |
32 | "Gather strings from INPUT, a list." | |
33 | (let ((result ())) | |
34 | (while input | |
35 | (cond | |
36 | ((stringp input) | |
37 | (setq result (cons input result) | |
38 | input nil)) | |
39 | ((atom input) | |
40 | (setq input nil)) | |
41 | ((listp (car input)) | |
42 | (setq result (append | |
43 | (imenu-simple-scan-deftest-gather-strings-from-list (car input)) | |
44 | result) | |
45 | input (cdr input))) | |
46 | ((stringp (car input)) | |
47 | (setq result (cons (car input) result) | |
48 | input (cdr input))) | |
49 | (t | |
50 | (setq input (cdr input))))) | |
51 | result)) | |
52 | ||
53 | (defmacro imenu-simple-scan-deftest (name doc major-mode content expected-items) | |
54 | "Generate an ert test for mode-own imenu expression. | |
55 | Run `imenu-create-index-function' at the buffer which content is | |
56 | CONTENT with MAJOR-MODE. A generated test runs `imenu-create-index-function' | |
57 | at the buffer which content is CONTENT with MAJOR-MODE. Then it compares a list | |
58 | of strings which are picked up from the result with EXPECTED-ITEMS." | |
59 | (let ((xname (intern (concat "imenu-simple-scan-deftest-" (symbol-name name))))) | |
60 | `(ert-deftest ,xname () | |
61 | ,doc | |
62 | (with-temp-buffer | |
63 | (insert ,content) | |
64 | (funcall ',major-mode) | |
65 | (let ((result-items (sort (imenu-simple-scan-deftest-gather-strings-from-list | |
66 | (funcall imenu-create-index-function)) | |
67 | #'string-lessp)) | |
68 | (expected-items (sort (copy-sequence ,expected-items) #'string-lessp))) | |
69 | (should (equal result-items expected-items)) | |
70 | ))))) | |
71 | ||
72 | (imenu-simple-scan-deftest sh "Test imenu expression for sh-mode." sh-mode "a() | |
73 | { | |
74 | } | |
75 | function b | |
76 | { | |
77 | } | |
78 | function c() | |
79 | { | |
80 | } | |
81 | function ABC_D() | |
82 | { | |
83 | } | |
84 | " '("a" "b" "c" "ABC_D")) | |
85 | ||
86 | (provide 'imenu-tests) | |
87 | ||
88 | ;;; imenu-tests.el ends here |