[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/org-edna 69ecfe4 57/72: Added tests for conditions
From: |
Ian Dunn |
Subject: |
[elpa] scratch/org-edna 69ecfe4 57/72: Added tests for conditions |
Date: |
Sun, 21 May 2017 21:11:28 -0400 (EDT) |
branch: scratch/org-edna
commit 69ecfe4e63b15cb9eb5d77137b757474a63c7b87
Author: Ian D <address@hidden>
Commit: Ian D <address@hidden>
Added tests for conditions
* org-edna.el (org-edna-condition/variable-set?): Fixed handling of NEG.
(org-edna-condition/re-search?): Same.
* org-edna-tests.el: Added tests for conditions.
* org-edna-tests.org: Added ID Heading 4
---
org-edna-tests.el | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
org-edna-tests.org | 4 +++
org-edna.el | 4 +--
3 files changed, 97 insertions(+), 5 deletions(-)
diff --git a/org-edna-tests.el b/org-edna-tests.el
index 651f31c..4698e52 100644
--- a/org-edna-tests.el
+++ b/org-edna-tests.el
@@ -34,6 +34,9 @@
(defconst org-edna-test-file
(expand-file-name "org-edna-tests.org" org-edna-test-dir))
+(defconst org-edna-tests-el
+ (expand-file-name "org-edna-tests.el" org-edna-test-dir))
+
;; Jan 15, 2000; chosen at random
(defconst org-edna-test-time
(encode-time 0 0 0 15 1 2000))
@@ -42,12 +45,14 @@
(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")
+(defconst org-edna-test-id-heading-one
"0d491588-7da3-43c5-b51a-87fbd34f79f7")
+(defconst org-edna-test-id-heading-two
"b010cbad-60dc-46ef-a164-eb155e62cbb2")
+(defconst org-edna-test-id-heading-three
"97e6b0f0-40c4-464f-b760-6e5ca9744eb5")
+(defconst org-edna-test-id-heading-four
"7d4d564b-18b2-445c-a0c8-b1b3fb9ad29e")
(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)))
+ (org-id-find-id-in-file id org-edna-test-file t))
(ert-deftest org-edna-parse-form-no-arguments ()
(let* ((input-string "test-string")
@@ -364,6 +369,89 @@
;; Conditions
+(defun org-edna-test-condition-form (func-sym pom-true pom-false block-true
block-false &rest args)
+ (org-with-point-at pom-true
+ (should-not (apply func-sym t args))
+ (should (equal (apply func-sym nil args) block-true)))
+ (org-with-point-at pom-false
+ (should (equal (apply func-sym t args) block-false))
+ (should-not (apply func-sym nil args))))
+
+(ert-deftest org-edna-condition-done ()
+ (let* ((pom-done (org-edna-find-test-heading org-edna-test-id-heading-four))
+ (pom-todo (org-edna-find-test-heading org-edna-test-id-heading-one))
+ (block-done (org-with-point-at pom-done (org-get-heading)))
+ (block-todo (org-with-point-at pom-todo (org-get-heading))))
+ (org-edna-test-condition-form 'org-edna-condition/done?
+ pom-done pom-todo
+ block-done block-todo)))
+
+(ert-deftest org-edna-condition-todo-state-string ()
+ (let* ((pom-done (org-edna-find-test-heading org-edna-test-id-heading-four))
+ (pom-todo (org-edna-find-test-heading org-edna-test-id-heading-one))
+ (block-done (org-with-point-at pom-done (org-get-heading)))
+ (block-todo (org-with-point-at pom-todo (org-get-heading))))
+ (org-edna-test-condition-form 'org-edna-condition/todo-state?
+ pom-todo pom-done
+ block-todo block-done
+ "TODO")))
+
+(ert-deftest org-edna-condition-todo-state-symbol ()
+ (let* ((pom-done (org-edna-find-test-heading org-edna-test-id-heading-four))
+ (pom-todo (org-edna-find-test-heading org-edna-test-id-heading-one))
+ (block-done (org-with-point-at pom-done (org-get-heading)))
+ (block-todo (org-with-point-at pom-todo (org-get-heading))))
+ (org-edna-test-condition-form 'org-edna-condition/todo-state?
+ pom-todo pom-done
+ block-todo block-done
+ 'TODO)))
+
+(ert-deftest org-edna-condition-headings ()
+ (pcase-let* ((`(,pom-headings ,block-headings)
+ (with-current-buffer (find-file-noselect org-edna-test-file)
+ (list (point-min-marker) (buffer-name))))
+ (`(,pom-no-headings ,block-no-headings)
+ (with-current-buffer (find-file-noselect org-edna-tests-el)
+ (list (point-min-marker) (buffer-name)))))
+ (org-edna-test-condition-form 'org-edna-condition/headings?
+ pom-headings pom-no-headings
+ block-headings block-no-headings)))
+
+(ert-deftest org-edna-condition-variable-set ()
+ (let* ((temp-var t))
+ (should-not (org-edna-condition/variable-set? t 'temp-var t))
+ (should (equal (org-edna-condition/variable-set? nil 'temp-var t)
+ "temp-var == t"))
+ (should (equal (org-edna-condition/variable-set? t 'temp-var nil)
+ "temp-var != nil"))
+ (should-not (org-edna-condition/variable-set? nil 'temp-var nil))))
+
+(ert-deftest org-edna-condition-has-property ()
+ (let* ((pom-true (org-edna-find-test-heading org-edna-test-id-heading-four))
+ (pom-false (org-edna-find-test-heading org-edna-test-id-heading-one))
+ (block-true (org-with-point-at pom-true (org-get-heading)))
+ (block-false (org-with-point-at pom-false (org-get-heading))))
+ (org-edna-test-condition-form 'org-edna-condition/has-property?
+ pom-true pom-false
+ block-true block-false
+ "ID" org-edna-test-id-heading-four)))
+
+(ert-deftest org-edna-condition-re-search ()
+ (pcase-let* ((case-fold-search nil)
+ (string "require")
+ (`(,pom-true ,block-true)
+ (with-current-buffer (find-file-noselect org-edna-tests-el)
+ (list (point-min-marker)
+ (format "Found %s in %s" string (buffer-name)))))
+ (`(,pom-false ,block-false)
+ (with-current-buffer (find-file-noselect org-edna-test-file)
+ (list (point-min-marker)
+ (format "Did Not Find %s in %s" string
(buffer-name))))))
+ (org-edna-test-condition-form 'org-edna-condition/re-search?
+ pom-true pom-false
+ block-true block-false
+ string)))
+
;; Consideration
diff --git a/org-edna-tests.org b/org-edna-tests.org
index f44702f..ca881df 100644
--- a/org-edna-tests.org
+++ b/org-edna-tests.org
@@ -33,6 +33,10 @@ SCHEDULED: <2000-01-15 Sat 00:00>
:PROPERTIES:
:ID: 97e6b0f0-40c4-464f-b760-6e5ca9744eb5
:END:
+** DONE ID Heading 4
+:PROPERTIES:
+:ID: 7d4d564b-18b2-445c-a0c8-b1b3fb9ad29e
+:END:
** Scheduled Headings
*** TODO Scheduled Heading 1
SCHEDULED: <2017-01-01 Sun>
diff --git a/org-edna.el b/org-edna.el
index 634576a..bb99ec4 100644
--- a/org-edna.el
+++ b/org-edna.el
@@ -572,7 +572,7 @@ IDS are all UUIDs as understood by `org-id-find'."
(defun org-edna-condition/variable-set? (neg var val)
(let ((condition (equal (symbol-value var) val)))
(when (org-xor condition neg)
- (format "%s %s= %s" var (or neg "=") val))))
+ (format "%s %s= %s" var (if neg "!" "=") val))))
(defun org-edna-condition/has-property? (neg prop val)
(let ((condition (string-equal (org-entry-get nil prop) val)))
@@ -582,7 +582,7 @@ IDS are all UUIDs as understood by `org-id-find'."
(defun org-edna-condition/re-search? (neg match)
(let ((condition (re-search-forward match nil t)))
(when (org-xor condition neg)
- (format "Found %s in %s" match (buffer-name)))))
+ (format "%s %s in %s" (if neg "Did Not Find" "Found") match
(buffer-name)))))
- [elpa] scratch/org-edna e03fa9c 60/72: Fixed up chain test, (continued)
- [elpa] scratch/org-edna e03fa9c 60/72: Fixed up chain test, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna ad7bdc9 62/72: Fixed actions and documentation, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 96ca42c 65/72: Compile targets before running tests, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 24b323d 52/72: Finished rough draft of documentation, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 7517c15 63/72: Use org source blocks instead of example blocks in documentation, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna ce425a3 71/72: Fixed up documentation, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna c62886d 55/72: Updated to new syntax, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 0444691 49/72: Fixed error in last commit, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 9573539 53/72: Added Savannah project link to documentation, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 406f8ea 67/72: Fixed ancestors example, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 69ecfe4 57/72: Added tests for conditions,
Ian Dunn <=
- [elpa] scratch/org-edna 74dae46 51/72: Added tests for finders, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna f56be02 69/72: Silenced byte-compiler, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 8c31160 59/72: Added tests for actions, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 83663fa 64/72: Cleaned up package header and added various docstrings, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 37e9b58 50/72: Fixed chain-find and planning actions, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna ad0f3ef 66/72: Added in-buffer settings and new sections to Documentation, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 3167ea7 39/72: Added check and local settings to Makefile, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 50652ab 58/72: Added installation and setup instructions to documentation, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 191c938 41/72: Added copyright and licensing information to all files, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 7e1dafb 44/72: Fixed license blocks in elisp files, Ian Dunn, 2017/05/21