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.
This commit is contained in:
parent
90bd3b3d69
commit
fdb725c384
1 changed files with 22 additions and 16 deletions
|
@ -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)))
|
||||
|
|
Loading…
Add table
Reference in a new issue