summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Gutov <dgutov@yandex.ru>2016-05-04 01:38:02 +0300
committerDmitry Gutov <dgutov@yandex.ru>2016-05-04 01:38:02 +0300
commitf559b374a30f3615261f7a902fc3428cac6289f4 (patch)
treed675d99cd88cce9d078e05e42e5f6f26d7382e9e
parent6428aa044ad872e9b8b60d825b7cbcb38ae3e492 (diff)
downloademacs-f559b374a30f3615261f7a902fc3428cac6289f4.tar.gz
Add tests for xref-collect-matches
* test/automated/xref-tests.el: New file. Add tests for xref-collect-matches.
-rw-r--r--test/automated/data/xref/file1.txt2
-rw-r--r--test/automated/data/xref/file2.txt2
-rw-r--r--test/automated/xref-tests.el37
3 files changed, 41 insertions, 0 deletions
diff --git a/test/automated/data/xref/file1.txt b/test/automated/data/xref/file1.txt
new file mode 100644
index 00000000000..5d7cc544443
--- /dev/null
+++ b/test/automated/data/xref/file1.txt
@@ -0,0 +1,2 @@
+foo foo
+bar
diff --git a/test/automated/data/xref/file2.txt b/test/automated/data/xref/file2.txt
new file mode 100644
index 00000000000..9f075f26004
--- /dev/null
+++ b/test/automated/data/xref/file2.txt
@@ -0,0 +1,2 @@
+
+bar
diff --git a/test/automated/xref-tests.el b/test/automated/xref-tests.el
new file mode 100644
index 00000000000..1b500c3c418
--- /dev/null
+++ b/test/automated/xref-tests.el
@@ -0,0 +1,37 @@
+(require 'xref)
+(require 'cl-lib)
+
+(defvar xref-tests-data-dir
+ (expand-file-name "data/xref/"
+ (file-name-directory (or load-file-name (buffer-file-name)))))
+
+(ert-deftest xref-collect-matches-finds-none-for-some-regexp ()
+ (should (null (xref-collect-matches "zzz" "*" xref-tests-data-dir nil))))
+
+(ert-deftest xref-collect-matches-finds-some-for-bar ()
+ (let* ((matches (xref-collect-matches "bar" "*" xref-tests-data-dir nil))
+ (locs (cl-sort (mapcar #'xref-item-location matches)
+ #'string<
+ :key #'xref-location-group)))
+ (should (= 2 (length matches)))
+ (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-collect-matches-finds-two-matches-on-the-same-line ()
+ (let* ((matches (xref-collect-matches "foo" "*" xref-tests-data-dir nil))
+ (locs (mapcar #'xref-item-location matches)))
+ (should (= 2 (length matches)))
+ (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))))
+ (should (equal 1 (xref-location-line (nth 1 locs))))
+ (should (equal 0 (xref-file-location-column (nth 0 locs))))
+ (should (equal 4 (xref-file-location-column (nth 1 locs))))))
+
+;; (ert-deftest xref-collect-matches-finds-an-empty-line-regexp-match ()
+;; (let* ((matches (xref-collect-matches "^$" "*" xref-tests-data-dir nil))
+;; (locs (mapcar #'xref-item-location matches)))
+;; (should (= 1 (length matches)))
+;; (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-file-location-column (nth 0 locs))))))