-
Notifications
You must be signed in to change notification settings - Fork 14
/
spec.cljs
73 lines (61 loc) · 2.15 KB
/
spec.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(ns zetawar.system.spec
(:require
[cljs.core.async :as async]
[cljs.core.async.impl.protocols :as async.protocols]
[clojure.spec :as s]
[clojure.spec.impl.gen :as gen]
[clojure.test.check]
[datascript.core :as d]))
;; Logger
(s/def :zetawar.system/logger nil?)
;; DataScript
(s/def :zetawar.system.datascript/schema
(s/with-gen map?
#(gen/return {})))
(s/def :zetawar.system.datascript/conn
(s/with-gen d/conn?
#(gen/return (d/create-conn {}))))
(s/def :zetawar.system/datascript
(s/keys :req-un [:zetawar.system.datascript/schema
:zetawar.system.datascript/conn]))
;; Players
(s/def :zetawar.system/players
(s/with-gen (s/and #(satisfies? IDeref %)
#(map? (deref %)))
#(gen/fmap (fn [m] (atom m))
(gen/map (gen/keyword) (gen/any-printable)))))
;; Router
(s/def :zetawar.system.router/ev-chan
(s/with-gen
(s/and #(satisfies? async.protocols/ReadPort %)
#(satisfies? async.protocols/WritePort %))
#(gen/return (async/chan))))
(s/def :zetawar.system.router/notify-chan
(s/with-gen
#(satisfies? async.protocols/WritePort %)
#(gen/return (async/chan))))
(s/def :zetawar.system.router/notify-pub
(s/with-gen
#(satisfies? async/Pub %)
#(gen/return (let [notify-chan (async/chan)]
(async/pub notify-chan (fn [x] (nth x 1)))))))
(s/def :zetawar.system/router
(s/keys :req-un [:zetawar.system.datascript/conn
:zetawar.system/players
:zetawar.system.router/ev-chan
:zetawar.system.router/notify-chan
:zetawar.system.router/notify-pub]))
;; Views
(s/def :zetawar.system.views/dispatch fn?)
(s/def :zetawar.system.views/translate fn?)
(s/def :zetawar.system/views
(s/keys :req-un [:zetawar.system.datascript/conn
:zetawar.system.views/dispatch
:zetawar.system.views/translate]))
;; System
(s/def :zetawar/system
(s/keys :req-un [:zetawar.system/logger
:zetawar.system/datascript
:zetawar.system/players
:zetawar.system/router
:zetawar.system/views]))