prettyprinter 1.4.0 → 1.5.0
raw patch · 4 files changed
+33/−4 lines, 4 files
Files
- CHANGELOG.md +4/−2
- prettyprinter.cabal +1/−1
- src/Data/Text/Prettyprint/Doc/Internal.hs +19/−1
- test/Testsuite/Main.hs +9/−0
CHANGELOG.md view
@@ -1,9 +1,11 @@+# 1.5++- Fix inconsistent formatting within align and wide sub-docs on narrow layouts+ # 1.4 - Add fixity declaration to `<+>`, matching `<>` - Fix removal of trailing whitespace- - Keep very last newlines, Unix-style- - Do not trim leading whitespace # 1.3.0.1
prettyprinter.cabal view
@@ -1,5 +1,5 @@ name: prettyprinter-version: 1.4.0+version: 1.5.0 cabal-version: >= 1.10 category: User Interfaces, Text synopsis: A modern, easy to use, well-documented, extensible pretty-printer.
src/Data/Text/Prettyprint/Doc/Internal.hs view
@@ -1524,6 +1524,15 @@ deriving Typeable +-- | Test whether a docstream starts with a linebreak, ignoring any annotations.+startsWithLine :: SimpleDocStream ann -> Bool+startsWithLine sds = case sds of+ SLine{} -> True+ SAnnPush _ s -> startsWithLine s+ SAnnPop s -> startsWithLine s+ _ -> False++ -- $ -- >>> import qualified Data.Text.IO as T -- >>> doc = "lorem" <> hardline <> hardline <> pretty "ipsum"@@ -1785,7 +1794,16 @@ | fits pWidth minNestingLevel availableWidth x = x | otherwise = y where- minNestingLevel = min lineIndent currentColumn+ minNestingLevel =+ -- See https://github.com/quchen/prettyprinter/issues/83.+ if startsWithLine y+ -- y might be a (more compact) hanging layout. Let's check x+ -- thoroughly with the smaller lineIndent.+ then lineIndent+ -- y definitely isn't a hanging layout. Let's allow the first+ -- line of x to be checked on its own and format it consistently+ -- with subsequent lines with the same indentation.+ else currentColumn ribbonWidth = case pWidth of AvailablePerLine lineLength ribbonFraction -> (Just . max 0 . min lineLength . round)
test/Testsuite/Main.hs view
@@ -55,6 +55,7 @@ regressionLayoutSmartSoftline , testCase "alterAnnotationsS causes panic when removing annotations (#50)" regressionAlterAnnotationsS+ , testCase "Bad fallback handling with align (#83)" badFallbackAlign , testGroup "removeTrailingWhitespace removes leading whitespace (#84)" [ testCase "Text node" doNotRemoveLeadingWhitespaceText@@ -268,3 +269,11 @@ sdoc = SChar 'x' (SLine 2 (SLine 2 SEmpty)) sdoc' = SChar 'x' (SLine 0 (SLine 0 SEmpty)) in assertEqual "" sdoc' (removeTrailingWhitespace sdoc)++badFallbackAlign :: Assertion+badFallbackAlign+ = let x = group (flatAlt "Default" "Fallback")+ doc = "/" <> align (cat [x, x, "Too wide!!!!!"])+ actual = renderStrict (layoutSmart (LayoutOptions (AvailablePerLine 12 1)) doc)+ expected = "/Fallback\n Fallback\n Too wide!!!!!"+ in assertEqual "" expected actual