11module Test.Main where
22
33import Prelude
4+ import Data.Maybe (Maybe (..))
45import Effect (Effect )
5- import Effect.Aff (launchAff_ )
6+ import Effect.Aff (Milliseconds (..), delay , launchAff_ )
67import Effect.Class (liftEffect )
78import Effect.Ref as Ref
8- import React.Halo (Lifecycle (..), modify_ )
9+ import React.Halo (liftAff )
10+ import React.Halo as Halo
911import React.Halo.Internal.Eval as Eval
1012import React.Halo.Internal.State as State
1113import Test.Spec (Spec , describe , it )
@@ -44,7 +46,7 @@ runPropsTests = do
4446 count <- Ref .new 0
4547 let
4648 eval = case _ of
47- Update _ _ -> liftEffect $ Ref .modify_ (add 1 ) count
49+ Halo. Update _ _ -> liftEffect $ Ref .modify_ (add 1 ) count
4850 _ -> pure unit
4951
5052 initialProps = { value: " " }
@@ -63,7 +65,7 @@ runStateTests = do
6365 value <- read
6466 value `shouldEqual` { value: " first test" }
6567 expect 2
66- it " does not modify the state when the reference does not change " do
68+ it " does not modify the state when the reference has not changed " do
6769 { modify, expect, read } <- makeState { value: " " }
6870 modify identity
6971 value <- read
@@ -84,7 +86,7 @@ runStateTests = do
8486 expect x = liftEffect (Ref .read count) >>= shouldEqual x
8587
8688 eval = case _ of
87- Action f -> modify_ f
89+ Halo. Action f -> Halo . modify_ f
8890 _ -> pure unit
8991 state <- State .createInitialState { props: unit, initialState, eval, update }
9092 Eval .runInitialize state
@@ -96,7 +98,36 @@ runSubscriptionTests :: Spec Unit
9698runSubscriptionTests = pure unit
9799
98100runParallelismTests :: Spec Unit
99- runParallelismTests = pure unit
101+ runParallelismTests = do
102+ it " should run logic in parallel" do
103+ state <-
104+ liftEffect do
105+ internalState <- Ref .new Nothing
106+ state <-
107+ State .createInitialState
108+ { props: unit
109+ , initialState: 0
110+ , update: \x -> Ref .write (Just x) internalState
111+ , eval:
112+ \_ -> do
113+ c <-
114+ Halo .sequential ado
115+ a <-
116+ Halo .parallel do
117+ liftAff $ delay $ Milliseconds 1_000 .0
118+ pure 1
119+ b <-
120+ Halo .parallel do
121+ liftAff $ delay $ Milliseconds 1_000 .0
122+ pure 2
123+ in a + b
124+ Halo .put c
125+ }
126+ Eval .runInitialize state
127+ pure internalState
128+ delay $ Milliseconds 1_100 .0
129+ c <- liftEffect $ Ref .read state
130+ c `shouldEqual` (Just 3 )
100131
101132runForkingTests :: Spec Unit
102133runForkingTests = pure unit
0 commit comments