Skip to content
Closed
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
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ packages: prettyprinter
, prettyprinter-compat-annotated-wl-pprint
tests: true
benchmarks: true
write-ghc-environment-files: always
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ test-suite doctest
main-is: Main.hs
build-depends:
base >= 4.9 && < 5
, doctest >= 0.9
, doctest-parallel >= 0.1
, prettyprinter-ansi-terminal
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import Data.Semigroup (Semigroup(..))
-- >>> :set -XOverloadedStrings
-- >>> import qualified Data.Text.Lazy.IO as TL
-- >>> import qualified Data.Text.Lazy as TL
-- >>> import Prettyprinter
-- >>> import Prettyprinter.Render.Terminal


Expand Down
5 changes: 3 additions & 2 deletions prettyprinter-ansi-terminal/test/Doctest/Main.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Main (main) where

import Test.DocTest
import Test.DocTest (mainFromCabal)
import System.Environment (getArgs)

main :: IO ()
main = doctest [ "src" , "-Imisc"]
main = mainFromCabal "prettyprinter-ansi-terminal" =<< getArgs
3 changes: 1 addition & 2 deletions prettyprinter/prettyprinter.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ source-repository head
type: git
location: https://github.com/quchen/prettyprinter


library
exposed-modules:
Prettyprinter
Expand Down Expand Up @@ -123,7 +122,7 @@ test-suite doctest
main-is: Main.hs
build-depends:
base >= 4.9 && < 5
, doctest >= 0.9
, doctest-parallel >= 0.1
, prettyprinter
, QuickCheck >= 2.5
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
Expand Down
13 changes: 3 additions & 10 deletions prettyprinter/src/Prettyprinter/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1385,16 +1385,6 @@ spaces n
| n == 1 = Char ' '
| otherwise = Text n (textSpaces n)

-- $
-- prop> \(NonNegative n) -> length (show (spaces n)) == n
--
-- >>> case spaces 1 of Char ' ' -> True; _ -> False
-- True
--
-- >>> case spaces 0 of Empty -> True; _ -> False
-- True
--
-- prop> \(Positive n) -> case (spaces (-n)) of Empty -> True; _ -> False



Expand Down Expand Up @@ -2345,6 +2335,9 @@ textSpaces n = T.replicate n (T.singleton ' ')
-- (Definitions for the doctests)
--
-- >>> :set -XOverloadedStrings
-- >>> import Data.Functor.Identity
-- >>> import Data.Text (Text)
-- >>> import Data.Void (Void)
-- >>> import Prettyprinter.Render.Text
-- >>> import Prettyprinter.Symbols.Ascii
-- >>> import Prettyprinter.Util as Util
Expand Down
7 changes: 7 additions & 0 deletions prettyprinter/src/Prettyprinter/Internal/Debug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ import Data.Text (Text)
import Prettyprinter.Internal (PageWidth, Doc)
import qualified Prettyprinter.Internal as Doc

-- $setup
--
-- (Definitions for the doctests)
--
-- >>> :set -XOverloadedStrings
-- >>> import qualified Prettyprinter.Internal as Doc

