From 7dc6c525eb0a17e51446f1c3399769f37842f24e Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Tue, 7 Mar 2017 21:43:01 +0100 Subject: [PATCH] Fix minor layouting issue with long guards (see test multiple-clauses-4) --- src-literatetests/tests.blt | 49 +++++++++---------- .../Haskell/Brittany/Layouters/Decl.hs | 7 ++- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src-literatetests/tests.blt b/src-literatetests/tests.blt index 461de8b..a923d81 100644 --- a/src-literatetests/tests.blt +++ b/src-literatetests/tests.blt @@ -325,6 +325,30 @@ func (x:+:xr) = x #test simple guard func | True = x +#test multiple-clauses-1 +func x | x = simple expression + | otherwise = 0 + +#test multiple-clauses-2 +func x + | a somewhat longer guard x = "and a somewhat longer expession that does not" + | otherwise = "fit without putting the guards in new lines" + +#test multiple-clauses-3 +func x + | very long guard, another rather long guard that refers to x + = nontrivial expression foo bar alsdkjlasdjlasj + | otherwise + = 0 + +#test multiple-clauses-4 +func x + | very loooooooooooooooooooooooooooooong guard + , another rather long guard that refers to x + = nontrivial expression foo bar alsdkjlasdjlasj + | otherwise + = 0 + ############################################################################### ############################################################################### @@ -443,31 +467,6 @@ func = do stmt x -############################################################################### -############################################################################### -############################################################################### -#group equations -############################################################################### -############################################################################### -############################################################################### - -#test multiple-clauses-1 -func x | x = simple expression - | otherwise = 0 - -#test multiple-clauses-2 -func x - | a somewhat longer guard x = "and a somewhat longer expession that does not" - | otherwise = "fit without putting the guards in new lines" - -#test multiple-clauses-3 -func x - | very long guard, another rather long guard that refers to x - = nontrivial expression foo bar alsdkjlasdjlasj - | otherwise - = 0 - - ############################################################################### ############################################################################### ############################################################################### diff --git a/src/Language/Haskell/Brittany/Layouters/Decl.hs b/src/Language/Haskell/Brittany/Layouters/Decl.hs index 565869a..b5d1e87 100644 --- a/src/Language/Haskell/Brittany/Layouters/Decl.hs +++ b/src/Language/Haskell/Brittany/Layouters/Decl.hs @@ -356,9 +356,12 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs mWhereDocs = ( case guardDocs of [] -> [] [g] -> - [docSeq [appSep $ docLit $ Text.pack "|", return g]] + [ docForceSingleline + $ docSeq [appSep $ docLit $ Text.pack "|", return g] + ] gs -> - [ docSeq + [ docForceSingleline + $ docSeq $ [appSep $ docLit $ Text.pack "|"] ++ List.intersperse docCommaSep (return <$> gs) ]