1{-# LANGUAGE BangPatterns #-}
2{-# LANGUAGE ConstraintKinds #-}
3{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleInstances #-}
6{-# LANGUAGE MultiParamTypeClasses #-}
7{-# LANGUAGE RankNTypes #-}
8{-# LANGUAGE RecursiveDo #-}
10module Reflex.Test.Micro (testCases) where
15import Control.Applicative
17import Control.Monad.Fix
20import Data.Functor.Misc
21import qualified Data.Map as Map
26testCases :: [(String, TestCase)]
28 [ testB "hold" $ hold "0" =<< events1
31 b <- current <$> (count =<< events2)
32 return $ (+ (0::Int)) <$> b
35 b <- hold "0" =<< events1
36 return (pull $ sample $ pull $ sample b)
40 return (pull $ liftA2 (<>) (sample b1) (sample b1))
45 return (pull $ liftA2 (<>) (sample b1) (sample b2))
48 es <- planList ["a", "b", "c"]
50 b <- hold (constant "") $
51 pushAlways (const $ hold "z" es) e
57 , testE "fmap-id" $ do
69 return (tag (map toUpper <$> b1) e)
71 , testE "attach-1" $ do
74 return (attachWith (++) (map toUpper <$> b1) e)
76 , testE "leftmost" $ liftA2 leftmost2 events1 events2
78 , testE "appendEvents-1" $ liftA2 mappend events1 events2
80 , testE "appendEvents-2" $ liftA2 mappend events3 events2
82 , testE "merge-1" $ do
84 return $ leftmost ["x" <$ e, "y" <$ e]
86 , testE "merge-2" $ do
88 let m = mergeMap $ Map.fromList [(1::Int, "y" <$ e), (2, "z" <$ e)]
89 let ee = flip pushAlways e $ const $ return m
90 return $ coincidence ee
92 , testE "headE-1" $ do
94 headE $ leftmost [e, e]
96 , testE "headE-2" $ do
98 b <- hold never (e <$ e)
101 , testE "switch-1" $ do
103 b <- hold never (e <$ e)
106 , testE "switch-2" $ do
108 return $ coincidence $ flip pushAlways e $ const $ do
109 switch <$> hold (leftmost ["x" <$ e, "y" <$ e, "z" <$ e]) (e <$ e)
111 , testE "switch-3" $ do
113 return $ coincidence $ flip pushAlways e $ const $ do
114 switch <$> hold (leftmost ["x" <$ e, "y" <$ e, "z" <$ e]) never
116 , testE "switch-4" $ do
118 switch <$> hold (deep e) (e <$ e)
120 , testE "switch-5" $ do
122 return $ coincidence $ flip pushAlways e $ const $
123 return $ leftmost ["x" <$ e, "y" <$ e, "z" <$ e]
125 , testE "switch-6" $ do
127 return $ coincidence $ flip pushAlways e $ const $ do
128 switch <$> hold ("x" <$ e) (e <$ e)
130 , testE "switchPromptly-1" $ do
133 switchPromptly never $ e <$ e'
135 , testE "switchPromptly-2" $ do
137 switchPromptly never $ deep (e <$ e)
139 , testE "switchPromptly-3" $ do
141 switchPromptly never $ (e <$ deep e)
143 , testE "switchPromptly-4" $ do
145 switchPromptly never $ (deep e <$ e)
147 , testE "switch-5" $ do
149 switch <$> hold never (deep e <$ e)
151 , testE "switchPromptly-5" $ do
153 switchPromptly never $ flip push e $
154 const (Just <$> headE e)
156 , testE "switchPromptly-6" $ do
158 switchPromptly never $ flip pushAlways e $
159 const (switchPromptly e never)
161 , testE "coincidence-1" $ do
163 return $ coincidence $ flip pushAlways e $
166 , testE "coincidence-2" $ do
168 return $ coincidence $ flip pushAlways e $
169 const $ return (deep e)
171 , testE "coincidence-3" $ do
173 return $ coincidence $ flip pushAlways e $
174 const $ return (coincidence (e <$ e))
176 , testE "coincidence-4" $ do
178 return $ coincidence $ flip pushAlways e $
181 , testE "coincidence-5" $ do
183 return $ coincidence $ flip pushAlways e $ const $ do
185 return (coincidence (e' <$ e'))
187 , testE "coincidence-6" $ do
189 return $ coincidence $ flip pushAlways e $ const $ do
190 let e' = coincidence (e <$ e)
193 , testE "coincidence-7" $ do
195 return $ coincidence (deep e <$ e)
197 , testB "holdWhileFiring" $ do
200 bb <- hold (constant "x") $ pushAlways (const $ hold "a" eo) eo
201 return $ pull $ sample =<< sample bb
203 , testE "joinDyn" $ do
206 bd <- hold never . fmap (const e) =<< headE e
208 eOuter <- pushAlways sample . fmap (const bb) <$> headE e
209 let eInner = switch bd
210 return $ leftmost [eOuter, eInner]
212 , testB "foldDyn" $ do
213 d <- foldDyn (++) "0" =<< events1
216 , testB "mapDyn" $ do
217 d <- foldDyn (++) "0" =<< events1
218 return $ current $ fmap (map toUpper) d
220 , testB "combineDyn" $ do
221 d1 <- foldDyn (++) "0" =<< events1
222 d2 <- fmap (fmap (map toUpper)) $ foldDyn (++) "0" =<< events2
224 return $ current $ zipDynWith (<>) d1 d2
226 e <- fmap toMap <$> events1
227 let es = select (fanMap e) . Const2 <$> values
229 return (mergeList es)
232 e <- fmap toMap <$> events3
233 let es = select (fanMap e) . Const2 <$> values
235 return (mergeList es)
238 f <- fanMap . fmap toMap <$> events3
239 return $ select f (Const2 'c')
242 e <- fmap toMap <$> events1
243 return $ toUpper <$> select (fanMap e) (Const2 'a')
246 e <- fmap toMap <$> events2
247 return $ toUpper <$> select (fanMap e) (Const2 'c')
250 f <- fanMap . fmap toMap <$> events1
251 return $ toList <$> mergeList [ select f (Const2 'b'), select f (Const2 'b'), select f (Const2 'e'), select f (Const2 'e') ]
253 , testE "lazy-hold" $ do
254 let lazyHold :: forall t m. (Reflex t, MonadHold t m, MonadFix m) => m (Event t ())
256 rec !b <- hold never e
257 let e = never <$ switch b
263 events1, events2, events3 :: TestPlan t m => m (Event t String)
264 events1 = plan [(1, "a"), (2, "b"), (5, "c"), (7, "d"), (8, "e")]
265 events2 = plan [(1, "e"), (3, "d"), (4, "c"), (6, "b"), (7, "a")]
267 events3 = liftA2 mappend events1 events2
270 toMap str = Map.fromList $ map (\c -> (c, c)) str
272 behavior1, behavior2 :: forall t m. TestPlan t m => m (Behavior t String)
273 behavior1 = hold "1" =<< events1
274 behavior2 = hold "2" =<< events2
276 deep e = leftmost [e, e]
277 leftmost2 e1 e2 = leftmost [e1, e2]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list