Created
August 7, 2012 17:29
-
-
Save bdaniels/3287562 to your computer and use it in GitHub Desktop.
I thought that the first constraint on design would cause all to fail if null, but I'm getting results from the conde statement afterwards in my unit tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Logic Code | |
(defn uri-path [design view search path] | |
(logic/!= nil design) | |
(logic/conde | |
[(logic/!= nil view) (logic/== ["_design" design "_view" view] path)])) | |
; Unit test | |
(test/deftest test-path | |
(test/is (= '() | |
(logic/run* [q] (db/uri-path nil "view" "search" q)))) | |
(test/is (= '(["_design" "design" "_view" "view"]) | |
(logic/run* [q] (db/uri-path "design" "view" nil q))))) | |
; Test results | |
; FAIL in (test-path) (db_test.clj:24) | |
; expected: (= (quote ()) (logic/run* [q] (db/uri-path nil "view" "search" q))) | |
; actual: (not (= () (["_design" nil "_view" "view"]))) | |
; The solution | |
(defn uri-path [design view search path] | |
(logic/fresh [x] | |
(logic/== x design) | |
(logic/!= x nil) | |
(logic/conde | |
[(logic/!= nil view) (logic/== ["_design" x "_view" view] path)]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment