]> code.delx.au - gnu-emacs/blob - test/automated/xref-tests.el
Handle "empty line" regexp in xref searches
[gnu-emacs] / test / automated / xref-tests.el
1 (require 'xref)
2 (require 'cl-lib)
3
4 (defvar xref-tests-data-dir
5 (expand-file-name "data/xref/"
6 (file-name-directory (or load-file-name (buffer-file-name)))))
7
8 (ert-deftest xref-collect-matches-finds-none-for-some-regexp ()
9 (should (null (xref-collect-matches "zzz" "*" xref-tests-data-dir nil))))
10
11 (ert-deftest xref-collect-matches-finds-some-for-bar ()
12 (let* ((matches (xref-collect-matches "bar" "*" xref-tests-data-dir nil))
13 (locs (cl-sort (mapcar #'xref-item-location matches)
14 #'string<
15 :key #'xref-location-group)))
16 (should (= 2 (length matches)))
17 (should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 0 locs))))
18 (should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 1 locs))))))
19
20 (ert-deftest xref-collect-matches-finds-two-matches-on-the-same-line ()
21 (let* ((matches (xref-collect-matches "foo" "*" xref-tests-data-dir nil))
22 (locs (mapcar #'xref-item-location matches)))
23 (should (= 2 (length matches)))
24 (should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 0 locs))))
25 (should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 1 locs))))
26 (should (equal 1 (xref-location-line (nth 0 locs))))
27 (should (equal 1 (xref-location-line (nth 1 locs))))
28 (should (equal 0 (xref-file-location-column (nth 0 locs))))
29 (should (equal 4 (xref-file-location-column (nth 1 locs))))))
30
31 (ert-deftest xref-collect-matches-finds-an-empty-line-regexp-match ()
32 (let* ((matches (xref-collect-matches "^$" "*" xref-tests-data-dir nil))
33 (locs (mapcar #'xref-item-location matches)))
34 (should (= 1 (length matches)))
35 (should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 0 locs))))
36 (should (equal 1 (xref-location-line (nth 0 locs))))
37 (should (equal 0 (xref-file-location-column (nth 0 locs))))))