packages feed

prettyprinter 1.1.1 → 1.2

raw patch · 4 files changed

+34/−16 lines, 4 files

Files

prettyprinter.cabal view
@@ -1,5 +1,5 @@ name:                prettyprinter-version:             1.1.1+version:             1.2 cabal-version:       >= 1.10 category:            User Interfaces, Text synopsis:            A modern, easy to use, well-documented, extensible prettyprinter.@@ -62,9 +62,9 @@      if impl(ghc >= 8.0)         ghc-options: -Wcompat-    if impl(ghc < 8.0)+    if !impl(ghc >= 8.0)         build-depends: semigroups >= 0.1-    if impl(ghc < 7.10)+    if !impl(ghc >= 7.10)         build-depends: void  @@ -124,7 +124,7 @@     ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall     default-language: Haskell2010 -    if impl(ghc < 8.0)+    if !impl(ghc >= 8.0)         build-depends: semigroups >= 0.6  
src/Data/Text/Prettyprint/Doc.hs view
@@ -178,6 +178,7 @@      -- * Basic functionality     Pretty(..),+    viaShow, unsafeViaShow,     emptyDoc, nest, line, line', softline, softline', hardline, group, flatAlt,      -- * Alignment functions
src/Data/Text/Prettyprint/Doc/Internal.hs view
@@ -235,13 +235,14 @@      prettyList = pretty . (id :: Text -> Text) . fromString --- | Convert a 'Show'able value to a 'Doc'. If the 'String' does not contain--- newlines, consider using the more performant 'unsafeViaShow'.+-- | Convenience function to convert a 'Show'able value to a 'Doc'. If the+-- 'String' does not contain newlines, consider using the more performant+-- 'unsafeViaShow'. viaShow :: Show a => a -> Doc ann viaShow = pretty . T.pack . show --- | Convert a 'Show'able value /that must not contain newlines/ to a 'Doc'.--- If there may be newlines, use 'viaShow' instead.+-- | Convenience function to convert a 'Show'able value /that must not contain+-- newlines/ to a 'Doc'. If there may be newlines, use 'viaShow' instead. unsafeViaShow :: Show a => a -> Doc ann unsafeViaShow = unsafeTextWithoutNewlines . T.pack . show @@ -576,7 +577,7 @@ -- >>> let open        = flatAlt "" "{ " -- >>> let close       = flatAlt "" " }" -- >>> let separator   = flatAlt "" "; "--- >>> let prettyDo xs = group ("do" <+> encloseSep open close separator xs)+-- >>> let prettyDo xs = group ("do" <+> align (encloseSep open close separator xs)) -- >>> let statements  = ["name:_ <- getArgs", "let greet = \"Hello, \" <> name", "putStrLn greet"] -- -- This is put into a single line with @{;}@ style if it fits,@@ -671,12 +672,12 @@ -- -- The documents are laid out horizontally if that fits the page, ----- >>> let doc = "list" <+> encloseSep lbracket rbracket comma (map pretty [1,20,300,4000])+-- >>> let doc = "list" <+> align (encloseSep lbracket rbracket comma (map pretty [1,20,300,4000])) -- >>> putDocW 80 doc -- list [1,20,300,4000] -- -- If there is not enough space, then the input is split into lines entry-wise--- therwise they are aligned vertically, with separators put in the front:+-- therwise they are laid out vertically, with separators put in the front: -- -- >>> putDocW 10 doc -- list [1@@ -684,6 +685,9 @@ --      ,300 --      ,4000] --+-- Note that @doc@ contains an explicit call to 'align' so that the list items+-- are aligned vertically.+-- -- For putting separators at the end of entries instead, have a look at -- 'punctuate'. encloseSep@@ -695,7 +699,7 @@ encloseSep l r s ds = case ds of     []  -> l <> r     [d] -> l <> d <> r-    _   -> align (cat (zipWith (<>) (l : repeat s) ds) <> r)+    _   -> cat (zipWith (<>) (l : repeat s) ds) <> r  -- | Haskell-inspired variant of 'encloseSep' with braces and comma as -- separator.@@ -1474,9 +1478,9 @@ -- example. -- -- >>> defaultLayoutOptions--- LayoutOptions {layoutPageWidth = AvailablePerLine 80 0.4}+-- LayoutOptions {layoutPageWidth = AvailablePerLine 80 1.0} defaultLayoutOptions :: LayoutOptions-defaultLayoutOptions = LayoutOptions { layoutPageWidth = AvailablePerLine 80 0.4 }+defaultLayoutOptions = LayoutOptions { layoutPageWidth = AvailablePerLine 80 1 }  -- | This is the default layout algorithm, and it is used by 'show', 'putDoc' -- and 'hPutDoc'.@@ -1514,7 +1518,7 @@ -- Considre the following python-ish document, -- -- >>> let fun x = hang 2 ("fun(" <> softline' <> x) <> ")"--- >>> let doc = (fun . fun . fun . fun . fun) (list ["abcdef", "ghijklm"])+-- >>> let doc = (fun . fun . fun . fun . fun) (align (list ["abcdef", "ghijklm"])) -- -- which we’ll be rendering using the following pipeline (where the layout -- algorithm has been left open),@@ -1558,7 +1562,7 @@     -> SimpleDocStream ann layoutSmart = layoutWadlerLeijen     (FittingPredicate (\pWidth minNestingLevel maxWidth sdoc -> case maxWidth of-        Nothing -> False+        Nothing -> True         Just w -> fits pWidth minNestingLevel w sdoc ))   where     -- Search with more lookahead: assuming that nesting roughly corresponds to
test/Testsuite/Main.hs view
@@ -48,6 +48,10 @@         , testCase "fillSep performance"                    fillSepPerformance         ]+    , testGroup "Regression tests"+        [ testCase "layoutSmart: softline behaves like a newline (#49)"+                   regressionLayoutSmartSoftline+        ]     ]  fusionDoesNotChangeRendering :: FusionDepth -> Property@@ -179,3 +183,12 @@   where     pathological :: Int -> Doc ann     pathological n = iterate (\x -> fillSep ["a", x <+> "b"] ) "foobar" !! n++regressionLayoutSmartSoftline :: Assertion+regressionLayoutSmartSoftline+  = let doc = "a" <> softline <> "b"+        layouted :: SimpleDocStream ()+        layouted = layoutSmart (defaultLayoutOptions { layoutPageWidth = Unbounded }) doc+    in assertEqual "softline should be rendered as space page width is unbounded"+                   (SChar 'a' (SChar ' ' (SChar 'b' SEmpty)))+                   layouted