mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
* fix: Make `str` work for (Pointer a) types * test: Make sure that the Pointer.str compiles * fix: Remove test case, keep function around to make sure it compiles
53 lines
1.4 KiB
Plaintext
53 lines
1.4 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))))
|
|
|
|
;; Just make sure the 'str' for a Pointer compiles
|
|
;; (testing out its contents is platform specific)
|
|
(defn pointer-to-str []
|
|
(let [p (the (Ptr CChar) NULL)]
|
|
(str p)))
|
|
|
|
; 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"
|
|
)
|
|
)
|