mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-12 12:49:13 +03:00
47 lines
1.2 KiB
Plaintext
47 lines
1.2 KiB
Plaintext
(load "Test.carp")
|
|
|
|
(use-all Test Pointer)
|
|
|
|
; we go to the middle of a chunk of 10 safe elements
|
|
(def x (add (Array.raw (the (Array Int) (Array.allocate 10))) 5l))
|
|
(def xa (to-long x))
|
|
(def w (width x))
|
|
|
|
(defn ref-to-ptr [r]
|
|
(the (Ptr a) (Unsafe.coerce (the (Ref a) r))))
|
|
|
|
; these tests are sadly a little unsafe
|
|
(deftest test
|
|
(assert-equal test
|
|
4l
|
|
; we assume that the width of a char is 4
|
|
(width (Array.raw (the (Array Char) [])))
|
|
"Pointer.width works as expected"
|
|
)
|
|
(assert-equal test
|
|
(+ xa (* 3l w))
|
|
(to-long (add x 3l))
|
|
"Pointer.add works as expected"
|
|
)
|
|
(assert-equal test
|
|
(- xa (* 3l w))
|
|
(to-long (sub x 3l))
|
|
"Pointer.sub works as expected"
|
|
)
|
|
(assert-equal test
|
|
(+ xa w)
|
|
(to-long (inc x))
|
|
"Pointer.inc works as expected"
|
|
)
|
|
(assert-equal test
|
|
(- xa w)
|
|
(to-long (dec x))
|
|
"Pointer.dec works as expected"
|
|
)
|
|
(assert-equal test
|
|
(to-value (ref-to-ptr &123))
|
|
123
|
|
"Pointer.to-value works as expected"
|
|
)
|
|
)
|