1{-# LANGUAGE ConstraintKinds, GADTs, RankNTypes, FlexibleInstances, FlexibleContexts, MultiParamTypeClasses, GeneralizedNewtypeDeriving #-}
3module Reflex.Test.Micro (testCases) where
9import Control.Applicative
12import Data.Functor.Misc
16import qualified Data.Map as Map
20testCases :: [(String, TestCase)]
22 [ testB "hold" $ hold "0" =<< events1
25 b <- current <$> (count =<< events2)
26 return $ (+ (0::Int)) <$> b
29 b <- hold "0" =<< events1
30 return (id <$> id <$> b)
34 return (id <$> pull $ liftA2 (<>) (sample b1) (sample b1))
39 return (id <$> pull $ liftA2 (<>) (sample b1) (sample b2))
42 es <- planList ["a", "b", "c"]
44 b <- hold (constant "") $
45 pushAlways (const $ hold "z" es) e
56 return (tag (map toUpper <$> b1) e)
58 , testE "attach-1" $ do
61 return (attachWith (++) (map toUpper <$> b1) e)
63 , testE "leftmost" $ liftA2 leftmost2 events1 events2
65 , testE "appendEvents-1" $ liftA2 appendEvents events1 events2
67 , testE "appendEvents-2" $ liftA2 appendEvents events3 events2
69 , testE "merge-1" $ do
71 return $ leftmost ["x" <$ e, "y" <$ e]
73 , testE "merge-2" $ do
75 let m = mergeMap $ Map.fromList [(1::Int, "y" <$ e), (2, "z" <$ e)]
76 let ee = flip pushAlways e $ const $ return m
77 return $ coincidence ee
79 , testE "onceE-1" $ do
81 onceE $ leftmost [e, e]
83 , testE "onceE-2" $ do
85 b <- hold never (e <$ e)
88 , testE "switch-1" $ do
90 b <- hold never (e <$ e)
93 , testE "switch-2" $ do
95 return $ coincidence $ flip pushAlways e $ const $ do
96 switch <$> hold (leftmost ["x" <$ e, "y" <$ e, "z" <$ e]) (e <$ e)
98 , testE "switch-3" $ do
100 return $ coincidence $ flip pushAlways e $ const $ do
101 switch <$> hold (leftmost ["x" <$ e, "y" <$ e, "z" <$ e]) never
103 , testE "switch-4" $ do
105 switch <$> hold (deep e) (e <$ e)
107 , testE "switch-5" $ do
109 return $ coincidence $ flip pushAlways e $ const $
110 return $ leftmost ["x" <$ e, "y" <$ e, "z" <$ e]
112 , testE "switch-6" $ do
114 return $ coincidence $ flip pushAlways e $ const $ do
115 switch <$> hold ("x" <$ e) (e <$ e)
117 , testE "switchPromptly-1" $ do
120 switchPromptly never $ e <$ e'
122 , testE "switchPromptly-2" $ do
124 switchPromptly never $ deep (e <$ e)
126 , testE "switchPromptly-3" $ do
128 switchPromptly never $ (e <$ deep e)
130 , testE "switchPromptly-4" $ do
132 switchPromptly never $ (deep e <$ e)
134 , testE "switch-5" $ do
136 switch <$> hold never (deep e <$ e)
138 , testE "switchPromptly-5" $ do
140 switchPromptly never $ flip push e $
141 const (Just <$> onceE e)
143 , testE "switchPromptly-6" $ do
145 switchPromptly never $ flip pushAlways e $
146 const (switchPromptly e never)
148 , testE "coincidence-1" $ do
150 return $ coincidence $ flip pushAlways e $
151 const $ return (id <$> e)
153 , testE "coincidence-2" $ do
155 return $ coincidence $ flip pushAlways e $
156 const $ return (deep e)
158 , testE "coincidence-3" $ do
160 return $ coincidence $ flip pushAlways e $
161 const $ return (coincidence (e <$ e))
163 , testE "coincidence-4" $ do
165 return $ coincidence $ flip pushAlways e $
168 , testE "coincidence-5" $ do
170 return $ coincidence $ flip pushAlways e $ const $ do
172 return (coincidence (e' <$ e'))
174 , testE "coincidence-6" $ do
176 return $ coincidence $ flip pushAlways e $ const $ do
177 let e' = coincidence (e <$ e)
180 , testE "coincidence-7" $ do
182 return $ coincidence (deep e <$ e)
184 , testB "holdWhileFiring" $ do
187 bb <- hold (constant "x") $ pushAlways (const $ hold "a" eo) eo
188 return $ pull $ sample =<< sample bb
190 , testE "joinDyn" $ do
193 bd <- hold never . fmap (const e) =<< onceE e
195 eOuter <- pushAlways sample . fmap (const bb) <$> onceE e
196 let eInner = switch bd
197 return $ leftmost [eOuter, eInner]
199 , testB "foldDyn" $ do
200 d <- foldDyn (++) "0" =<< events1
203 , testB "mapDyn" $ do
204 d <- foldDyn (++) "0" =<< events1
205 current <$> mapDyn (map toUpper) d
207 , testB "combineDyn" $ do
208 d1 <- foldDyn (++) "0" =<< events1
209 d2 <- mapDyn (map toUpper) =<< foldDyn (++) "0" =<< events2
211 current <$> combineDyn (<>) d1 d2
213 e <- fmap toMap <$> events1
214 let es = select (fanMap e) . Const2 <$> values
216 return (mergeList es)
219 e <- fmap toMap <$> events3
220 let es = select (fanMap e) . Const2 <$> values
222 return (mergeList es)
225 f <- fanMap <$> fmap toMap <$> events3
226 return $ select f (Const2 'c')
229 e <- fmap toMap <$> events1
230 return $ toUpper <$> select (fanMap e) (Const2 'a')
233 e <- fmap toMap <$> events2
234 return $ toUpper <$> select (fanMap e) (Const2 'c')
237 f <- fanMap <$> fmap toMap <$> events1
238 return $ toList <$> mergeList [ select f (Const2 'b'), select f (Const2 'b'), select f (Const2 'e'), select f (Const2 'e') ]
242 events1, events2, events3 :: TestPlan t m => m (Event t String)
243 events1 = plan [(1, "a"), (2, "b"), (5, "c"), (7, "d"), (8, "e")]
244 events2 = plan [(1, "e"), (3, "d"), (4, "c"), (6, "b"), (7, "a")]
246 events3 = liftA2 appendEvents events1 events2
249 toMap str = Map.fromList $ map (\c -> (c, c)) str
251 behavior1, behavior2 :: forall t m. TestPlan t m => m (Behavior t String)
252 behavior1 = hold "1" =<< events1
253 behavior2 = hold "2" =<< events2
255 deep e = leftmost [e, e]
256 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