diff options
| author | Masatake YAMATO | 2013-04-20 04:02:55 +0900 |
|---|---|---|
| committer | Masatake YAMATO | 2013-04-20 04:02:55 +0900 |
| commit | 1398a54d6abf5b7cab98ec8a1063c155707cdb83 (patch) | |
| tree | 19c822a34ab3005952438fbe23001f18e0a45d25 | |
| parent | 4d3268ba39ffbc885b0238bacdbe61bdf29f526f (diff) | |
| download | emacs-1398a54d6abf5b7cab98ec8a1063c155707cdb83.tar.gz emacs-1398a54d6abf5b7cab98ec8a1063c155707cdb83.zip | |
* automated/imenu-tests.el: New file.
| -rw-r--r-- | test/ChangeLog | 4 | ||||
| -rw-r--r-- | test/automated/imenu-test.el | 87 |
2 files changed, 91 insertions, 0 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 0c240394c5c..3619414c231 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2013-04-01 Masatake YAMATO <yamato@redhat.com> | ||
| 2 | |||
| 3 | * automated/imenu-tests.el: New file. | ||
| 4 | |||
| 1 | 2013-04-19 Fabián Ezequiel Gallina <fgallina@gnu.org> | 5 | 2013-04-19 Fabián Ezequiel Gallina <fgallina@gnu.org> |
| 2 | 6 | ||
| 3 | * automated/python-tests.el (python-imenu-prev-index-position-1): | 7 | * automated/python-tests.el (python-imenu-prev-index-position-1): |
diff --git a/test/automated/imenu-test.el b/test/automated/imenu-test.el new file mode 100644 index 00000000000..83e19ebd914 --- /dev/null +++ b/test/automated/imenu-test.el | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | ;;; imenu-tests.el --- Test suite for imenu. | ||
| 2 | |||
| 3 | ;; Copyright (C) 2013 Free Software Foundation, Inc. | ||
| 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 | |||
| 25 | (require 'imenu) | ||
| 26 | |||
| 27 | ;; (imenu-simple-scan-deftest-gather-strings-from-list | ||
| 28 | ;; '(nil t 'a (0 . "x") ("c" . "d") ("a" 0 "b") )) | ||
| 29 | ;; => ("b" "a" "d" "c" "x") | ||
| 30 | (defun imenu-simple-scan-deftest-gather-strings-from-list(input) | ||
| 31 | "Gather strings from INPUT, a list." | ||
| 32 | (let ((result ())) | ||
| 33 | (while input | ||
| 34 | (cond | ||
| 35 | ((stringp input) | ||
| 36 | (setq result (cons input result) | ||
| 37 | input nil)) | ||
| 38 | ((atom input) | ||
| 39 | (setq input nil)) | ||
| 40 | ((listp (car input)) | ||
| 41 | (setq result (append | ||
| 42 | (imenu-simple-scan-deftest-gather-strings-from-list (car input)) | ||
| 43 | result) | ||
| 44 | input (cdr input))) | ||
| 45 | ((stringp (car input)) | ||
| 46 | (setq result (cons (car input) result) | ||
| 47 | input (cdr input))) | ||
| 48 | (t | ||
| 49 | (setq input (cdr input))))) | ||
| 50 | result)) | ||
| 51 | |||
| 52 | (defmacro imenu-simple-scan-deftest (name doc major-mode content expected-items) | ||
| 53 | "Generate an ert test for mode-own imenu expression. | ||
| 54 | Run `imenu-create-index-function' at the buffer which content is | ||
| 55 | CONTENT with MAJOR-MODE. A generated test runs `imenu-create-index-function' | ||
| 56 | at the buffer which content is CONTENT with MAJOR-MODE. Then it compares a list | ||
| 57 | of strings which are picked up from the result with EXPECTED-ITEMS." | ||
| 58 | (let ((xname (intern (concat "imenu-simple-scan-deftest-" (symbol-name name))))) | ||
| 59 | `(ert-deftest ,xname () | ||
| 60 | ,doc | ||
| 61 | (with-temp-buffer | ||
| 62 | (insert ,content) | ||
| 63 | (funcall ',major-mode) | ||
| 64 | (let ((result-items (sort (imenu-simple-scan-deftest-gather-strings-from-list | ||
| 65 | (funcall imenu-create-index-function)) | ||
| 66 | #'string-lessp)) | ||
| 67 | (expected-items (sort (copy-sequence ,expected-items) #'string-lessp))) | ||
| 68 | (should (equal result-items expected-items)) | ||
| 69 | ))))) | ||
| 70 | |||
| 71 | (imenu-simple-scan-deftest sh "Test imenu expression for sh-mode." sh-mode "a() | ||
| 72 | { | ||
| 73 | } | ||
| 74 | function b | ||
| 75 | { | ||
| 76 | } | ||
| 77 | function c() | ||
| 78 | { | ||
| 79 | } | ||
| 80 | function ABC_D() | ||
| 81 | { | ||
| 82 | } | ||
| 83 | " '("a" "b" "c" "ABC_D")) | ||
| 84 | |||
| 85 | (provide 'imenu-tests) | ||
| 86 | |||
| 87 | ;;; imenu-tests.el ends here | ||