4 (defvar xref-tests-data-dir
5 (expand-file-name "data/xref/"
6 (file-name-directory (or load-file-name
(buffer-file-name)))))
8 (ert-deftest xref-collect-matches-finds-none-for-some-regexp
()
9 (should (null (xref-collect-matches "zzz" "*" xref-tests-data-dir nil
))))
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
)
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
))))))
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
))))))
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
))))))