mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-05 04:44:12 +03:00
76 lines
2.0 KiB
Plaintext
76 lines
2.0 KiB
Plaintext
(load "Test.carp")
|
|
(use-all Maybe Test)
|
|
|
|
(deftest test
|
|
(assert-true test
|
|
(nothing? &(the (Maybe Int) (Nothing)))
|
|
"nothing? works on Nothing"
|
|
)
|
|
(assert-false test
|
|
(nothing? &(Just 1))
|
|
"nothing? works on Just"
|
|
)
|
|
(assert-true test
|
|
(just? &(Just 1))
|
|
"just? works on Just"
|
|
)
|
|
(assert-false test
|
|
(just? &(the (Maybe Int) (Nothing)))
|
|
"just? works on Nothing"
|
|
)
|
|
(assert-equal test
|
|
1
|
|
(from (Just 1) 0)
|
|
"from works on Just"
|
|
)
|
|
(assert-equal test
|
|
0
|
|
(from (the (Maybe Int) (Nothing)) 0)
|
|
"from works on Nothing"
|
|
)
|
|
(assert-equal test
|
|
1
|
|
(unsafe-from (Just 1))
|
|
"unsafe-from works on Just"
|
|
)
|
|
(assert-equal test
|
|
2
|
|
(from (apply (Just 1) Int.inc) 0)
|
|
"apply works on Just"
|
|
)
|
|
(assert-equal test
|
|
0
|
|
(from (apply (the (Maybe Int) (Nothing)) Int.inc) 0)
|
|
"apply works on Nothing"
|
|
)
|
|
(assert-equal test
|
|
&(Result.Success 1)
|
|
&(to-result (Just 1) @"error")
|
|
"to-result works on Just"
|
|
)
|
|
(assert-equal test
|
|
&(the (Result Int String) (Result.Error @"error"))
|
|
&(to-result (Nothing) @"error")
|
|
"to-result works on Nothing"
|
|
)
|
|
(assert-equal test
|
|
1
|
|
@(Pointer.to-ref (ptr (Just 1)))
|
|
"ptr works on Just"
|
|
)
|
|
(assert-true test
|
|
(null? (ptr (the (Maybe Int) (Nothing))))
|
|
"ptr works on Nothing"
|
|
)
|
|
(assert-equal test
|
|
&(Just 0)
|
|
&(from-ptr (address (zero)))
|
|
"from-ptr works on Ptr/Just"
|
|
)
|
|
(assert-equal test
|
|
&(Nothing)
|
|
&(the (Maybe Int) (from-ptr NULL))
|
|
"from-ptr works on NULL/Nothing"
|
|
)
|
|
)
|