Skip to content

Commit

Permalink
Added Elmish View test
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Sep 13, 2019
1 parent 2f9a9b0 commit 5e5d28b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 4 deletions.
73 changes: 73 additions & 0 deletions src/Fantomas.Tests/ElmishTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,77 @@ let view (model: Model) dispatch =
(appearing = (fun () -> dispatch PageAppearing), title = model.Planet.Info.Name, backgroundColor = Color.Black,
content =
[ "....long line....................................................................................................." ])
"""

[<Test>]
let ``fabulous view`` () =
formatSourceString false """
let loginPage =
View.ContentPage(
title = "Fabulous Demo",
content = View.ScrollView(
content = View.StackLayout(
padding = 30.0,
children = [
View.Frame(
verticalOptions = LayoutOptions.CenterAndExpand,
content = View.StackLayout(children = [
View.Entry(
placeholder = "User name",
isEnabled = (not model.IsSigningIn),
textChanged = (fun args -> (dispatch (UserNameChanged args.NewTextValue))))
View.Entry(
placeholder = "Password",
isPassword = true,
isEnabled = (not model.IsSigningIn),
textChanged = (fun args -> (dispatch (PasswordChanged args.NewTextValue))))
View.Button(
text = "Sign in",
heightRequest = 30.0,
isVisible = (not model.IsSigningIn),
command = (fun () -> dispatch SignIn),
canExecute = model.IsCredentialsProvided)
View.ActivityIndicator(
isRunning = true,
heightRequest = 30.0,
isVisible = model.IsSigningIn)])
)
]
)
)
)
""" config
|> prepend newline
|> should equal """
let loginPage =
View.ContentPage
(title = "Fabulous Demo",
content =
View.ScrollView
(content =
View.StackLayout
(padding = 30.0,
children =
[ View.Frame
(verticalOptions = LayoutOptions.CenterAndExpand,
content =
View.StackLayout
(children =
[ View.Entry
(placeholder = "User name", isEnabled = (not model.IsSigningIn),
textChanged =
(fun args -> (dispatch (UserNameChanged args.NewTextValue))))
View.Entry
(placeholder = "Password", isPassword = true,
isEnabled = (not model.IsSigningIn),
textChanged =
(fun args -> (dispatch (PasswordChanged args.NewTextValue))))
View.Button
(text = "Sign in", heightRequest = 30.0,
isVisible = (not model.IsSigningIn),
command = (fun () -> dispatch SignIn),
canExecute = model.IsCredentialsProvided)
View.ActivityIndicator
(isRunning = true, heightRequest = 30.0,
isVisible = model.IsSigningIn) ])) ])))
"""
10 changes: 6 additions & 4 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,12 +1141,14 @@ and genInfixApps astContext hasNewLine synExprs =
| (s, opE, e)::es when (NoBreakInfixOps.Contains s) ->
(sepSpace +> tok opE.Range s
+> (fun ctx ->
let futureNln = futureNlnCheck (genExpr astContext e) ctx
let genExpr =
let isEqualOperator =
match opE with
| SynExpr.Ident(Ident("op_Equality")) when(futureNln) ->
| SynExpr.Ident(Ident("op_Equality")) -> true
| _ -> false
let genExpr =
if isEqualOperator && (futureNlnCheck (genExpr astContext e) ctx) then
indent +> sepNln +> genExpr astContext e +> unindent
| _ ->
else
sepSpace +> genExpr astContext e
genExpr ctx))
+> genInfixApps astContext (hasNewLine || checkNewLine e es) es
Expand Down

0 comments on commit 5e5d28b

Please sign in to comment.