[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 89c2ecf 057/135: Added tests for conditions
From: |
Ian Dunn |
Subject: |
[elpa] master 89c2ecf 057/135: Added tests for conditions |
Date: |
Mon, 17 Feb 2020 10:52:52 -0500 (EST) |
branch: master
commit 89c2ecf633cd28e8bd0c06dddd73a84bd3ed991d
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] master e793f3c 047/135: Fixed bugs from last commit, (continued)
- [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
- [elpa] master f560f1b 056/135: Fixed error reporting, Ian Dunn, 2020/02/17
- [elpa] master 827d7c1 060/135: Fixed up chain test, Ian Dunn, 2020/02/17
- [elpa] master 89c2ecf 057/135: Added tests for conditions,
Ian Dunn <=
- [elpa] master 03bafb0 061/135: Documented delete-property! action, Ian Dunn, 2020/02/17
- [elpa] master 4c26cc8 041/135: Added copyright and licensing information to all files, Ian Dunn, 2020/02/17
- [elpa] master 390ee68 067/135: Fixed ancestors example, Ian Dunn, 2020/02/17
- [elpa] master 3b3625f 064/135: Cleaned up package header and added various docstrings, Ian Dunn, 2020/02/17
- [elpa] master a71c519 068/135: Added docstrings to some finders, Ian Dunn, 2020/02/17
- [elpa] master 3ff308b 055/135: Updated to new syntax, Ian Dunn, 2020/02/17
- [elpa] master 7618794 066/135: Added in-buffer settings and new sections to Documentation, Ian Dunn, 2020/02/17
- [elpa] master 9a6ba17 071/135: Fixed up documentation, Ian Dunn, 2020/02/17
- [elpa] master d493232 077/135: Added support for interactive editing of blockers and triggers, Ian Dunn, 2020/02/17
- [elpa] master 0aa0bf8 082/135: Don't present variables for keyword completion, Ian Dunn, 2020/02/17