aboutsummaryrefslogtreecommitdiffstats
path: root/test/automated
diff options
context:
space:
mode:
authorPaul Eggert2016-05-05 23:11:11 -0700
committerPaul Eggert2016-05-05 23:11:11 -0700
commit89ce83b20249dfb4e45f09dfdddf4c4b66d82968 (patch)
tree3d75245a5514df2ad7b17ae6d56727b9629846a9 /test/automated
parentd546ed13b04521308ef7ec8e7e5b68e03f1bbb38 (diff)
parent50650cb6887d99b01eeb1e686fc1f695c2a0c64a (diff)
downloademacs-89ce83b20249dfb4e45f09dfdddf4c4b66d82968.tar.gz
emacs-89ce83b20249dfb4e45f09dfdddf4c4b66d82968.zip
Merge from origin/emacs-25
50650cb Doc fixes for fclist and grep 5e814e0 Minor doc fixes for quoting 3347a73 `nreverse' the marker pairs list 1a4127d Use save-excursion in xref-location-marker more ab3ba91 shell-quote-argument DIR when appropriate 922c7a3 Rework xref-query-replace-in-results 3fe3510 * lisp/replace.el (query-replace-read-from): Use minibuffer-w... 0932b94 Fix todo-mode bug involving archived items (bug#23447) e68ad1f ; * etc/NEWS: Tiny edit. (Bug#23432) adc80b7 ; * test/automated/xref-tests.el: Add copyright and license. 4d8fd9c Handle "empty line" regexp in xref searches f559b37 Add tests for xref-collect-matches 6428aa0 Use grep-find-ignored-directories instead of vc-directory-exc... 6f82d8e Clear buffer-undo-list when showing xrefs c68a091 Note the quote translation in `message' in section "incompati... 52f86a7 * etc/NEWS: Mention (message "%s" (format ...)). 93703c5 (Common Keywords): Correct what missing :group means 79e5800 Improve documentation of Dired's 'A' and 'Q' commands 2ea2a2f Doc fixes for quoting 8544b98 posnp doc clarification 805204f Mention what a missing :group does ec554d7 Fix documentation of dired-aux search/replace commands
Diffstat (limited to 'test/automated')
-rw-r--r--test/automated/data/xref/file1.txt2
-rw-r--r--test/automated/data/xref/file2.txt2
-rw-r--r--test/automated/xref-tests.el91
3 files changed, 95 insertions, 0 deletions
diff --git a/test/automated/data/xref/file1.txt b/test/automated/data/xref/file1.txt
new file mode 100644
index 00000000000..5d7cc544443
--- /dev/null
+++ b/test/automated/data/xref/file1.txt
@@ -0,0 +1,2 @@
1foo foo
2bar
diff --git a/test/automated/data/xref/file2.txt b/test/automated/data/xref/file2.txt
new file mode 100644
index 00000000000..9f075f26004
--- /dev/null
+++ b/test/automated/data/xref/file2.txt
@@ -0,0 +1,2 @@
1
2bar
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))))))))