Skip to content

Commit bcf920c

Browse files
committed
test case for performEvent
1 parent d9f7dec commit bcf920c

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

test/RequesterT.hs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Control.Lens hiding (has)
1717
import Control.Monad
1818
import Control.Monad.Fail (MonadFail)
1919
import Control.Monad.Fix
20-
import Control.Monad.IO.Class (MonadIO, liftIO)
20+
import Control.Monad.IO.Class (MonadIO)
2121
import Control.Monad.Primitive
2222
import Data.Constraint.Extras
2323
import Data.Constraint.Extras.TH
@@ -70,6 +70,8 @@ main = do
7070
print os7
7171
os8 <- runApp' testMatchRequestsWithResponses [ Just $ TestRequest_Reverse "abcd" ]
7272
print os8
73+
os9 <- runApp' testMoribundPerformEvent $ map Just [ 1 .. 3 ]
74+
print os9
7375
let ![[Just [10,9,8,7,6,5,4,3,2,1]]] = os1
7476
let ![[Just [1,3,5,7,9]],[Nothing,Nothing],[Just [2,4,6,8,10]],[Just [2,4,6,8,10],Nothing]] = os2
7577
let ![[Nothing, Just [2]]] = os3
@@ -78,6 +80,7 @@ main = do
7880
let ![[Nothing, Nothing]] = os6 -- TODO re-enable this test after issue #233 has been resolved
7981
let !(Just [(-9223372036854775808,"2")]) = M.toList <$> head (head os7)
8082
let !(Just [(-9223372036854775808,"dcba")]) = M.toList <$> head (head os8)
83+
let ![[Nothing,Just "0:1"],[Nothing,Just "1:2"],[Nothing,Just "2:3"]] = os9
8184
return ()
8285

8386
unwrapApp :: forall t m a.
@@ -203,6 +206,11 @@ data TestRequest a where
203206
TestRequest_Reverse :: String -> TestRequest String
204207
TestRequest_Increment :: Int -> TestRequest Int
205208

209+
instance Show (TestRequest a) where
210+
show = \case
211+
TestRequest_Reverse str -> "reverse " <> str
212+
TestRequest_Increment i -> "increment " <> show i
213+
206214
testMatchRequestsWithResponses
207215
:: forall m t req a
208216
. ( MonadFix m
@@ -234,9 +242,23 @@ testMatchRequestsWithResponses pulse = mdo
234242
, \x -> has @Read r $ readMaybe x
235243
)
236244

237-
deriveArgDict ''TestRequest
245+
-- If a widget is destroyed, and simultaneously it tries to use performEvent, the event does not get performed.
246+
-- TODO Determine whether this is actually the behavior we want.
247+
testMoribundPerformEvent
248+
:: forall t m
249+
. ( Adjustable t m
250+
, PerformEvent t m
251+
, MonadHold t m
252+
, Reflex t
253+
)
254+
=> Event t Int -> m (Event t String)
255+
testMoribundPerformEvent pulse = do
256+
(outputInitial, outputReplaced) <- runWithReplace (performPrint 0 pulse) $ ffor pulse $ \i -> performPrint i pulse
257+
switchHold outputInitial outputReplaced
258+
where
259+
performPrint i evt =
260+
performEvent $ ffor evt $ \output ->
261+
return $ show i <> ":" <> show output
238262

239-
instance Show (TestRequest a) where
240-
show = \case
241-
TestRequest_Reverse str -> "reverse " <> str
242-
TestRequest_Increment i -> "increment " <> show i
263+
264+
deriveArgDict ''TestRequest

0 commit comments

Comments
 (0)