1{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE RankNTypes #-}
8module Reflex.Test.Micro (testCases) where
13import Control.Applicative
16import Data.Functor.Misc
21import qualified Data.Map as Map
25testCases :: [(String, TestCase)]
27 [ testB "hold" $ hold "0" =<< events1
30 b <- current <$> (count =<< events2)
31 return $ (+ (0::Int)) <$> b
34 b <- hold "0" =<< events1
35 return (pull $ sample $ pull $ sample b)
39 return (pull $ liftA2 (<>) (sample b1) (sample b1))
44 return (pull $ liftA2 (<>) (sample b1) (sample b2))
47 es <- planList ["a", "b", "c"]
49 b <- hold (constant "") $
50 pushAlways (const $ hold "z" es) e
61 return (tag (map toUpper <$> b1) e)
63 , testE "attach-1" $ do
66 return (attachWith (++) (map toUpper <$> b1) e)
68 , testE "leftmost" $ liftA2 leftmost2 events1 events2
70 , testE "appendEvents-1" $ liftA2 mappend events1 events2
72 , testE "appendEvents-2" $ liftA2 mappend events3 events2
74 , testE "merge-1" $ do
76 return $ leftmost ["x" <$ e, "y" <$ e]
78 , testE "merge-2" $ do
80 let m = mergeMap $ Map.fromList [(1::Int, "y" <$ e), (2, "z" <$ e)]
81 let ee = flip pushAlways e $ const $ return m
82 return $ coincidence ee
84 , testE "headE-1" $ do
86 headE $ leftmost [e, e]
88 , testE "headE-2" $ do
90 b <- hold never (e <$ e)
93 , testE "switch-1" $ do
95 b <- hold never (e <$ e)
98 , testE "switch-2" $ do
100 return $ coincidence $ flip pushAlways e $ const $ do
101 switch <$> hold (leftmost ["x" <$ e, "y" <$ e, "z" <$ e]) (e <$ e)
103 , testE "switch-3" $ do
105 return $ coincidence $ flip pushAlways e $ const $ do
106 switch <$> hold (leftmost ["x" <$ e, "y" <$ e, "z" <$ e]) never
108 , testE "switch-4" $ do
110 switch <$> hold (deep e) (e <$ e)
112 , testE "switch-5" $ do
114 return $ coincidence $ flip pushAlways e $ const $
115 return $ leftmost ["x" <$ e, "y" <$ e, "z" <$ e]
117 , testE "switch-6" $ do
119 return $ coincidence $ flip pushAlways e $ const $ do
120 switch <$> hold ("x" <$ e) (e <$ e)
122 , testE "switchPromptly-1" $ do
125 switchPromptly never $ e <$ e'
127 , testE "switchPromptly-2" $ do
129 switchPromptly never $ deep (e <$ e)
131 , testE "switchPromptly-3" $ do
133 switchPromptly never $ (e <$ deep e)
135 , testE "switchPromptly-4" $ do
137 switchPromptly never $ (deep e <$ e)
139 , testE "switch-5" $ do
141 switch <$> hold never (deep e <$ e)
143 , testE "switchPromptly-5" $ do
145 switchPromptly never $ flip push e $
146 const (Just <$> headE e)
148 , testE "switchPromptly-6" $ do
150 switchPromptly never $ flip pushAlways e $
151 const (switchPromptly e never)
153 , testE "coincidence-1" $ do
155 return $ coincidence $ flip pushAlways e $
158 , testE "coincidence-2" $ do
160 return $ coincidence $ flip pushAlways e $
161 const $ return (deep e)
163 , testE "coincidence-3" $ do
165 return $ coincidence $ flip pushAlways e $
166 const $ return (coincidence (e <$ e))
168 , testE "coincidence-4" $ do
170 return $ coincidence $ flip pushAlways e $
173 , testE "coincidence-5" $ do
175 return $ coincidence $ flip pushAlways e $ const $ do
177 return (coincidence (e' <$ e'))
179 , testE "coincidence-6" $ do
181 return $ coincidence $ flip pushAlways e $ const $ do
182 let e' = coincidence (e <$ e)
185 , testE "coincidence-7" $ do
187 return $ coincidence (deep e <$ e)
189 , testB "holdWhileFiring" $ do
192 bb <- hold (constant "x") $ pushAlways (const $ hold "a" eo) eo
193 return $ pull $ sample =<< sample bb
195 , testE "joinDyn" $ do
198 bd <- hold never . fmap (const e) =<< headE e
200 eOuter <- pushAlways sample . fmap (const bb) <$> headE e
201 let eInner = switch bd
202 return $ leftmost [eOuter, eInner]
204 , testB "foldDyn" $ do
205 d <- foldDyn (++) "0" =<< events1
208 , testB "mapDyn" $ do
209 d <- foldDyn (++) "0" =<< events1
210 return $ current $ fmap (map toUpper) d
212 , testB "combineDyn" $ do
213 d1 <- foldDyn (++) "0" =<< events1
214 d2 <- fmap (fmap (map toUpper)) $ foldDyn (++) "0" =<< events2
216 return $ current $ zipDynWith (<>) d1 d2
218 e <- fmap toMap <$> events1
219 let es = select (fanMap e) . Const2 <$> values
221 return (mergeList es)
224 e <- fmap toMap <$> events3
225 let es = select (fanMap e) . Const2 <$> values
227 return (mergeList es)
230 f <- fanMap . fmap toMap <$> events3
231 return $ select f (Const2 'c')
234 e <- fmap toMap <$> events1
235 return $ toUpper <$> select (fanMap e) (Const2 'a')
238 e <- fmap toMap <$> events2
239 return $ toUpper <$> select (fanMap e) (Const2 'c')
242 f <- fanMap . fmap toMap <$> events1
243 return $ toList <$> mergeList [ select f (Const2 'b'), select f (Const2 'b'), select f (Const2 'e'), select f (Const2 'e') ]
247 events1, events2, events3 :: TestPlan t m => m (Event t String)
248 events1 = plan [(1, "a"), (2, "b"), (5, "c"), (7, "d"), (8, "e")]
249 events2 = plan [(1, "e"), (3, "d"), (4, "c"), (6, "b"), (7, "a")]
251 events3 = liftA2 mappend events1 events2
254 toMap str = Map.fromList $ map (\c -> (c, c)) str
256 behavior1, behavior2 :: forall t m. TestPlan t m => m (Behavior t String)
257 behavior1 = hold "1" =<< events1
258 behavior2 = hold "2" =<< events2
260 deep e = leftmost [e, e]
261 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