Skip to content

Commit

Permalink
Add regression tests for long function signatures. fsprojects#740
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Apr 17, 2020
1 parent 63a7137 commit f71af42
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/Fantomas.Tests/FunctionDefinitionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,77 @@ let internal UpdateStrongNaming
let UpdateStrongNamingX (assembly : AssemblyDefinition) (key : StrongNameKeyPair option) =
assembly.Name
"""

[<Test>]
let ``long function definition should put equals and body on a newline, 740`` () =
formatSourceString false """
module FormatCode =
let private format filename code config =
let checker = Fantomas.FakeHelpers.sharedChecker.Force()
let options = Fantomas.FakeHelpers.createParsingOptionsFromFile filename
let source = SourceOrigin.SourceString code
CodeFormatter.FormatDocumentAsync("tmp.fsx", source, config, options, checker)
[<FunctionName("FormatCode")>]
let run ([<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "{*any}")>] req: HttpRequest) (log: ILogger) = Http.main CodeFormatter.GetVersion format FormatConfig.FormatConfig.Default log req
""" config
|> prepend newline
|> should equal """
module FormatCode =
let private format filename code config =
let checker =
Fantomas.FakeHelpers.sharedChecker.Force()
let options =
Fantomas.FakeHelpers.createParsingOptionsFromFile filename
let source = SourceOrigin.SourceString code
CodeFormatter.FormatDocumentAsync("tmp.fsx", source, config, options, checker)
[<FunctionName("FormatCode")>]
let run
([<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "{*any}")>] req: HttpRequest)
(log: ILogger)
=
Http.main CodeFormatter.GetVersion format FormatConfig.FormatConfig.Default log req
"""

[<Test>]
let ``long function definition with return type should have multiline signature`` () =
formatSourceString false """
module FormatCode =
let private format filename code config =
let checker = Fantomas.FakeHelpers.sharedChecker.Force()
let options = Fantomas.FakeHelpers.createParsingOptionsFromFile filename
let source = SourceOrigin.SourceString code
CodeFormatter.FormatDocumentAsync("tmp.fsx", source, config, options, checker)
[<FunctionName("FormatCode")>]
let run ([<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "{*any}")>] req: HttpRequest) (log: ILogger) : HttpResponse = Http.main CodeFormatter.GetVersion format FormatConfig.FormatConfig.Default log req
""" config
|> prepend newline
|> should equal """
module FormatCode =
let private format filename code config =
let checker =
Fantomas.FakeHelpers.sharedChecker.Force()
let options =
Fantomas.FakeHelpers.createParsingOptionsFromFile filename
let source = SourceOrigin.SourceString code
CodeFormatter.FormatDocumentAsync("tmp.fsx", source, config, options, checker)
[<FunctionName("FormatCode")>]
let run
([<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "{*any}")>] req: HttpRequest)
(log: ILogger)
: HttpResponse
=
Http.main CodeFormatter.GetVersion format FormatConfig.FormatConfig.Default log req
"""

0 comments on commit f71af42

Please sign in to comment.