Skip to content
Draft
Show file tree
Hide file tree
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
10 changes: 1 addition & 9 deletions prettyprinter/src/Prettyprinter/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2073,15 +2073,7 @@ layoutWadlerLeijen
Empty -> best nl cc ds
Char c -> let !cc' = cc+1 in SChar c (best nl cc' ds)
Text l t -> let !cc' = cc+l in SText l t (best nl cc' ds)
Line -> let x = best i i ds
-- Don't produce indentation if there's no
-- following text on the same line.
-- This prevents trailing whitespace.
i' = case x of
SEmpty -> 0
SLine{} -> 0
_ -> i
in SLine i' x
Line -> SLine i (best i i ds)
FlatAlt x _ -> best nl cc (Cons i x ds)
Cat x y -> best nl cc (Cons i x (Cons i y ds))
Nest j x -> let !ij = i+j in best nl cc (Cons ij x ds)
Expand Down
20 changes: 10 additions & 10 deletions prettyprinter/test/Testsuite/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ tests = testGroup "Tests"
groupingPerformance
, testCase "fillSep performance"
fillSepPerformance
, testCase "Issue 205"
issue205
]
, testGroup "Regression tests"
[ testCase "layoutSmart: softline behaves like a newline (#49)"
Expand Down Expand Up @@ -88,8 +90,6 @@ tests = testGroup "Tests"
[ testCase "Line" regressionUnboundedGroupedLine
, testCase "Line within align" regressionUnboundedGroupedLineWithinAlign
]
, testCase "Indentation on otherwise empty lines results in trailing whitespace (#139)"
indentationShouldntCauseTrailingWhitespaceOnOtherwiseEmptyLines
, testCase "Ribbon width should be computed with `floor` instead of `round` (#157)"
computeRibbonWidthWithFloor
]
Expand Down Expand Up @@ -285,6 +285,14 @@ fillSepPerformance = docPerformanceTest (pathological 1000)
pathological :: Int -> Doc ann
pathological n = iterate (\x -> fillSep ["a", x <+> "b"] ) "foobar" !! n

issue205 :: Assertion
issue205 = do
let doc = fillSep (replicate 30 (sep ["abc", "xyz" :: Doc ()]))
t = renderStrict (layoutSmart defaultLayoutOptions doc)
timeout 1000000 (evaluate t) >>= \t' -> case t' of
Nothing -> assertFailure "Timeout!"
Just _success -> pure ()

regressionLayoutSmartSoftline :: Assertion
regressionLayoutSmartSoftline
= let doc = "a" <> softline <> "b"
Expand Down Expand Up @@ -385,14 +393,6 @@ regressionUnboundedGroupedLineWithinAlign
expected = SChar 'x' (SLine 0 (SChar 'y' SEmpty))
in assertEqual "" expected sdoc

indentationShouldntCauseTrailingWhitespaceOnOtherwiseEmptyLines :: Assertion
indentationShouldntCauseTrailingWhitespaceOnOtherwiseEmptyLines
= let doc :: Doc ()
doc = indent 1 ("x" <> hardline <> hardline <> "y" <> hardline)
sdoc = layoutPretty (LayoutOptions Unbounded) doc
expected = SChar ' ' (SChar 'x' (SLine 0 (SLine 1 (SChar 'y' (SLine 0 SEmpty)))))
in assertEqual "" expected sdoc

computeRibbonWidthWithFloor :: Assertion
computeRibbonWidthWithFloor
= let doc :: Doc ()
Expand Down
Loading