Skip to content
Merged
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
16 changes: 1 addition & 15 deletions prettyprinter/src/Prettyprinter/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module Prettyprinter.Internal (
renderShowS,

-- * Internal helpers
textSpaces
spaces, textSpaces
) where


Expand Down Expand Up @@ -1385,19 +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



-- | @('plural' n one many)@ is @one@ if @n@ is @1@, and @many@ otherwise. A
-- typical use case is adding a plural "s".
--
Expand Down Expand Up @@ -2348,4 +2335,3 @@ textSpaces n = T.replicate n (T.singleton ' ')
-- >>> import Prettyprinter.Render.Text
-- >>> import Prettyprinter.Symbols.Ascii
-- >>> import Prettyprinter.Util as Util
-- >>> import Test.QuickCheck.Modifiers
20 changes: 20 additions & 0 deletions prettyprinter/test/Testsuite/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Data.Word
import System.Timeout (timeout)

import Prettyprinter
import qualified Prettyprinter.Internal as Internal
import Prettyprinter.Internal.Debug
import Prettyprinter.Render.Text
import Prettyprinter.Render.Util.StackMachine (renderSimplyDecorated)
Expand All @@ -41,6 +42,7 @@ tests = testGroup "Tests"
(fusionDoesNotChangeRendering Deep)
]
, testStripTrailingSpace
, testSpaces
, testGroup "Performance tests"
[ testCase "Grouping performance"
groupingPerformance
Expand Down Expand Up @@ -88,6 +90,24 @@ tests = testGroup "Tests"
]
]

testSpaces :: TestTree
testSpaces = testGroup "Spaces"
[ testProperty "n >= 0 ==> length (show (spaces n)) == n"
(\(NonNegative n) -> length (show (Internal.spaces n)) == n)
, testCase "spaces 1 is a Char ' '"
(case Internal.spaces 1 of
Internal.Char ' ' -> pure ()
_ -> assertFailure "Expected Char ' '")
, testCase "spaces 0 is Empty"
(case Internal.spaces 0 of
Internal.Empty -> pure ()
_ -> assertFailure "Expected Empty")
, testProperty "negative spaces are Empty"
(\(Positive n) -> case Internal.spaces (-n) of
Internal.Empty -> True
_ -> False)
]

fusionDoesNotChangeRendering :: FusionDepth -> Property
fusionDoesNotChangeRendering depth
= forAllShow (arbitrary :: Gen (Doc Int)) (show . diag) (\doc ->
Expand Down
Loading