fix order of type and fieldname for defstruct in tests

This commit is contained in:
Kristin Rutenkolk 2025-01-04 20:40:03 +01:00
parent 5a9d156e17
commit 637f156663
2 changed files with 11 additions and 13 deletions

View file

@ -73,13 +73,13 @@
:ok)))
(mem/defstruct Point [::mem/float x ::mem/float y])
(mem/defstruct Point [x ::mem/float y ::mem/float])
(t/deftest can-call-with-defstruct
(t/is (= {:x 2.0 :y 2.0}
((ffi/cfn "add_points" [::Point ::Point] ::Point) (Point. 1 2) (Point. 1 0)))))
(mem/defstruct AlignmentTest [::mem/char a ::mem/double x ::mem/float y])
(mem/defstruct AlignmentTest [a ::mem/char x ::mem/double y ::mem/float])
(t/deftest padding-matches-defstruct
(t/is (= ((ffi/cfn "get_struct" [] ::AlignmentTest))
@ -87,7 +87,7 @@
:x 3.14
:y 42.0})))
(mem/defstruct ComplexType [::Point x ::mem/byte y [::mem/array ::mem/int 4 :raw? true] z ::mem/c-string w])
(mem/defstruct ComplexType [x ::Point y ::mem/byte z [::mem/array ::mem/int 4 :raw? true] w ::mem/c-string])
(t/deftest can-call-with-complex-defstruct
(t/are [x y] (= x (y ((ffi/cfn "complexTypeTest" [::ComplexType] ::ComplexType)
@ -95,7 +95,7 @@
{:x {:x 3.0 :y 4.0} :y 3 :w "hello from c"} #(dissoc % :z)
[5 6 7 8] (comp vec :z)))
(mem/defstruct ComplexTypeWrapped [::Point x ::mem/byte y [::mem/array ::mem/int 4] z ::mem/c-string w])
(mem/defstruct ComplexTypeWrapped [x ::Point y ::mem/byte z [::mem/array ::mem/int 4] w ::mem/c-string])
(t/deftest can-call-with-wrapped-complex-defstruct
(t/are [x y] (= x (y ((ffi/cfn "complexTypeTest" [::ComplexTypeWrapped] ::ComplexTypeWrapped)
@ -103,5 +103,3 @@
{:x {:x 3.0 :y 4.0} :y 3 :w "hello from c"} #(dissoc % :z)
[5 6 7 8] (comp vec :z)))

View file

@ -32,9 +32,9 @@
(t/deftest can-define-struct
(t/is
(eval
`(mem/defstruct ~'TestType [::mem/int ~'a ::mem/byte ~'b]))))
`(mem/defstruct ~'TestType [~'a ::mem/int ~'b ::mem/byte]))))
(mem/defstruct TestType [::mem/int a ::mem/byte b ::mem/short c])
(mem/defstruct TestType [a ::mem/int b ::mem/byte c ::mem/short])
(t/deftest can-initialize-struct
(t/is (TestType. 5 10 15)))
@ -78,7 +78,7 @@
(= {:a 5 :b 10 :c 15}
(mem/deserialize (mem/serialize (TestType. 5 10 15) ::TestType) ::TestType))))
(mem/defstruct NestedTestType [::mem/int x ::mem/byte y ::TestType z])
(mem/defstruct NestedTestType [x ::mem/int y ::mem/byte z ::TestType])
(t/deftest can-instantiated-nested-structs
(t/is
@ -88,9 +88,9 @@
(t/deftest can-define-structs-with-array-members
(t/is
(eval
`(mem/defstruct ~'ArrayTestType [::mem/int ~'x ::mem/byte ~'y [::mem/array ::mem/int 4 :raw? true] ~'z]))))
`(mem/defstruct ~'ArrayTestType [~'x ::mem/int ~'y ::mem/byte ~'z [::mem/array ::mem/int 4 :raw? true]]))))
(mem/defstruct ArrayTestType [::mem/int x ::mem/byte y [::mem/array ::mem/int 4 :raw? true] z])
(mem/defstruct ArrayTestType [x ::mem/int y ::mem/byte z [::mem/array ::mem/int 4 :raw? true]])
(t/deftest can-instantiated-array-member-structs
(t/are [x y z] (z x (y (ArrayTestType. 5 6 (int-array [1 2 3 4]))))
@ -108,7 +108,7 @@
(int-array [1 2 3 4])
(.z (mem/deserialize (mem/serialize (ArrayTestType. 5 6 (int-array [1 2 3 4])) ::ArrayTestType) ::ArrayTestType)))))
(mem/defstruct ComplexTestType [[::mem/array ::ArrayTestType 4 :raw? true] x ::mem/byte y [::mem/array ::mem/int 4 :raw? true] z ::NestedTestType w])
(mem/defstruct ComplexTestType [x [::mem/array ::ArrayTestType 4 :raw? true] y ::mem/byte z [::mem/array ::mem/int 4 :raw? true] w ::NestedTestType])
(t/deftest can-serialize-deserialize-complex-struct-type
(t/is
@ -121,7 +121,7 @@
(mem/serialize ::ComplexTestType)
(mem/deserialize ::ComplexTestType)))))
(mem/defstruct ComplexTestTypeWrapped [[::mem/array ::ArrayTestType 4] x ::mem/byte y [::mem/array ::mem/int 4] z ::NestedTestType w])
(mem/defstruct ComplexTestTypeWrapped [x [::mem/array ::ArrayTestType 4] y ::mem/byte z [::mem/array ::mem/int 4] w ::NestedTestType])
(t/deftest can-serialize-deserialize-complex-wrapped-struct-type
(t/is