-- | A variant of 'Doc' for debugging.
--
-- Unlike in the 'Doc' type, the 'Column', 'WithPageWidth' and 'Nesting'
Expand Down
1 change: 1 addition & 0 deletions prettyprinter/src/Prettyprinter/Render/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Prettyprinter.Render.Util.Panic
-- (Definitions for the doctests)
--
-- >>> :set -XOverloadedStrings
-- >>> import Prettyprinter
-- >>> import qualified Data.Text.IO as T
-- >>> import qualified Data.Text.Lazy.IO as TL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,19 @@ render doc
--
-- We can now render an example document using our definitions:
--
-- >>> :set -XOverloadedStrings
-- >>> import qualified Data.Text.Lazy.IO as TL
-- >>> :{
-- >>> let go = TL.putStrLn . render . layoutPretty defaultLayoutOptions
-- >>> in go (vsep
-- >>> [ headline "Example document"
-- >>> , paragraph ("This is a" <+> color Red "paragraph" <> comma)
-- >>> , paragraph ("and" <+> bold "this text is bold.")
-- >>> ])
-- >>> :}
-- <h1>Example document</h1>
-- <p>This is a <span style="color: #f00">paragraph</span>,</p>
-- <p>and <strong>this text is bold.</strong></p>
-- > :set -XOverloadedStrings
-- > import qualified Data.Text.Lazy.IO as TL
-- > :{
-- > let go = TL.putStrLn . render . layoutPretty defaultLayoutOptions
-- > in go (vsep
-- > [ headline "Example document"
-- > , paragraph ("This is a" <+> color Red "paragraph" <> comma)
-- > , paragraph ("and" <+> bold "this text is bold.")
-- > ])
-- > :}
--
-- Result:
--
-- > <h1>Example document</h1>
-- > <p>This is a <span style="color: #f00">paragraph</span>,</p>
-- > <p>and <strong>this text is bold.</strong></p>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ import Prettyprinter.Render.Util.SimpleDocTree
#if !(FOLDABLE_TRAVERSABLE_IN_PRELUDE)
import Data.Foldable (foldMap)
#endif

-- $setup
--
-- (Definitions for the doctests)
--
-- >>> :set -XOverloadedStrings
-- >>> import Prettyprinter
#if !(SEMIGROUP_MONOID_SUPERCLASS)
import Data.Semigroup
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Data.Traversable (Traversable (..))
--
-- (Definitions for the doctests)
--
-- >>> :set -XOverloadedStrings
-- >>> import Prettyprinter hiding ((<>))
-- >>> import qualified Data.Text.IO as T

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import Control.Applicative (liftA2)
--
-- (Definitions for the doctests)
--
-- >>> :set -XOverloadedStrings
-- >>> import Prettyprinter hiding ((<>))
-- >>> import qualified Data.Text.IO as T

Expand Down
1 change: 1 addition & 0 deletions prettyprinter/src/Prettyprinter/Symbols/Ascii.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,6 @@ pipe = Char '|'
--
-- >>> :set -XOverloadedStrings
-- >>> import Data.Semigroup
-- >>> import Prettyprinter
-- >>> import Prettyprinter.Render.Text
-- >>> import Prettyprinter.Util
19 changes: 10 additions & 9 deletions prettyprinter/src/Prettyprinter/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ import Prettyprinter



-- $setup
--
-- (Definitions for the doctests)
--
-- >>> :set -XOverloadedStrings
-- >>> import Prelude hiding (words)

-- | Split an input into word-sized 'Doc's.
--
-- >>> putDoc (tupled (words "Lorem ipsum dolor"))
-- @
-- putDoc (tupled (words "Lorem ipsum dolor"))
-- (Lorem, ipsum, dolor)
-- @
words :: Text -> [Doc ann]
words = map pretty . T.words

Expand Down Expand Up @@ -55,11 +64,3 @@ putDocW :: Int -> Doc ann -> IO ()
putDocW w doc = renderIO System.IO.stdout (layoutPretty layoutOptions (unAnnotate doc))
where
layoutOptions = LayoutOptions { layoutPageWidth = AvailablePerLine w 1 }



-- $setup
--
-- (Definitions for the doctests)
--
-- >>> :set -XOverloadedStrings
9 changes: 3 additions & 6 deletions prettyprinter/test/Doctest/Main.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
module Main (main) where

import Test.DocTest

-- Silence -Wunused-packages:
import Prettyprinter ()
import Test.QuickCheck ()
import Test.DocTest (mainFromCabal)
import System.Environment (getArgs)

main :: IO ()
main = doctest [ "src" , "-Imisc"]
main = mainFromCabal "prettyprinter" =<< getArgs
Loading