@@ -0,0 +1,38 @@
1+module Main (main) where
2+
3+import Test.Hspec
4+
5+import Control.Applicative ((<|>))
6+--import Control.Monad.IO.Class (liftIO)
7+import Strands
8+import Data.List (sort)
9+
10+default (Int)
11+
12+main :: IO ()
13+main = hspec $ do
14+ it "Captures a return value using wait" $
15+ wait (return 0) `shouldReturn` ([0] :: [Int])
16+ it "Alternative composition of sync tasks" $
17+ wait (return 0 <|> return 1) `shouldReturn` ([0] :: [Int])
18+ it "Creates a single async thread" $
19+ wait (async $ return 0) `shouldReturn` ([0] :: [Int])
20+ it "async ignoring return value" $
21+ wait (async (return 0 :: AsyncT IO Int) >> return 1)
22+ `shouldReturn` ([1] :: [Int])
23+ it "Alternative composition of async and sync tasks" $
24+ (wait (async (return 0) <|> return 1) >>= return . sort)
25+ `shouldReturn` ([0,1] :: [Int])
26+ it "Alternative composition of async tasks" $
27+ (wait (async (return 0) <|> async (return 1)) >>= return . sort)
28+ `shouldReturn` ([0,1] :: [Int])
29+ it "Nested async tasks" $
30+ (wait $ (async $ async $ return 0)) `shouldReturn` ([0] :: [Int])
31+ it "Nested async tasks ignoring return values" $
32+ (wait $ (async $ async $ return 0 :: AsyncT IO Int) >> return 1)
33+ `shouldReturn` ([1] :: [Int])
34+ -- XXX we should run the alternative purely based on the highest level
35+ -- computation, the nested ones should not affect it.
36+ it "Nested async tasks with Alternative" $
37+ (wait (async (async $ return 0) <|> return 1) >>= return . sort)
38+ `shouldReturn` ([0,1,1] :: [Int])