Skip to content

Commit 94f1d3b

Browse files
committed
WIP test case for performEvent
1 parent d9f7dec commit 94f1d3b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

test/RequesterT.hs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -203,6 +205,11 @@ data TestRequest a where
203205
TestRequest_Reverse :: String -> TestRequest String
204206
TestRequest_Increment :: Int -> TestRequest Int
205207

208+
instance Show (TestRequest a) where
209+
show = \case
210+
TestRequest_Reverse str -> "reverse " <> str
211+
TestRequest_Increment i -> "increment " <> show i
212+
206213
testMatchRequestsWithResponses
207214
:: forall m t req a
208215
. ( MonadFix m
@@ -234,9 +241,17 @@ testMatchRequestsWithResponses pulse = mdo
234241
, \x -> has @Read r $ readMaybe x
235242
)
236243

237-
deriveArgDict ''TestRequest
244+
-- If a widget is destroyed, and simultaneously it tries to use performEvent, the event shouldn't be performed.
245+
testMoribundPerformEvent
246+
:: ( Adjustable t m
247+
, PerformEvent t m
248+
, MonadIO (Performable m)
249+
)
250+
=> Event t Int -> m (Event t ())
251+
testMoribundPerformEvent pulse = do
252+
runWithReplace (performEvent $ liftIO . print <$> pulse) $ ffor pulse $ \i -> do
253+
performEvent $ liftIO . print <$> pulse
254+
pure ()
255+
pure never
238256

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

0 commit comments

Comments
 (0)