Skip to content

Commit

Permalink
Add a test showing that order of patterns matters
Browse files Browse the repository at this point in the history
  • Loading branch information
dungpa committed Apr 24, 2013
1 parent c3e00a1 commit d59939e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
17 changes: 17 additions & 0 deletions src/Fantomas.Tests/PipingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,21 @@ let m =
| y -> ErrorMessage msg
| _ -> LogMessage(msg, true)
|> console.Write
"""

[<Test>]
let ``should break new lines on piping``() =
formatSourceString false """
let runAll() =
urlList
|> Seq.map fetchAsync |> Async.Parallel
|> Async.RunSynchronously |> ignore""" config
|> prepend newline
|> should equal """
let runAll() =
urlList
|> Seq.map fetchAsync
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
"""
15 changes: 8 additions & 7 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module List =
| [] | [_] -> true
| _ -> false

/// Check whether an expression should be broken into multiple lines
/// Check whether an expression should be broken into multiple lines.
/// Notice that order of patterns matter due to non-disjoint property
let rec multiline = function
| ConstExpr _
| NullExpr
Expand Down Expand Up @@ -52,6 +53,12 @@ let rec multiline = function

| Tuple es ->
List.exists multiline es

// An infix app is multiline if it contains at least two new line infix ops
| InfixApps(e, es) ->
multiline e
|| not (List.atmostOne (List.filter (fst >> NewLineInfixOps.Contains) es))
|| List.exists (snd >> multiline) es

| App(e1, es) ->
multiline e1 || List.exists multiline es
Expand All @@ -75,12 +82,6 @@ let rec multiline = function
let fields = xs |> List.choose ((|RecordFieldName|) >> snd)
not (List.atmostOne fields) || List.exists multiline fields

// An infix app is multiline if it contains at least two new line infix ops
| InfixApps(e, es) ->
multiline e
|| not (List.atmostOne (List.filter (fst >> NewLineInfixOps.Contains) es))
|| List.exists (snd >> multiline) es

// Default mode is single-line
| _ -> false

Expand Down

0 comments on commit d59939e

Please sign in to comment.