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
26{-# ANN testCases "HLint: ignore Functor law" #-}
27testCases :: [(String, TestCase)]
29 [ testB "hold" $ hold "0" =<< events1
32 b <- current <$> (count =<< events2)
33 return $ (+ (0::Int)) <$> b
36 b <- hold "0" =<< events1
37 return (pull $ sample $ pull $ sample b)
41 return (pull $ liftA2 (<>) (sample b1) (sample b1))
46 return (pull $ liftA2 (<>) (sample b1) (sample b2))
49 es <- planList ["a", "b", "c"]
51 b <- hold (constant "") $
52 pushAlways (const $ hold "z" es) e
58 , testE "fmap-id" $ do
70 return (tag (map toUpper <$> b1) e)
72 , testE "attach-1" $ do
75 return (attachWith (++) (map toUpper <$> b1) e)
77 , testE "leftmost" $ liftA2 leftmost2 events1 events2
79 , testE "appendEvents-1" $ liftA2 mappend events1 events2
81 , testE "appendEvents-2" $ liftA2 mappend events3 events2
83 , testE "merge-1" $ do
85 return $ leftmost ["x" <$ e, "y" <$ e]
87 , testE "merge-2" $ do
89 let m = mergeMap $ Map.fromList [(1::Int, "y" <$ e), (2, "z" <$ e)]
90 let ee = flip pushAlways e $ const $ return m
91 return $ coincidence ee
93 , testE "headE-1" $ do
95 headE $ leftmost [e, e]
97 , testE "headE-2" $ do
99 b <- hold never (e <$ e)
102 , testE "switch-1" $ do
104 b <- hold never (e <$ e)
107 , testE "switch-2" $ do
109 return $ coincidence $ flip pushAlways e $ const $ do
110 switch <$> hold (leftmost ["x" <$ e, "y" <$ e, "z" <$ e]) (e <$ e)
112 , testE "switch-3" $ do
114 return $ coincidence $ flip pushAlways e $ const $ do
115 switch <$> hold (leftmost ["x" <$ e, "y" <$ e, "z" <$ e]) never
117 , testE "switch-4" $ do
119 switch <$> hold (deep e) (e <$ e)
121 , testE "switch-5" $ do
123 return $ coincidence $ flip pushAlways e $ const $
124 return $ leftmost ["x" <$ e, "y" <$ e, "z" <$ e]
126 , testE "switch-6" $ do
128 return $ coincidence $ flip pushAlways e $ const $ do
129 switch <$> hold ("x" <$ e) (e <$ e)
131 , testE "switchPromptly-1" $ do
134 switchPromptly never $ e <$ e'
136 , testE "switchPromptly-2" $ do
138 switchPromptly never $ deep (e <$ e)
140 , testE "switchPromptly-3" $ do
142 switchPromptly never $ (e <$ deep e)
144 , testE "switchPromptly-4" $ do
146 switchPromptly never $ (deep e <$ e)
148 , testE "switch-5" $ do
150 switch <$> hold never (deep e <$ e)
152 , testE "switchPromptly-5" $ do
154 switchPromptly never $ flip push e $
155 const (Just <$> headE e)
157 , testE "switchPromptly-6" $ do
159 switchPromptly never $ flip pushAlways e $
160 const (switchPromptly e never)
162 , testE "coincidence-1" $ do
164 return $ coincidence $ flip pushAlways e $
167 , testE "coincidence-2" $ do
169 return $ coincidence $ flip pushAlways e $
170 const $ return (deep e)
172 , testE "coincidence-3" $ do
174 return $ coincidence $ flip pushAlways e $
175 const $ return (coincidence (e <$ e))
177 , testE "coincidence-4" $ do
179 return $ coincidence $ flip pushAlways e $
182 , testE "coincidence-5" $ do
184 return $ coincidence $ flip pushAlways e $ const $ do
186 return (coincidence (e' <$ e'))
188 , testE "coincidence-6" $ do
190 return $ coincidence $ flip pushAlways e $ const $ do
191 let e' = coincidence (e <$ e)
194 , testE "coincidence-7" $ do
196 return $ coincidence (deep e <$ e)
198 , testB "holdWhileFiring" $ do
201 bb <- hold (constant "x") $ pushAlways (const $ hold "a" eo) eo
202 return $ pull $ sample =<< sample bb
204 , testE "joinDyn" $ do
207 bd <- hold never . fmap (const e) =<< headE e
209 eOuter <- pushAlways sample . fmap (const bb) <$> headE e
210 let eInner = switch bd
211 return $ leftmost [eOuter, eInner]
213 , testB "foldDyn" $ do
214 d <- foldDyn (++) "0" =<< events1
217 , testB "mapDyn" $ do
218 d <- foldDyn (++) "0" =<< events1
219 return $ current $ fmap (map toUpper) d
221 , testB "combineDyn" $ do
222 d1 <- foldDyn (++) "0" =<< events1
223 d2 <- fmap (fmap (map toUpper)) $ foldDyn (++) "0" =<< events2
225 return $ current $ zipDynWith (<>) d1 d2
227 e <- fmap toMap <$> events1
228 let es = select (fanMap e) . Const2 <$> values
230 return (mergeList es)
233 e <- fmap toMap <$> events3
234 let es = select (fanMap e) . Const2 <$> values
236 return (mergeList es)
239 f <- fanMap . fmap toMap <$> events3
240 return $ select f (Const2 'c')
243 e <- fmap toMap <$> events1
244 return $ toUpper <$> select (fanMap e) (Const2 'a')
247 e <- fmap toMap <$> events2
248 return $ toUpper <$> select (fanMap e) (Const2 'c')
251 f <- fanMap . fmap toMap <$> events1
252 return $ toList <$> mergeList [ select f (Const2 'b'), select f (Const2 'b'), select f (Const2 'e'), select f (Const2 'e') ]
254 , testE "difference" $ do
257 return $ e1 `difference ` e2
259 , testE "lazy-hold" $ do
260 let lazyHold :: forall t m. (Reflex t, MonadHold t m, MonadFix m) => m (Event t ())
262 rec !b <- hold never e
263 let e = never <$ switch b
269 events1, events2, events3 :: TestPlan t m => m (Event t String)
270 events1 = plan [(1, "a"), (2, "b"), (5, "c"), (7, "d"), (8, "e")]
271 events2 = plan [(1, "e"), (3, "d"), (4, "c"), (6, "b"), (7, "a")]
273 events3 = liftA2 mappend events1 events2
276 toMap str = Map.fromList $ map (\c -> (c, c)) str
278 behavior1, behavior2 :: forall t m. TestPlan t m => m (Behavior t String)
279 behavior1 = hold "1" =<< events1
280 behavior2 = hold "2" =<< events2
282 deep e = leftmost [e, e]
283 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