forked from suhailshergill/extensible-effects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.hs
53 lines (44 loc) · 1.58 KB
/
Test.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{-# LANGUAGE FlexibleContexts, AllowAmbiguousTypes #-}
{-# LANGUAGE TemplateHaskell #-}
module Control.Eff.Example.Test (testGroups, ex2) where
import Test.HUnit hiding (State)
import Test.QuickCheck
import Test.Framework.TH
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2
import Control.Eff
import Control.Eff.Example
import Control.Eff.Exception
import Control.Eff.Reader.Lazy
import Control.Eff.Writer.Lazy
import Control.Eff.State.Lazy
import Utils
testGroups = [ $(testGroupGenerator) ]
-- The type is inferred
-- ex2 :: Member (Exc TooBig) r => Eff r Int -> Eff r Int
ex2 m = do
v <- m
if v > 5 then throwError (TooBig v)
else return v
case_Exception1_ex2r :: Assertion
case_Exception1_ex2r = (Right 5) @=? (run ex2r)
where
ex2r = runReader (runErrBig (ex2 ask)) (5::Int)
case_Exception1_ex2r1 :: Assertion
case_Exception1_ex2r1 = (Left (TooBig 7)) @=? (run ex2r1)
where
ex2r1 = runReader (runErrBig (ex2 ask)) (7::Int)
-- Different order of handlers (layers)
case_Exception1_ex2r2 :: Assertion
case_Exception1_ex2r2 = (Left (TooBig 7)) @=? (run ex2r2)
where
ex2r2 = runErrBig (runReader (ex2 ask) (7::Int))
prop_Documentation_example :: [Integer] -> Property
prop_Documentation_example l = let
((), total1) = run $ runState (sumAll l) 0
((), last1) = run $ runLastWriter $ writeAll l
(((), last2), total2) = run $ runState (runLastWriter (writeAndAdd l)) 0
(((), total3), last3) = run $ runLastWriter $ runState (writeAndAdd l) 0
in
allEqual [safeLast l, last1, last2, last3]
.&&. allEqual [sum l, total1, total2, total3]