Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test suite for Adjustable #386

Merged
merged 4 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions reflex.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,21 @@ test-suite RequesterT
Reflex.Plan.Pure
Test.Run

test-suite Adjustable
default-language: Haskell2010
type: exitcode-stdio-1.0
main-is: Adjustable.hs
hs-source-dirs: test
build-depends: base
, containers
, dependent-sum
, reflex
, ref-tf
, these

other-modules:
Test.Run

test-suite QueryT
default-language: Haskell2010
type: exitcode-stdio-1.0
Expand Down
62 changes: 62 additions & 0 deletions test/Adjustable.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecursiveDo #-}

module Main where

import Control.Monad.Fix
import Data.Maybe
import qualified Data.Map as Map

import Reflex
import Reflex.EventWriter.Base
import Reflex.Network
import Reflex.Patch.MapWithMove
import Test.Run

main :: IO ()
main = do
let actions = [ Increment, Update0th, Increment, Swap, Increment, Increment ]
os <- runAppB testPatchMapWithMove $ map Just actions
-- If the final counter value in the adjusted widgets corresponds to the number of times it has
-- been incremented, we know that the networks haven't broken.
let expectedCount = length $ ffilter (== Increment) actions
-- let !True = last (last os) == [expectedCount,expectedCount] -- TODO re-enable this test after issue #369 has been resolved
return ()

data PatchMapTestAction
= Increment
| Swap
| Update0th
deriving Eq

-- See https://github.com/reflex-frp/reflex/issues/369 for the bug that this is testing.
testPatchMapWithMove
:: forall t m
. ( Reflex t
, Adjustable t m
, MonadHold t m
, MonadFix m
)
=> Event t PatchMapTestAction
-> m (Behavior t [Int])
testPatchMapWithMove pulse = do
let pulseAction = ffor pulse $ \case
Increment -> Nothing
Swap -> patchMapWithMove $ Map.fromList
[ (0, NodeInfo (From_Move 1) (Just 1))
, (1, NodeInfo (From_Move 0) (Just 0))
]
Update0th -> patchMapWithMove $ Map.fromList
[ (0, NodeInfo (From_Insert 'z') Nothing) ]
(_, result) <- runBehaviorWriterT $ mdo
counter <- foldDyn (+) 1 $ fmapMaybe (\e -> if isNothing e then Just 1 else Nothing) pulseAction
_ <- mapMapWithAdjustWithMove
(\_ _ -> networkHold
(tellBehavior $ constant [])
((\t -> tellBehavior $ constant [t]) <$> updated counter))
(Map.fromList $ zip [0..] "ab")
(fmapMaybe id pulseAction)
return ()
return result