Skip to content

Commit

Permalink
move tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi committed Jan 6, 2024
1 parent c864341 commit eacd6e4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 48 deletions.
61 changes: 38 additions & 23 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3009,28 +3009,43 @@
[:id #'UserId]
[:friends {:optional true} [:set [:ref #'User]]]])

(def registry (mr/composite-registry
(m/default-schemas)
(mr/var-registry)))

(deftest var-registry-test
(let [schema (m/schema User {:registry registry})]

(testing "getting schema over Var works"
(is (= UserId (mr/-schema (mr/var-registry) #'UserId)))
(is (= User (mr/-schema (mr/var-registry) #'User))))

(testing "we do not list all Var schemas (yet)"
(is (= nil (mr/-schemas (mr/var-registry)))))

(testing "it works"
(is (= User (m/form schema)))
(is (every? (m/validator schema) (mg/sample schema {:seed 100}))))))

#?(:clj
(deftest roundrobin-var-references
(let [registry (mr/composite-registry
(m/default-schemas)
(mr/var-registry))]

(testing "default options with var-registry fails"
(let [options {:registry registry}
schema (m/schema User options)]
(is (thrown? Exception
(as-> schema $
(edn/write-string $)
(edn/read-string $ options)
(every? (m/validator $) (mg/sample schema)))))))

(testing "with custom edamame options with var-registry succeeds"
(let [options {:registry registry
::edn/edamame-options {:fn true,
:regex true,
:var resolve}}
schema (m/schema User options)]
(is (as-> schema $
(edn/write-string $)
(edn/read-string $ options)
(every? (m/validator $) (mg/sample schema)))))))))

(testing "default options with var-registry fails"
(let [options {:registry registry}
schema (m/schema User options)]
(is (thrown? Exception
(as-> schema $
(edn/write-string $)
(edn/read-string $ options)
(every? (m/validator $) (mg/sample schema)))))))

(testing "with custom edamame options with var-registry succeeds"
(let [options {:registry registry
::edn/edamame-options {:fn true,
:regex true,
:var resolve}}
schema (m/schema User options)]
(is (as-> schema $
(edn/write-string $)
(edn/read-string $ options)
(every? (m/validator $) (mg/sample schema))))))))
25 changes: 0 additions & 25 deletions test/malli/registry_test.cljc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns malli.registry-test
(:require [clojure.test :refer [deftest is testing]]
[malli.core :as m]
[malli.generator :as mg]
[malli.registry :as mr]))

(deftest mutable-test
Expand Down Expand Up @@ -32,30 +31,6 @@
{:registry registry})))
(is (= #{:string :map :maybe} (-> registry (mr/-schemas) (keys) (set)))))))

(def UserId :string)

(def User
[:map
[:id #'UserId]
[:friends {:optional true} [:set [:ref #'User]]]])

(deftest var-registry-test
(let [registry (mr/composite-registry
(m/default-schemas)
(mr/var-registry))
schema (m/schema User {:registry registry})]

(testing "getting schema over Var works"
(is (= UserId (mr/-schema (mr/var-registry) #'UserId)))
(is (= User (mr/-schema (mr/var-registry) #'User))))

(testing "we do not list all Var schemas (yet)"
(is (= nil (mr/-schemas (mr/var-registry)))))

(testing "it works"
(is (= User (m/form schema)))
(is (every? (m/validator schema) (mg/sample schema {:seed 100}))))))

(deftest lazy-registry-test
(let [loads (atom #{})
registry (mr/lazy-registry
Expand Down

0 comments on commit eacd6e4

Please sign in to comment.