Skip to content
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

Add regression tests for long function signatures #759

Merged
merged 2 commits into from
Apr 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
"""