[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master a758e6a 051/135: Added tests for finders
From: |
Ian Dunn |
Subject: |
[elpa] master a758e6a 051/135: Added tests for finders |
Date: |
Mon, 17 Feb 2020 10:52:51 -0500 (EST) |
branch: master
commit a758e6a873830fa908394b78977ac0439c9c3eeb
Author: Ian D <address@hidden>
Commit: Ian D <address@hidden>
Added tests for finders
* org-edna.el (org-edna-finder/siblings): Fixed case where current headline
is
the first sibling.
(org-edna-finder/siblings-wrap): Wrap movements in save-excursion to allow
returning to original headline.
* org-edna-tests.el, org-edna-tests.org: Tests for the rest of the finders.
---
org-edna-tests.el | 145 +++++++++++++++++++++++++++++++++++++++++++++++++----
org-edna-tests.org | 16 ++++++
org-edna.el | 17 ++++---
3 files changed, 160 insertions(+), 18 deletions(-)
diff --git a/org-edna-tests.el b/org-edna-tests.el
index 14c0caa..46f5f49 100644
--- a/org-edna-tests.el
+++ b/org-edna-tests.el
@@ -28,6 +28,27 @@
(require 'org-edna)
(require 'ert)
+(defconst org-edna-test-dir
+ (expand-file-name (file-name-directory (or load-file-name
buffer-file-name))))
+
+(defconst org-edna-test-file
+ (expand-file-name "org-edna-tests.org" org-edna-test-dir))
+
+;; Jan 15, 2000; chosen at random
+(defconst org-edna-test-time
+ (encode-time 0 0 0 15 1 2000))
+
+(defconst org-edna-test-sibling-one-id
"82a4ac3d-9565-4f94-bc84-2bbfd8d7d96c")
+(defconst org-edna-test-sibling-two-id
"72534efa-e932-460b-ae2d-f044a0074815")
+(defconst org-edna-test-sibling-three-id
"06aca55e-ce09-46df-80d7-5b52e55d6505")
+(defconst org-edna-test-parent-id
"21b8f1f5-14e8-4677-873d-69e0389fdc9e")
+
+(defun org-edna-find-test-heading (id)
+ "Find the test heading with id ID."
+ (with-current-buffer (find-file-noselect org-edna-test-file)
+ (goto-char (org-find-entry-with-id id))
+ (point-marker)))
+
(ert-deftest org-edna-parse-form-no-arguments ()
(let* ((input-string "test-string")
(parsed (org-edna-parse-form input-string)))
@@ -102,16 +123,6 @@
(should (not modifier1))
(should (= pos1 (length input-string))))))
-(defconst org-edna-test-dir
- (expand-file-name (file-name-directory (or load-file-name
buffer-file-name))))
-
-(defconst org-edna-test-file
- (expand-file-name "org-edna-tests.org" org-edna-test-dir))
-
-;; Jan 15, 2000; chosen at random
-(defconst org-edna-test-time
- (encode-time 0 0 0 15 1 2000))
-
;; Finders
@@ -155,6 +166,118 @@
(should (string-equal (substring-no-properties org-block-entry-blocking)
"TODO Tagged Heading 1 :1:test:"))))
+(ert-deftest org-edna-finder/file ()
+ (let* ((targets (org-edna-finder/file org-edna-test-file)))
+ (should (= (length targets) 1))
+ (should (markerp (nth 0 targets)))
+ (org-with-point-at (nth 0 targets)
+ (should (equal (current-buffer) (find-buffer-visiting
org-edna-test-file)))
+ (should (equal (point) 1)))))
+
+(ert-deftest org-edna-finder/org-file ()
+ (let* ((org-directory (file-name-directory org-edna-test-file))
+ (targets (org-edna-finder/org-file (file-name-nondirectory
org-edna-test-file))))
+ (should (= (length targets) 1))
+ (should (markerp (nth 0 targets)))
+ (org-with-point-at (nth 0 targets)
+ (should (equal (current-buffer) (find-buffer-visiting
org-edna-test-file)))
+ (should (equal (point) 1)))))
+
+(ert-deftest org-edna-finder/self ()
+ (let* ((org-agenda-files `(,org-edna-test-file))
+ (current (org-id-find "82a4ac3d-9565-4f94-bc84-2bbfd8d7d96c" t))
+ (targets (org-with-point-at current (org-edna-finder/self))))
+ (should (= (length targets) 1))
+ (should (equal current (nth 0 targets)))))
+
+(ert-deftest org-edna-finder/siblings ()
+ (let* ((org-agenda-files `(,org-edna-test-file))
+ (current (org-id-find "82a4ac3d-9565-4f94-bc84-2bbfd8d7d96c" t))
+ (siblings (mapcar
+ (lambda (uuid) (org-id-find uuid t))
+ '("72534efa-e932-460b-ae2d-f044a0074815"
+ "06aca55e-ce09-46df-80d7-5b52e55d6505")))
+ (targets (org-with-point-at current
+ (org-edna-finder/siblings))))
+ (should (= (length targets) 2))
+ (should (equal siblings targets))))
+
+(ert-deftest org-edna-finder/siblings-wrap ()
+ (let* ((org-agenda-files `(,org-edna-test-file))
+ (current (org-id-find "72534efa-e932-460b-ae2d-f044a0074815" t))
+ (siblings (mapcar
+ (lambda (uuid) (org-id-find uuid t))
+ '("06aca55e-ce09-46df-80d7-5b52e55d6505"
+ "82a4ac3d-9565-4f94-bc84-2bbfd8d7d96c")))
+ (targets (org-with-point-at current
+ (org-edna-finder/siblings-wrap))))
+ (should (= (length targets) 2))
+ (should (equal siblings targets))))
+
+(ert-deftest org-edna-finder/rest-of-siblings ()
+ (let* ((org-agenda-files `(,org-edna-test-file))
+ (current (org-id-find "72534efa-e932-460b-ae2d-f044a0074815" t))
+ (siblings (mapcar
+ (lambda (uuid) (org-id-find uuid t))
+ '("06aca55e-ce09-46df-80d7-5b52e55d6505")))
+ (targets (org-with-point-at current
+ (org-edna-finder/rest-of-siblings))))
+ (should (= (length targets) 1))
+ (should (equal siblings targets))))
+
+(ert-deftest org-edna-finder/next-sibling ()
+ (let* ((org-agenda-files `(,org-edna-test-file))
+ (current (org-id-find "72534efa-e932-460b-ae2d-f044a0074815" t))
+ (siblings (mapcar
+ (lambda (uuid) (org-id-find uuid t))
+ '("06aca55e-ce09-46df-80d7-5b52e55d6505")))
+ (targets (org-with-point-at current
+ (org-edna-finder/next-sibling))))
+ (should (= (length targets) 1))
+ (should (equal siblings targets))))
+
+(ert-deftest org-edna-finder/previous-sibling ()
+ (let* ((org-agenda-files `(,org-edna-test-file))
+ (current (org-id-find "06aca55e-ce09-46df-80d7-5b52e55d6505" t))
+ (siblings (mapcar
+ (lambda (uuid) (org-id-find uuid t))
+ '("72534efa-e932-460b-ae2d-f044a0074815")))
+ (targets (org-with-point-at current
+ (org-edna-finder/previous-sibling))))
+ (should (= (length targets) 1))
+ (should (equal siblings targets))))
+
+(ert-deftest org-edna-finder/first-child ()
+ (let* ((org-agenda-files `(,org-edna-test-file))
+ (current (org-id-find org-edna-test-parent-id t))
+ (first-child (list (org-id-find org-edna-test-sibling-one-id t)))
+ (targets (org-with-point-at current
+ (org-edna-finder/first-child))))
+ (should (= (length targets) 1))
+ (should (equal first-child targets))))
+
+(ert-deftest org-edna-finder/children ()
+ (let* ((org-agenda-files `(,org-edna-test-file))
+ (current (org-id-find org-edna-test-parent-id t))
+ (children (mapcar
+ (lambda (uuid) (org-id-find uuid t))
+ `(,org-edna-test-sibling-one-id
+ ,org-edna-test-sibling-two-id
+ ,org-edna-test-sibling-three-id)))
+ (targets (org-with-point-at current
+ (org-edna-finder/children))))
+ (should (= (length targets) 3))
+ (should (equal children targets))))
+
+(ert-deftest org-edna-finder/parent ()
+ (let* ((org-agenda-files `(,org-edna-test-file))
+ (current (org-id-find org-edna-test-sibling-one-id t))
+ (parent (list (org-id-find org-edna-test-parent-id t)))
+ (targets (org-with-point-at current
+ (org-edna-finder/parent))))
+ (should (= (length targets) 1))
+ (should (equal parent targets))))
+
;; Actions
@@ -196,7 +319,7 @@
(pairs '((cp . rm) (copy . remove) ("cp" . "rm") ("copy" .
"remove"))))
(org-with-point-at target
(dolist (pair pairs)
- (message "Pair: %s" pair)
+ ;; (message "Pair: %s" pair)
(org-edna-action/scheduled source (car pair))
(should (string-equal (org-entry-get nil "SCHEDULED")
"<2000-01-15 Sat 00:00>"))
diff --git a/org-edna-tests.org b/org-edna-tests.org
index 666ec1e..f44702f 100644
--- a/org-edna-tests.org
+++ b/org-edna-tests.org
@@ -44,6 +44,22 @@ SCHEDULED: <2017-01-01 Sun>
:PROPERTIES:
:ID: 5594d4f1-b1bb-400f-9f3d-e2f9b43e82c3
:END:
+** Sibling Headings
+:PROPERTIES:
+:ID: 21b8f1f5-14e8-4677-873d-69e0389fdc9e
+:END:
+*** Sibling 1
+:PROPERTIES:
+:ID: 82a4ac3d-9565-4f94-bc84-2bbfd8d7d96c
+:END:
+*** Sibling 2
+:PROPERTIES:
+:ID: 72534efa-e932-460b-ae2d-f044a0074815
+:END:
+*** Sibling 3
+:PROPERTIES:
+:ID: 06aca55e-ce09-46df-80d7-5b52e55d6505
+:END:
* Finder Tests
** Match
*** TODO Blocking Test
diff --git a/org-edna.el b/org-edna.el
index da8747a..cd83eb7 100644
--- a/org-edna.el
+++ b/org-edna.el
@@ -266,7 +266,8 @@ IDS are all UUIDs as understood by `org-id-find'."
(markers))
(org-up-heading-safe)
(org-goto-first-child)
- (push (point-marker) markers)
+ (unless (equal (point) self)
+ (push (point-marker) markers))
(while (org-get-next-sibling)
(unless (equal (point) self)
(push (point-marker) markers)))
@@ -277,15 +278,17 @@ IDS are all UUIDs as understood by `org-id-find'."
(let ((self (and (ignore-errors (org-back-to-heading t)) (point)))
(markers))
;; Go from this heading to the end
- (while (org-get-next-sibling)
- (unless (equal (point) self)
- (push (point-marker) markers)))
+ (save-excursion
+ (while (org-get-next-sibling)
+ (unless (equal (point) self)
+ (push (point-marker) markers))))
;; Go to the first heading
(org-up-heading-safe)
(org-goto-first-child)
- (while (not (equal (point) self))
- (push (point-marker) markers)
- (org-get-next-sibling))
+ (save-excursion
+ (while (not (equal (point) self))
+ (push (point-marker) markers)
+ (org-get-next-sibling)))
(nreverse markers))))
(defun org-edna-finder/rest-of-siblings ()
- [elpa] master 7a3332d 032/135: Fixed error in re-search, (continued)
- [elpa] master 7a3332d 032/135: Fixed error in re-search, Ian Dunn, 2020/02/17
- [elpa] master 6470c5f 033/135: Added test for todo action, Ian Dunn, 2020/02/17
- [elpa] master db23e3f 034/135: Added some more test headings, Ian Dunn, 2020/02/17
- [elpa] master aa259f0 037/135: Fix considerations, Ian Dunn, 2020/02/17
- [elpa] master f80835a 038/135: Added tests for considerations, Ian Dunn, 2020/02/17
- [elpa] master 729a391 040/135: Added copyright and licensing information to all files, Ian Dunn, 2020/02/17
- [elpa] master 7379c4f 043/135: Added copyright date to source files, Ian Dunn, 2020/02/17
- [elpa] master 8a21978 042/135: Fixed copyright notices, Ian Dunn, 2020/02/17
- [elpa] master 11aaa52 053/135: Added Savannah project link to documentation, Ian Dunn, 2020/02/17
- [elpa] master 34e4d86 054/135: Fixed variable-set condition, Ian Dunn, 2020/02/17
- [elpa] master a758e6a 051/135: Added tests for finders,
Ian Dunn <=
- [elpa] master 3f4595b 052/135: Finished rough draft of documentation, Ian Dunn, 2020/02/17
- [elpa] master 329b39e 058/135: Added installation and setup instructions to documentation, Ian Dunn, 2020/02/17
- [elpa] master e793f3c 047/135: Fixed bugs from last commit, Ian Dunn, 2020/02/17
- [elpa] master c29a951 045/135: Use example instead of src to make HTML export prettier, Ian Dunn, 2020/02/17
- [elpa] master 5b1c81a 049/135: Fixed error in last commit, Ian Dunn, 2020/02/17
- [elpa] master 99939aa 048/135: Handle all errors in Edna forms, Ian Dunn, 2020/02/17
- [elpa] master d07a8d8 035/135: Added note about quoting file names to documentation., Ian Dunn, 2020/02/17
- [elpa] master bb3c739 044/135: Fixed license blocks in elisp files, Ian Dunn, 2020/02/17
- [elpa] master 3a3ed39 046/135: Various parsing fixes, Ian Dunn, 2020/02/17
- [elpa] master eda515d 039/135: Added check and local settings to Makefile, Ian Dunn, 2020/02/17