add map functionaliy test for struct

This commit is contained in:
Kristin Rutenkolk 2024-10-24 14:42:31 +02:00
parent 18679c435e
commit e5cd228f94

View file

@ -29,4 +29,39 @@
(t/is
(instance? MemorySegment (mem/serialize "this is a string" ::mem/c-string))))
(t/deftest can-define-struct
(t/is
(eval
`(mem/defstruct ~'TestType [::mem/int ~'a ::mem/byte ~'b]))))
(mem/defstruct TestType [::mem/int a ::mem/byte b ::mem/short c])
(t/deftest can-initialize-struct
(t/is (TestType. 5 10 15)))
(t/deftest can-use-common-map-functions
(t/are [x y] (= x (y (TestType. 5 10 15)))
5 :a
10 :b
15 :c
5 #(% :a)
10 #(% :b)
15 #(% :c)
5 #(get :a)
10 #(get :b)
15 #(get :c)
20 #(get :d 20)
nil #(get :d)
[:a :b :c] keys
[5 10 15] vals
{:a 5 :c 15} #(dissoc % :b)
{:a 5 :b 10 :c 0} #(assoc % :c 0)
{:a 5 :b 10 :c 15 :d 20} #(assoc % :d 20)
[[:a 5] [:b 10] [:c 15]] seq
{:a 5 :b 10 :c 15 :d 20} #(merge % {:d 20})
{:a [5 6] :b [10 11] :c [15 16]} #(merge-with vector % {:a 6 :b 11 :c 16})
{:a [5 6] :b [10 11] :c [15 16]} #(merge-with vector % (TestType. 6 11 16))
[:a 5] #(find % :a)
nil #(find % :d)))