Skip to content

Commit baadc4c

Browse files
committed
Add tests showing RequesterT/EventWriterT inconsistency
Issue #233
1 parent 6331936 commit baadc4c

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

test/EventWriterT.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BangPatterns #-}
12
{-# LANGUAGE FlexibleContexts #-}
23
{-# LANGUAGE GADTs #-}
34
{-# LANGUAGE RecursiveDo #-}
@@ -36,6 +37,9 @@ main = do
3637
print os4
3738
os5@[[Nothing, Just [1, 2]]] <- runApp' (unwrapApp testLiveTellEventDMap) [Just ()]
3839
print os5
40+
os6 <- runApp' (unwrapApp delayedPulse) [Just ()]
41+
print os6
42+
let ![[Nothing, Nothing]] = os6
3943
return ()
4044

4145
unwrapApp :: (Reflex t, Monad m) => (a -> EventWriterT t [Int] m ()) -> a -> m (Event t [Int])
@@ -112,3 +116,17 @@ testLiveTellEventDMap pulse = do
112116
(mapToDMap $ M.singleton 1 ())
113117
((PatchDMap $ DMap.map (ComposeMaybe . Just) $ mapToDMap $ M.singleton 2 ()) <$ pulse)
114118
return ()
119+
120+
delayedPulse
121+
:: forall t m
122+
. ( Reflex t
123+
, Adjustable t m
124+
, MonadHold t m
125+
, MonadFix m
126+
)
127+
=> Event t ()
128+
-> EventWriterT t [Int] m ()
129+
delayedPulse pulse = void $ flip runWithReplace (pure () <$ pulse) $ do
130+
-- This has the effect of delaying pulse' from pulse
131+
(_, pulse') <- runWithReplace (pure ()) $ pure [1] <$ pulse
132+
tellEvent pulse'

test/RequesterT.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ main = do
4242
print os4
4343
os5 <- runApp' (unwrapApp testLiveRequestDMap) [Just ()]
4444
print os5
45+
os6 <- runApp' (unwrapApp delayedPulse) [Just ()]
46+
print os6
4547
let ![[Just [10,9,8,7,6,5,4,3,2,1]]] = os1
4648
let ![[Just [1,3,5,7,9]],[Nothing,Nothing],[Just [2,4,6,8,10]],[Just [2,4,6,8,10],Nothing]] = os2
4749
let ![[Nothing, Just [2]]] = os3
4850
let ![[Nothing, Just [2]]] = os4
4951
let ![[Nothing, Just [1, 2]]] = os5
52+
let ![[Nothing, Nothing]] = os6
5053
return ()
5154

5255
unwrapRequest :: DSum tag RequestInt -> Int
@@ -146,3 +149,21 @@ testLiveRequestDMap pulse = do
146149
(mapToDMap $ M.singleton 1 ())
147150
((PatchDMap $ DMap.map (ComposeMaybe . Just) $ mapToDMap $ M.singleton 2 ()) <$ pulse)
148151
return ()
152+
153+
delayedPulse
154+
:: forall t m
155+
. ( Reflex t
156+
, Adjustable t m
157+
, MonadHold t m
158+
, MonadFix m
159+
, Response m ~ Identity
160+
, Request m ~ RequestInt
161+
, PerformEvent t m
162+
, Requester t m
163+
)
164+
=> Event t ()
165+
-> m ()
166+
delayedPulse pulse = void $ flip runWithReplace (pure () <$ pulse) $ do
167+
-- This has the effect of delaying pulse' from pulse
168+
(_, pulse') <- runWithReplace (pure ()) $ pure (RequestInt 1) <$ pulse
169+
requestingIdentity pulse'

0 commit comments

Comments
 (0)