emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master fdb725c: Minor refactoring of xref-tests


From: Dmitry Gutov
Subject: master fdb725c: Minor refactoring of xref-tests
Date: Tue, 29 Dec 2020 21:10:26 -0500 (EST)

branch: master
commit fdb725c3847feeccb7396519eea1758428370107
Author: Tobias Rittweiler <trittweiler@gmail.com>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    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.
---
 test/lisp/progmodes/xref-tests.el | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/test/lisp/progmodes/xref-tests.el 
b/test/lisp/progmodes/xref-tests.el
index e220d09..e1efbe8 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)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]