-
Notifications
You must be signed in to change notification settings - Fork 9
Adds test for purescript-concur-react #45 issue #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
let conf = ./spago.dhall | ||
|
||
in conf | ||
⫽ { sources = conf.sources # [ "test/**/*.purs" ] | ||
, dependencies = conf.dependencies # [ "spec" ] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Test.Main where | ||
|
||
import Prelude | ||
|
||
import Effect (Effect) | ||
import Effect.Aff (launchAff_) | ||
import Test.Spec (describe) | ||
import Test.Spec.Reporter.Console (consoleReporter) | ||
import Test.Spec.Runner (runSpec) | ||
import Test.WidgetSpec (widgetSpec) | ||
|
||
main :: Effect Unit | ||
main = launchAff_ $ runSpec [consoleReporter] do | ||
describe "Concur.Core" do | ||
widgetSpec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Test.Utils where | ||
|
||
import Prelude | ||
|
||
import Concur.Core (Widget) | ||
import Concur.Core.Types (WidgetStep(..), unWidget) | ||
import Control.Monad.Free (runFreeM) | ||
import Control.Monad.Writer.Trans (runWriterT, tell) | ||
import Data.Array (singleton) | ||
import Data.Tuple (Tuple(..)) | ||
import Effect.Aff (Aff) | ||
import Effect.Aff.Class (liftAff) | ||
import Effect.Class (liftEffect) | ||
|
||
|
||
-- Evalutates Widget to Aff | ||
-- Be carefull that never ending Widget will convert to never ending Aff. | ||
runWidgetAsAff :: forall v a. Widget v a -> Aff { result :: a, views :: Array v } | ||
runWidgetAsAff widget = do | ||
Tuple result views <- runWriterT $ runFreeM interpret (unWidget widget) | ||
pure { result, views } | ||
where | ||
interpret (WidgetStepEff eff) = | ||
liftEffect eff | ||
|
||
interpret (WidgetStepView rec) = do | ||
tell $ singleton rec.view | ||
liftAff rec.cont |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module Test.WidgetSpec where | ||
|
||
import Prelude | ||
|
||
import Concur.Core.Types (affAction) | ||
import Control.MultiAlternative (orr) | ||
import Data.Time.Duration (Milliseconds(..)) | ||
import Effect.Aff (delay, never) | ||
import Effect.Class (liftEffect) | ||
import Effect.Ref as Ref | ||
import Test.Spec (Spec, describe, it) | ||
import Test.Spec.Assertions (shouldEqual, shouldReturn) | ||
import Test.Utils (runWidgetAsAff) | ||
|
||
widgetSpec :: Spec Unit | ||
widgetSpec = | ||
describe "Widget" do | ||
describe "orr" do | ||
it "should cancel running effects when the widget returns a value" do | ||
ref <- liftEffect $ Ref.new "" | ||
{ views } <- runWidgetAsAff $ orr | ||
[ affAction "a" do | ||
delay (Milliseconds 100.0) | ||
liftEffect $ Ref.write "a" ref | ||
, affAction "b" do | ||
delay (Milliseconds 150.0) | ||
liftEffect $ Ref.write "b" ref | ||
] | ||
views `shouldEqual` [ "ab" ] | ||
liftEffect (Ref.read ref) `shouldReturn` "a" | ||
delay (Milliseconds 100.0) | ||
liftEffect (Ref.read ref) `shouldReturn` "a" | ||
|
||
it "should start all the widgets only once" do | ||
ref <- liftEffect (Ref.new 0) | ||
{ result, views } <- runWidgetAsAff $ orr | ||
[ do | ||
affAction "a0" $ delay (Milliseconds 100.0) | ||
affAction "a1" $ delay (Milliseconds 100.0) | ||
pure "a" | ||
, affAction "b" do | ||
liftEffect $ Ref.modify_ (_ + 1) ref | ||
never | ||
] | ||
result `shouldEqual` "a" | ||
views `shouldEqual` [ "a0b", "a1b" ] | ||
liftEffect (Ref.read ref) `shouldReturn` 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.