add tests for structs with array members
This commit is contained in:
parent
8844eef320
commit
cec1a8a0a8
1 changed files with 32 additions and 3 deletions
|
|
@ -76,7 +76,6 @@
|
||||||
(= {:a 5 :b 10 :c 15}
|
(= {:a 5 :b 10 :c 15}
|
||||||
(mem/deserialize (mem/serialize (TestType. 5 10 15) ::TestType) ::TestType))))
|
(mem/deserialize (mem/serialize (TestType. 5 10 15) ::TestType) ::TestType))))
|
||||||
|
|
||||||
|
|
||||||
(t/deftest can-define-nested-structs
|
(t/deftest can-define-nested-structs
|
||||||
(t/is
|
(t/is
|
||||||
(eval
|
(eval
|
||||||
|
|
@ -92,9 +91,39 @@
|
||||||
(eval
|
(eval
|
||||||
`(mem/defstruct ~'ArrayTestType [::mem/int ~'x ::mem/byte ~'y [::mem/array ::mem/int 4] ~'z]))))
|
`(mem/defstruct ~'ArrayTestType [::mem/int ~'x ::mem/byte ~'y [::mem/array ::mem/int 4] ~'z]))))
|
||||||
|
|
||||||
|
(mem/defstruct ArrayTestType [::mem/int x ::mem/byte y [::mem/array ::mem/int 4] z])
|
||||||
|
|
||||||
(t/deftest can-instantiated-array-member-structs
|
(t/deftest can-instantiated-array-member-structs
|
||||||
(t/are [x y z] (z x (y (ArrayTestType. 5 6 (int-array [1 2 3 4]))))
|
(t/are [x y z] (z x (y (ArrayTestType. 5 6 (int-array [1 2 3 4]))))
|
||||||
{:x 5 :y 6} #(dissoc % :z) =
|
{:x 5 :y 6} #(dissoc % :z) =
|
||||||
(int-array [1 2 3 4]) :z java.util.Arrays/equals))
|
(int-array [1 2 3 4]) :z java.util.Arrays/equals))
|
||||||
|
|
||||||
|
(t/deftest can-serialize-array-struct
|
||||||
|
(t/is
|
||||||
|
(= [5 6 1 2 3 4]
|
||||||
|
(vec (filter #(not= 0 %) (vec (.toArray (mem/serialize (ArrayTestType. 5 6 (int-array [1 2 3 4])) ::ArrayTestType) mem/byte-layout)))))))
|
||||||
|
|
||||||
|
(t/deftest can-serialize-deserialize-array-struct
|
||||||
|
(t/is
|
||||||
|
(java.util.Arrays/equals
|
||||||
|
(int-array [1 2 3 4])
|
||||||
|
(.z (mem/deserialize (mem/serialize (ArrayTestType. 5 6 (int-array [1 2 3 4])) ::ArrayTestType) ::ArrayTestType)))))
|
||||||
|
|
||||||
|
(t/deftest can-define-complex-structs
|
||||||
|
(t/is
|
||||||
|
(eval
|
||||||
|
`(mem/defstruct ~'ComplexTestType [[::mem/array ::ArrayTestType 4] ~'x ::mem/byte ~'y [::mem/array ::mem/int 4] ~'z ::NestedTestType ~'w]))))
|
||||||
|
|
||||||
|
(mem/defstruct ComplexTestType [[::mem/array ::ArrayTestType 4] x ::mem/byte y [::mem/array ::mem/int 4] z ::NestedTestType w])
|
||||||
|
|
||||||
|
(t/deftest can-serialize-deserialize-complex-struct-type
|
||||||
|
(t/is
|
||||||
|
(let [x (object-array (map #(ArrayTestType. % % (int-array (range 4))) (range 4)))
|
||||||
|
y 12
|
||||||
|
z (int-array (range 4))
|
||||||
|
w (NestedTestType. 5 6 (TestType. 5 10 15))]
|
||||||
|
(->
|
||||||
|
(ComplexTestType. x y z w)
|
||||||
|
(mem/serialize ::ComplexTestType)
|
||||||
|
(mem/deserialize ::ComplexTestType)))))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue