|
1 | 1 | (ns datascript.test.serialize |
2 | 2 | (:require |
3 | | - [#?(:cljs cljs.reader :clj clojure.edn) :as edn] |
4 | | - #?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]] |
5 | | - :clj [clojure.test :as t :refer [is are deftest testing]]) |
6 | | - [datascript.core :as d] |
7 | | - [datascript.db :as db] |
8 | | - [datascript.test.core :as tdc] |
9 | | - #?(:clj [cheshire.core :as cheshire]) |
10 | | - #?(:clj [jsonista.core :as jsonista])) |
11 | | - #?(:clj |
12 | | - (:import [clojure.lang ExceptionInfo]))) |
| 3 | + [#?(:cljs cljs.reader :clj clojure.edn) :as edn] |
| 4 | + #?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]] |
| 5 | + :clj [clojure.test :as t :refer [is are deftest testing]]) |
| 6 | + [datascript.core :as d] |
| 7 | + [datascript.db :as db] |
| 8 | + [datascript.test.core :as tdc] |
| 9 | + #?(:clj [cheshire.core :as cheshire]) |
| 10 | + #?(:clj [jsonista.core :as jsonista])) |
| 11 | + #?(:clj |
| 12 | + (:import [clojure.lang ExceptionInfo]))) |
13 | 13 |
|
14 | 14 | (t/use-fixtures :once tdc/no-namespace-maps) |
15 | 15 |
|
|
31 | 31 | (is (= d (read-fn (pr-str d))))) |
32 | 32 |
|
33 | 33 | (let [db (-> (d/empty-db {:name {:db/unique :db.unique/identity}}) |
34 | | - (d/db-with [ [:db/add 1 :name "Petr"] |
35 | | - [:db/add 1 :age 44] ]) |
36 | | - (d/db-with [ [:db/add 2 :name "Ivan"] ]))] |
| 34 | + (d/db-with [[:db/add 1 :name "Petr"] |
| 35 | + [:db/add 1 :age 44]]) |
| 36 | + (d/db-with [[:db/add 2 :name "Ivan"]]))] |
37 | 37 | (is (= (pr-str db) |
38 | | - (str "#datascript/DB {" |
39 | | - ":schema {:name {:db/unique :db.unique/identity}}, " |
40 | | - ":datoms [" |
41 | | - "[1 :age 44 536870913] " |
42 | | - "[1 :name \"Petr\" 536870913] " |
43 | | - "[2 :name \"Ivan\" 536870914]" |
44 | | - "]}"))) |
| 38 | + (str "#datascript/DB {" |
| 39 | + ":schema {:name {:db/unique :db.unique/identity}}, " |
| 40 | + ":datoms [" |
| 41 | + "[1 :age 44 536870913] " |
| 42 | + "[1 :name \"Petr\" 536870913] " |
| 43 | + "[2 :name \"Ivan\" 536870914]" |
| 44 | + "]}"))) |
45 | 45 | (is (= db (read-fn (pr-str db)))))))) |
46 | 46 |
|
47 | 47 |
|
|
54 | 54 | |
55 | 55 | [1 :avatar 10] |
56 | 56 | [10 :url "http://"] |
57 | | - [1 :attach { :some-key :some-value }] |
| 57 | + [1 :attach {:some-key :some-value}] |
58 | 58 | [2 :name "Oleg"] |
59 | 59 | [2 :age 30] |
60 | 60 | |
61 | | - [2 :attach [ :just :values ]] |
| 61 | + [2 :attach [:just :values]] |
62 | 62 | [3 :name "Ivan"] |
63 | 63 | [3 :age 15] |
64 | 64 | [3 :follows 2] |
65 | | - [3 :attach { :another :map }] |
| 65 | + [3 :attach {:another :map}] |
66 | 66 | [3 :avatar 30] |
67 | 67 | [4 :name "Nick" d/tx0] |
68 | 68 | [5 :inf ##Inf] |
69 | 69 | [5 :-inf ##-Inf] |
| 70 | + #?@(:clj [[5 :ratio 22/7] |
| 71 | + [5 :bigint (bigint 100)] |
| 72 | + [5 :biginteger (biginteger 100)] |
| 73 | + [5 :bigdec (bigdec 100.005)]]) |
70 | 74 | ;; check that facts about transactions doesn’t set off max-eid |
71 | 75 | [d/tx0 :txInstant 0xdeadbeef] |
72 | | - [30 :url "https://" ]]) |
| 76 | + [30 :url "https://"]]) |
73 | 77 |
|
74 | 78 |
|
75 | 79 | (def schema |
76 | | - { :name { } ;; nothing special about name |
77 | | - :aka { :db/cardinality :db.cardinality/many } |
78 | | - :age { :db/index true } |
79 | | - :follows { :db/valueType :db.type/ref } |
80 | | - :email { :db/unique :db.unique/identity } |
81 | | - :avatar { :db/valueType :db.type/ref, :db/isComponent true } |
82 | | - :url { } ;; just a component prop |
83 | | - :attach { } ;; should skip index |
84 | | -}) |
| 80 | + {:name {} ;; nothing special about name |
| 81 | + :aka {:db/cardinality :db.cardinality/many} |
| 82 | + :age {:db/index true} |
| 83 | + :follows {:db/valueType :db.type/ref} |
| 84 | + :email {:db/unique :db.unique/identity} |
| 85 | + :avatar {:db/valueType :db.type/ref, :db/isComponent true} |
| 86 | + :url {} ;; just a component prop |
| 87 | + :attach {} ;; should skip index |
| 88 | + }) |
85 | 89 |
|
86 | 90 |
|
87 | 91 | (deftest test-init-db |
|
98 | 102 | (testing "db-init produces the same max-eid as regular transactions" |
99 | 103 | (let [assertions [ [:db/add -1 :name "Lex"] ]] |
100 | 104 | (is (= (d/db-with db-init assertions) |
101 | | - (d/db-with db-transact assertions))))) |
| 105 | + (d/db-with db-transact assertions))))) |
102 | 106 |
|
103 | 107 | (testing "Roundtrip" |
104 | 108 | (doseq [[r read-fn] readers] |
|
0 commit comments