-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de1bf6a
commit f16caf1
Showing
3 changed files
with
56 additions
and
89 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,47 @@ | ||
;(ns precept.macros-test | ||
; (:require [precept.rules :refer [session]] | ||
; [precept.util :as util] | ||
; [precept.core :as core] | ||
; [clara.rules :refer [defsession defrule]] | ||
; [clara.rules.accumulators :as acc] | ||
; [clojure.test :refer [deftest run-tests testing is]] | ||
; [precept.schema :as schema] | ||
; [precept.schema-fixture :refer [test-schema]] | ||
; [precept.dsl :refer [<- entity]] | ||
; [precept.state :as state] | ||
; [clara.rules.compiler :as com]) | ||
; (:import [precept.util Tuple])) | ||
; | ||
;(deftest session-test | ||
; (testing "Macroexpansion should be the same as equivalent | ||
; arguments to defsession" | ||
; (is (= (macroexpand `(defsession ~'foo | ||
; 'precept.impl.rules | ||
; 'precept.macros-test | ||
; :fact-type-fn :a | ||
; :ancestors-fn (util/make-ancestors-fn | ||
; (schema/init! (select-keys {} | ||
; [:db-schema :client-schema]))) | ||
; :activation-group-fn (util/make-activation-group-fn ~core/default-group) | ||
; :activation-group-sort-fn (util/make-activation-group-sort-fn | ||
; ~core/groups | ||
; ~core/default-group))) | ||
; (macroexpand '(session foo 'precept.macros-test))))) | ||
; | ||
; (testing "Allow overwrite defaults" | ||
; (let [clara-session `(defsession ~'foo | ||
; 'precept.impl.rules | ||
; 'precept.macros-test | ||
; :fact-type-fn ~'(fn [x] (or (:a x) | ||
; (:b x))) | ||
; :ancestors-fn ~'(fn [x] [:all :foo]) | ||
; :activation-group-fn (util/make-activation-group-fn ~core/default-group) | ||
; :activation-group-sort-fn (util/make-activation-group-sort-fn | ||
; ~core/groups | ||
; ~core/default-group)) | ||
; wrapper '(session foo | ||
; 'precept.macros-test | ||
; :fact-type-fn (fn [x] (or (:a x) | ||
; (:b x))) | ||
; :ancestors-fn (fn [x] [:all :foo]))])) | ||
; ;(is (= (macroexpand clara-session) (macroexpand wrapper))))) | ||
; | ||
; (testing "Expand :db-schema opt to ancestors fn") | ||
; ;(is (= (macroexpand `(defsession ~'foo | ||
; ; 'precept.impl.rules | ||
; ; 'precept.macros-test | ||
; ; :fact-type-fn :a | ||
; ; :ancestors-fn (util/make-ancestors-fn | ||
; ; (schema/init! | ||
; ; (select-keys | ||
; ; {:db-schema ~precept.schema-fixture/test-schema} | ||
; ; [:db-schema :client-schema] | ||
; ; :activation-group-fn (util/make-activation-group-fn ~core/default-group) | ||
; ; :activation-group-sort-fn (util/make-activation-group-sort-fn | ||
; ; ~core/groups | ||
; ; ~core/default-group | ||
; ; (macroexpand `(session ~'foo | ||
; ; 'precept.macros-test | ||
; ; :db-schema ~precept.schema-fixture/test-schema) | ||
; | ||
;;; TODO. Probably better off testing functionality over expansion at this point | ||
; (testing "Expand :client-schema and :db-schema opts to ancestors fn")) | ||
; ;(is (= (macroexpand `(defsession ~'foo | ||
; ; 'precept.impl.rules | ||
; ; 'precept.macros-test | ||
; ; :fact-type-fn :a | ||
; ; :ancestors-fn (util/make-ancestors-fn | ||
; ; (schema/init! | ||
; ; (select-keys | ||
; ; {:db-schema ~precept.schema-fixture/test-schema | ||
; ; :client-schema ~precept.schema-fixture/test-schema} | ||
; ; [:db-schema :client-schema]))) | ||
; ; :activation-group-fn (util/make-activation-group-fn ~core/default-group) | ||
; ; :activation-group-sort-fn (util/make-activation-group-sort-fn | ||
; ; ~core/groups | ||
; ; ~core/default-group))) | ||
; ; (macroexpand `(session ~'foo | ||
; ; 'precept.macros-test | ||
; ; :db-schema ~precept.schema-fixture/test-schema | ||
; ; :client-schema ~precept.schema-fixture/test-schema)))))) | ||
; | ||
;(run-tests) | ||
(ns precept.macros-test | ||
(:require [precept.macros :as macros] | ||
[clojure.test :refer [deftest run-tests testing is]])) | ||
|
||
(def all-options (list 'precept.macros-test | ||
:db-schema 'db-schema-ns | ||
:client-schema 'client-schema-ns | ||
:reload true)) | ||
|
||
(def no-options (list 'precept.macros-test)) | ||
|
||
(deftest options-map-test | ||
(is (= (macros/options-map no-options) | ||
{})) | ||
(is (= (macros/options-map all-options) | ||
{:db-schema 'db-schema-ns | ||
:client-schema 'client-schema-ns | ||
:reload true}))) | ||
|
||
(deftest sources-list-test | ||
(is (= (macros/sources-list all-options) | ||
(macros/sources-list no-options) | ||
(list 'precept.macros-test)))) | ||
|
||
(deftest precept->clara-options-test | ||
(let [cr-options '(:fact-type-fn :a | ||
:ancestors-fn identity | ||
:activation-group-fn | ||
(precept.util/make-activation-group-fn :calc) | ||
:activation-group-sort-fn | ||
(precept.util/make-activation-group-sort-fn | ||
[:action :calc :report :cleanup] :calc))] | ||
(is (= (macros/precept->clara-options | ||
(macros/merge-default-options | ||
(macros/options-map no-options) | ||
'identity) | ||
macros/precept-options-keys) | ||
cr-options)) | ||
|
||
(is (= (macros/precept->clara-options | ||
(macros/merge-default-options | ||
(macros/options-map all-options) | ||
'identity) | ||
macros/precept-options-keys) | ||
cr-options)))) | ||
|
||
(run-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