11module Test.Assert
2- ( assert'
2+ ( ASSERT
33 , assert
4+ , assert'
45 , assertThrows
56 , assertThrows'
6- , ASSERT ()
77 ) where
88
9- import Control.Monad.Eff (Eff ())
10- import Prelude
9+ import Control.Monad.Eff (Eff )
10+ import Control.Monad ((=<<))
11+ import Data.Unit (Unit )
1112
1213-- | Assertion effect type.
1314foreign import data ASSERT :: !
@@ -19,7 +20,11 @@ assert = assert' "Assertion failed"
1920
2021-- | Throws a runtime exception with the specified message when the boolean
2122-- | value is false.
22- foreign import assert' :: forall e . String -> Boolean -> Eff (assert :: ASSERT | e ) Unit
23+ foreign import assert'
24+ :: forall e
25+ . String
26+ -> Boolean
27+ -> Eff (assert :: ASSERT | e ) Unit
2328
2429-- | Throws a runtime exception with message "Assertion failed: An error should
2530-- | have been thrown", unless the argument throws an exception when evaluated.
@@ -29,7 +34,8 @@ foreign import assert' :: forall e. String -> Boolean -> Eff (assert :: ASSERT |
2934-- | satisfied. Functions which use `Eff (err :: EXCEPTION | eff) a` can be
3035-- | tested with `catchException` instead.
3136assertThrows :: forall e a . (Unit -> a ) -> Eff (assert :: ASSERT | e ) Unit
32- assertThrows = assertThrows' " Assertion failed: An error should have been thrown"
37+ assertThrows =
38+ assertThrows' " Assertion failed: An error should have been thrown"
3339
3440-- | Throws a runtime exception with the specified message, unless the argument
3541-- | throws an exception when evaluated.
@@ -38,9 +44,14 @@ assertThrows = assertThrows' "Assertion failed: An error should have been thrown
3844-- | to make sure that an exception is thrown if a precondition is not
3945-- | satisfied. Functions which use `Eff (err :: EXCEPTION | eff) a` can be
4046-- | tested with `catchException` instead.
41- assertThrows' :: forall e a . String -> (Unit -> a ) -> Eff (assert :: ASSERT | e ) Unit
42- assertThrows' msg fn =
43- checkThrows fn >>= assert' msg
44-
45-
46- foreign import checkThrows :: forall e a . (Unit -> a ) -> Eff (assert :: ASSERT | e ) Boolean
47+ assertThrows'
48+ :: forall e a
49+ . String
50+ -> (Unit -> a )
51+ -> Eff (assert :: ASSERT | e ) Unit
52+ assertThrows' msg fn = assert' msg =<< checkThrows fn
53+
54+ foreign import checkThrows
55+ :: forall e a
56+ . (Unit -> a )
57+ -> Eff (assert :: ASSERT | e ) Boolean
0 commit comments