summaryrefslogtreecommitdiff
path: root/test/lisp/progmodes/xref-tests.el
diff options
context:
space:
mode:
authorTobias Rittweiler <trittweiler@gmail.com>2020-12-08 09:59:15 +0100
committerDmitry Gutov <dgutov@yandex.ru>2020-12-30 04:10:08 +0200
commitfdb725c3847feeccb7396519eea1758428370107 (patch)
treeb881e68ff31d3ebe2c67c30cfb5428b656df52d8 /test/lisp/progmodes/xref-tests.el
parent90bd3b3d69d40339127b4744c459cedb7eb962b0 (diff)
downloademacs-fdb725c3847feeccb7396519eea1758428370107.tar.gz
emacs-fdb725c3847feeccb7396519eea1758428370107.tar.bz2
emacs-fdb725c3847feeccb7396519eea1758428370107.zip
Minor refactoring of xref-tests
* test/lisp/progmodes/xref-tests.el (xref-tests-data-dir): Rename to 'xref-tests--data-dir'. (xref-tests--matches-in-data-dir, xref-tests--locations-in-data-dir): New functions. Factored out from test cases and updated usage sites to use them.
Diffstat (limited to 'test/lisp/progmodes/xref-tests.el')
-rw-r--r--test/lisp/progmodes/xref-tests.el38
1 files changed, 22 insertions, 16 deletions
diff --git a/test/lisp/progmodes/xref-tests.el b/test/lisp/progmodes/xref-tests.el
index e220d09dada..e1efbe8a4eb 100644
--- a/test/lisp/progmodes/xref-tests.el
+++ b/test/lisp/progmodes/xref-tests.el
@@ -27,27 +27,34 @@
(require 'xref)
(require 'cl-lib)
-(defvar xref-tests-data-dir
+(defvar xref-tests--data-dir
(expand-file-name "xref-resources/"
(file-name-directory
(or load-file-name buffer-file-name))))
+(defun xref-tests--matches-in-data-dir (regexp &optional files)
+ (xref-matches-in-directory regexp (or files "*") xref-tests--data-dir nil))
+
+(defun xref-tests--locations-in-data-dir (regexp &optional files)
+ (let ((matches (xref-tests--matches-in-data-dir regexp files)))
+ ;; Sort in order to guarantee an order independent from the
+ ;; filesystem traversal.
+ (cl-sort (mapcar #'xref-item-location matches)
+ #'string<
+ :key #'xref-location-group)))
+
(ert-deftest xref-matches-in-directory-finds-none-for-some-regexp ()
- (should (null (xref-matches-in-directory "zzz" "*" xref-tests-data-dir nil))))
+ (should (null (xref-tests--matches-in-data-dir "zzz"))))
(ert-deftest xref-matches-in-directory-finds-some-for-bar ()
- (let* ((matches (xref-matches-in-directory "bar" "*" xref-tests-data-dir nil))
- (locs (cl-sort (mapcar #'xref-item-location matches)
- #'string<
- :key #'xref-location-group)))
- (should (= 2 (length matches)))
+ (let ((locs (xref-tests--locations-in-data-dir "bar")))
+ (should (= 2 (length locs)))
(should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 0 locs))))
(should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 1 locs))))))
(ert-deftest xref-matches-in-directory-finds-two-matches-on-the-same-line ()
- (let* ((matches (xref-matches-in-directory "foo" "*" xref-tests-data-dir nil))
- (locs (mapcar #'xref-item-location matches)))
- (should (= 2 (length matches)))
+ (let ((locs (xref-tests--locations-in-data-dir "foo")))
+ (should (= 2 (length locs)))
(should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 0 locs))))
(should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 1 locs))))
(should (equal 1 (xref-location-line (nth 0 locs))))
@@ -56,15 +63,14 @@
(should (equal 4 (xref-location-column (nth 1 locs))))))
(ert-deftest xref-matches-in-directory-finds-an-empty-line-regexp-match ()
- (let* ((matches (xref-matches-in-directory "^$" "*" xref-tests-data-dir nil))
- (locs (mapcar #'xref-item-location matches)))
- (should (= 1 (length matches)))
+ (let ((locs (xref-tests--locations-in-data-dir "^$")))
+ (should (= 1 (length locs)))
(should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 0 locs))))
(should (equal 1 (xref-location-line (nth 0 locs))))
(should (equal 0 (xref-location-column (nth 0 locs))))))
(ert-deftest xref--buf-pairs-iterator-groups-markers-by-buffers-1 ()
- (let* ((xrefs (xref-matches-in-directory "foo" "*" xref-tests-data-dir nil))
+ (let* ((xrefs (xref-tests--matches-in-data-dir "foo"))
(iter (xref--buf-pairs-iterator xrefs))
(cons (funcall iter :next)))
(should (null (funcall iter :next)))
@@ -72,7 +78,7 @@
(should (= 2 (length (cdr cons))))))
(ert-deftest xref--buf-pairs-iterator-groups-markers-by-buffers-2 ()
- (let* ((xrefs (xref-matches-in-directory "bar" "*" xref-tests-data-dir nil))
+ (let* ((xrefs (xref-tests--matches-in-data-dir "bar"))
(iter (xref--buf-pairs-iterator xrefs))
(cons1 (funcall iter :next))
(cons2 (funcall iter :next)))
@@ -82,7 +88,7 @@
(should (= 1 (length (cdr cons2))))))
(ert-deftest xref--buf-pairs-iterator-cleans-up-markers ()
- (let* ((xrefs (xref-matches-in-directory "bar" "*" xref-tests-data-dir nil))
+ (let* ((xrefs (xref-tests--matches-in-data-dir "bar"))
(iter (xref--buf-pairs-iterator xrefs))
(cons1 (funcall iter :next))
(cons2 (funcall iter :next)))