Initial Commit

This commit is contained in:
akko
2024-10-08 11:47:30 +02:00
commit 85b6b7360f
31 changed files with 2889 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
(ns emptyhead.test.idea.crud
(:require [cljs.test :as t :include-macros true]
[emptyhead.idea.crud :as crud]
[emptyhead.idea.state :as s :refer [state]]
[emptyhead.idea.protocol :as prtc]
[emptyhead.test.fixtures :as fx]))
(t/use-fixtures :once fx/temporary-state)
(t/use-fixtures :each fx/pre-reset)
(t/deftest have-idea!
(t/testing "Idea creation"
(let [idea (crud/have-idea!)]
(t/is (get @state idea)))))
(t/deftest idea-updating
(t/testing "Idea updating"
(let [idea (crud/have-idea!)]
(crud/extend-idea! idea {:foo :bar})
(t/is (= :bar (prtc/val-fn :foo idea)))
(crud/swap-idea! idea {:baz :quux})
(t/is (not (prtc/val-fn :foo idea)))
(t/is (= :quux (prtc/val-fn :baz idea)))
)))
(t/deftest forget!
(t/testing "Idea deletion"
(let [idea (crud/have-idea!)]
(crud/forget-idea! idea)
(t/is (= nil (get @state idea))))))

View File

@@ -0,0 +1,25 @@
(ns emptyhead.test.idea.property
(:require [cljs.test :as t :include-macros true]
[emptyhead.idea.crud :as crud]
[emptyhead.idea.property :as prop]
[emptyhead.test.fixtures :as fx]))
(t/use-fixtures :once fx/temporary-state)
(t/use-fixtures :each fx/pre-reset)
(t/deftest properties
(t/testing "Property addition and removal"
(let [idea (crud/have-idea!)]
(prop/register-property! idea [:a :b :c] [:a :d :e])
(t/is (= #{[:a :b :c] [:a :d :e] [:a] [:a :b] [:a :d]}
(prop/properties idea)))
(t/is (prop/has-property? idea [:a :b]))
(t/is (not (prop/has-property? idea [:invalid])))
(t/is (contains? (prop/with-property [:a :d]) idea))
(t/is (not (contains? (prop/with-property [:invalid]) idea)))
(prop/remove-property! idea [:a :b])
(t/is (not (prop/has-property? idea [:a :b :c]))))))

View File

@@ -0,0 +1,22 @@
(ns emptyhead.test.idea.protocol
(:require [cljs.test :as t :include-macros true]
[emptyhead.idea.crud :as crud]
[emptyhead.idea.protocol :as prtc]
[emptyhead.test.utils :refer [expect-error]]
[emptyhead.test.fixtures :as fx]))
(t/use-fixtures :once fx/temporary-state)
(t/use-fixtures :each fx/pre-reset)
(t/deftest protocol
(t/testing "Value/reference semantics"
(let [idea (crud/have-idea!)]
;; Repeatedly going between value and reference shouldn't mangle idea
(t/is (= idea (-> idea prtc/value prtc/reference)))
(t/is (= (prtc/value idea) (-> idea prtc/reference prtc/value)))
;; Attempting to get a reference to a copy should be an error
(expect-error :stale-reference #(prtc/reference (prtc/copy idea)))
;; Attempting to get a reference to an invalid idea should be an error
(expect-error :invalid-reference #(prtc/reference {})))))