diff --git a/local/lib/org-x/test/org-x-dag-test.el b/local/lib/org-x/test/org-x-dag-test.el index e4fd461..3a4ee5c 100644 --- a/local/lib/org-x/test/org-x-dag-test.el +++ b/local/lib/org-x/test/org-x-dag-test.el @@ -24,6 +24,7 @@ ;;; Code: (require 's) +(require 'either) (require 'dash) (require 'org-x) @@ -37,6 +38,50 @@ org-x-weekly-plan-file "weekly.org" org-x-quarterly-plan-file "quarterly.org")) +(buttercup-define-matcher :to-be-left-with (a x) + (cl-destructuring-bind + ((a-expr . a) (x-expr . x)) + (mapcar #'buttercup--expr-and-value (list a x)) + (either-from a + (lambda (l) + (if (equal l x) + `(t . ,(format "Expected %s left with %s" a-expr x)) + `(nil . ,(format "Expected %s left with %s, but got left with %s" + a-expr x l)))) + (lambda () + `(nil . ,(format "Expected %s to be a left, got a right" a-expr)))))) + +(buttercup-define-matcher :to-have-same-as-plist (a b) + (cl-destructuring-bind + ((a-expr . a) (b-expr . b)) + (mapcar #'buttercup--expr-and-value (list a b)) + (let* ((a* (-partition 2 a)) + (b* (-partition 2 b)) + (a-diff (->> (-difference a* b*) (--map (format "%S" it)) (s-join ", "))) + (b-diff (->> (-difference b* a*) (--map (format "%S" it)) (s-join ", ")))) + (cond + ((and a-diff b-diff) + (cons nil (format "Expected %s to have pairs '%s' and not to have pairs '%s'" + a-expr b-diff a-diff))) + (a-diff + (cons nil (format "Expected %s not to have pairs '%s'" a-expr a-diff))) + (b-diff + (cons nil (format "Expected %s to have pairs '%s'" a-expr b-diff))) + (t + (cons t (format "Expected %s not to have same items as '%s'" + a-expr b-expr))))))) + +;; (defun bs-error (id left) +;; (let ((bs (org-x-dag-id->bs id))) +;; (expect (either-is-left-p bs)) +;; (expect (either-from-left bs nil) :to-equal left))) + +;; (defun bs-action-equal (id ancestry local) +;; (let ((bs (org-x-dag-id-bs id))) +;; (expect (either-is-right-p bs)) +;; (from-either (org-x-dag-id-bs id) +;; (expect (org-x-dag-id-bs id) :to-equal bs)) + (describe "Sync DAG" ;; TODO this won't actually fail if there is an error (it "Sync completes without error" @@ -46,7 +91,13 @@ (it "One random hash is present in the dag" (expect (org-x-dag-id->title "06592f95-9cf5-4d7e-8546-da7796d76813") :to-equal - "don't be a dick"))) + "don't be a dick")) + + (it "test my own macros" + (expect (either :left "blabla") :to-be-left-with "blabla")) + + (it "test my own macros" + (expect '(:a 1) :to-have-same-as-plist '(:b 1)))) (provide 'org-x-dag-test) ;;; org-x-dag-test.el ends here