diff options
Diffstat (limited to 'test/automated/xref-tests.el')
| -rw-r--r-- | test/automated/xref-tests.el | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/test/automated/xref-tests.el b/test/automated/xref-tests.el new file mode 100644 index 00000000000..079b196aa8b --- /dev/null +++ b/test/automated/xref-tests.el | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | ;;; xref-tests.el --- tests for xref | ||
| 2 | |||
| 3 | ;; Copyright (C) 2016 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Dmitry Gutov <dgutov@yandex.ru> | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 12 | ;; (at your option) any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | |||
| 24 | ;;; Code: | ||
| 25 | |||
| 26 | (require 'xref) | ||
| 27 | (require 'cl-lib) | ||
| 28 | |||
| 29 | (defvar xref-tests-data-dir | ||
| 30 | (expand-file-name "data/xref/" | ||
| 31 | (file-name-directory (or load-file-name (buffer-file-name))))) | ||
| 32 | |||
| 33 | (ert-deftest xref-collect-matches-finds-none-for-some-regexp () | ||
| 34 | (should (null (xref-collect-matches "zzz" "*" xref-tests-data-dir nil)))) | ||
| 35 | |||
| 36 | (ert-deftest xref-collect-matches-finds-some-for-bar () | ||
| 37 | (let* ((matches (xref-collect-matches "bar" "*" xref-tests-data-dir nil)) | ||
| 38 | (locs (cl-sort (mapcar #'xref-item-location matches) | ||
| 39 | #'string< | ||
| 40 | :key #'xref-location-group))) | ||
| 41 | (should (= 2 (length matches))) | ||
| 42 | (should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 0 locs)))) | ||
| 43 | (should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 1 locs)))))) | ||
| 44 | |||
| 45 | (ert-deftest xref-collect-matches-finds-two-matches-on-the-same-line () | ||
| 46 | (let* ((matches (xref-collect-matches "foo" "*" xref-tests-data-dir nil)) | ||
| 47 | (locs (mapcar #'xref-item-location matches))) | ||
| 48 | (should (= 2 (length matches))) | ||
| 49 | (should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 0 locs)))) | ||
| 50 | (should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 1 locs)))) | ||
| 51 | (should (equal 1 (xref-location-line (nth 0 locs)))) | ||
| 52 | (should (equal 1 (xref-location-line (nth 1 locs)))) | ||
| 53 | (should (equal 0 (xref-file-location-column (nth 0 locs)))) | ||
| 54 | (should (equal 4 (xref-file-location-column (nth 1 locs)))))) | ||
| 55 | |||
| 56 | (ert-deftest xref-collect-matches-finds-an-empty-line-regexp-match () | ||
| 57 | (let* ((matches (xref-collect-matches "^$" "*" xref-tests-data-dir nil)) | ||
| 58 | (locs (mapcar #'xref-item-location matches))) | ||
| 59 | (should (= 1 (length matches))) | ||
| 60 | (should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 0 locs)))) | ||
| 61 | (should (equal 1 (xref-location-line (nth 0 locs)))) | ||
| 62 | (should (equal 0 (xref-file-location-column (nth 0 locs)))))) | ||
| 63 | |||
| 64 | (ert-deftest xref--buf-pairs-iterator-groups-markers-by-buffers-1 () | ||
| 65 | (let* ((xrefs (xref-collect-matches "foo" "*" xref-tests-data-dir nil)) | ||
| 66 | (iter (xref--buf-pairs-iterator xrefs)) | ||
| 67 | (cons (funcall iter :next))) | ||
| 68 | (should (null (funcall iter :next))) | ||
| 69 | (should (string-match "file1\\.txt\\'" (buffer-file-name (car cons)))) | ||
| 70 | (should (= 2 (length (cdr cons)))))) | ||
| 71 | |||
| 72 | (ert-deftest xref--buf-pairs-iterator-groups-markers-by-buffers-2 () | ||
| 73 | (let* ((xrefs (xref-collect-matches "bar" "*" xref-tests-data-dir nil)) | ||
| 74 | (iter (xref--buf-pairs-iterator xrefs)) | ||
| 75 | (cons1 (funcall iter :next)) | ||
| 76 | (cons2 (funcall iter :next))) | ||
| 77 | (should (null (funcall iter :next))) | ||
| 78 | (should-not (equal (car cons1) (car cons2))) | ||
| 79 | (should (= 1 (length (cdr cons1)))) | ||
| 80 | (should (= 1 (length (cdr cons2)))))) | ||
| 81 | |||
| 82 | (ert-deftest xref--buf-pairs-iterator-cleans-up-markers () | ||
| 83 | (let* ((xrefs (xref-collect-matches "bar" "*" xref-tests-data-dir nil)) | ||
| 84 | (iter (xref--buf-pairs-iterator xrefs)) | ||
| 85 | (cons1 (funcall iter :next)) | ||
| 86 | (cons2 (funcall iter :next))) | ||
| 87 | (funcall iter :cleanup) | ||
| 88 | (should (null (marker-position (car (nth 0 (cdr cons1)))))) | ||
| 89 | (should (null (marker-position (cdr (nth 0 (cdr cons1)))))) | ||
| 90 | (should (null (marker-position (car (nth 0 (cdr cons2)))))) | ||
| 91 | (should (null (marker-position (cdr (nth 0 (cdr cons2)))))))) | ||