Skip to content

Commit

Permalink
Add regression test for define above SynExpr.Do. (#1491)
Browse files Browse the repository at this point in the history
Fixes #1333.
  • Loading branch information
nojaf authored Feb 26, 2021
1 parent 69c30df commit 3cafac5
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/Fantomas.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2244,3 +2244,65 @@ let loader (projectRoot: string) (siteContent: SiteContents) =
#endif
disableLiveRefresh
"""

[<Test>]
let ``directive above SynExpr.Do, 1333`` () =
formatSourceString
false
"""
[<AutoOpen>]
module ReactHookExtensions =
type React with
[<Hook>]
static member useDeferred(operation: Async<'T>, dependencies: obj array) =
let (deferred, setDeferred) = React.useState(Deferred.HasNotStartedYet)
let token = React.useCancellationToken()
let executeOperation = async {
try
do setDeferred(Deferred<'T>.InProgress)
let! output = operation
do setDeferred(Deferred<'T>.Resolved output)
with error ->
#if DEBUG
Browser.Dom.console.log(error)
#endif
do setDeferred(Deferred<'T>.Failed error)
}
React.useEffect((fun () -> Async.StartImmediate(executeOperation, token.current)), dependencies)
deferred
"""
config
|> prepend newline
|> should
equal
"""
[<AutoOpen>]
module ReactHookExtensions =
type React with
[<Hook>]
static member useDeferred(operation: Async<'T>, dependencies: obj array) =
let (deferred, setDeferred) =
React.useState (Deferred.HasNotStartedYet)
let token = React.useCancellationToken ()
let executeOperation =
async {
try
do setDeferred (Deferred<'T>.InProgress)
let! output = operation
do setDeferred (Deferred<'T>.Resolved output)
with error ->
#if DEBUG
Browser.Dom.console.log (error)
#endif
do setDeferred (Deferred<'T>.Failed error)
}
React.useEffect ((fun () -> Async.StartImmediate(executeOperation, token.current)), dependencies)
deferred
"""

0 comments on commit 3cafac5

Please sign in to comment.