Make tests run in both clj and cljs.

This commit is contained in:
Richard Newman 2016-07-12 19:04:36 -07:00
parent 60aa3df5b0
commit c4f2e00112
6 changed files with 39 additions and 31 deletions

View file

@ -9,7 +9,7 @@
(defn var->sql-var (defn var->sql-var
"Turns '?xyz into :xyz." "Turns '?xyz into :xyz."
[x] [x]
(when-not (and (symbol? x) (if (and (symbol? x)
(str/starts-with? (name x) "?")) (str/starts-with? (name x) "?"))
(raise (str x " is not a Datalog var."))) (keyword (subs (name x) 1))
(keyword (subs (name x) 1))) (raise (str x " is not a Datalog var."))))

View file

@ -0,0 +1,9 @@
(ns datomish.test.query
(:require
[datomish.query :as dq]
#?(:clj [clojure.test :as t :refer [is are deftest testing]])
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]])
))
(deftest test-query
(is (= 1 1)))

View file

@ -1,7 +0,0 @@
(ns datomish.test.query
(:require
[cljs.test :as t :refer-macros [is are deftest testing]]
[datomish.query :as dq]))
(deftest test-query
(is (= 1 1)))

View file

@ -1,7 +1,9 @@
(ns datomish.test.transforms (ns datomish.test.transforms
(:require (:require
[cljs.test :as t :refer-macros [is are deftest testing]] [datomish.transforms :as transforms]
[datomish.transforms :as transforms])) #?(:clj [clojure.test :as t :refer [is are deftest testing]])
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]])
))
(deftest test-attribute-transform-string (deftest test-attribute-transform-string
(is (= "p/foo" (is (= "p/foo"
@ -16,7 +18,8 @@
(is (= 0 (transforms/constant-transform-default false))) (is (= 0 (transforms/constant-transform-default false)))
;; Numbers and strings. ;; Numbers and strings.
(is (= 1 (transforms/constant-transform-default 1.0))) #?(:cljs (is (= 1 (transforms/constant-transform-default 1.0))))
#?(:clj (is (= 1.0 (transforms/constant-transform-default 1.0))))
(is (= -1 (transforms/constant-transform-default -1))) (is (= -1 (transforms/constant-transform-default -1)))
(is (= 42 (transforms/constant-transform-default 42))) (is (= 42 (transforms/constant-transform-default 42)))
(is (= "" (transforms/constant-transform-default ""))) (is (= "" (transforms/constant-transform-default "")))

View file

@ -0,0 +1,20 @@
(ns datomish.test.util
(:require
[datomish.util :as util]
#?(:clj [clojure.test :as t :refer [is are deftest testing]])
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]])
))
(deftest test-var-translation
(is (= :x (util/var->sql-var '?x)))
(is (= :XX (util/var->sql-var '?XX))))
#?(:cljs
(deftest test-raise
(let [caught
(try
(do
(util/raise "succeed")
"fail")
(catch :default e e))]
(is (= "succeed" (aget caught "message"))))))

View file

@ -1,17 +0,0 @@
(ns datomish.test.util
(:require
[cljs.test :as t :refer-macros [is are deftest testing]]
[datomish.util :as util]))
(deftest test-var-translation
(is (= :x (util/var->sql-var '?x)))
(is (= :XX (util/var->sql-var '?XX))))
(deftest test-raise
(let [caught
(try
(do
(util/raise "succeed")
"fail")
(catch :default e e))]
(is (= "succeed" (aget caught "message")))))