Skip to content

Commit f8d63c7

Browse files
authored
Move the tests for spaces into the main testsuite (#293)
This allows us to remove the problematic import of Test.QuickCheck.Modifiers from the doctests. (#290)
1 parent 1626d38 commit f8d63c7

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

prettyprinter/src/Prettyprinter/Internal.hs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module Prettyprinter.Internal (
8080
renderShowS,
8181

8282
-- * Internal helpers
83-
textSpaces
83+
spaces, textSpaces
8484
) where
8585

8686

@@ -1385,19 +1385,6 @@ spaces n
13851385
| n == 1 = Char ' '
13861386
| otherwise = Text n (textSpaces n)
13871387

1388-
-- $
1389-
-- prop> \(NonNegative n) -> length (show (spaces n)) == n
1390-
--
1391-
-- >>> case spaces 1 of Char ' ' -> True; _ -> False
1392-
-- True
1393-
--
1394-
-- >>> case spaces 0 of Empty -> True; _ -> False
1395-
-- True
1396-
--
1397-
-- prop> \(Positive n) -> case (spaces (-n)) of Empty -> True; _ -> False
1398-
1399-
1400-
14011388
-- | @('plural' n one many)@ is @one@ if @n@ is @1@, and @many@ otherwise. A
14021389
-- typical use case is adding a plural "s".
14031390
--
@@ -2348,4 +2335,3 @@ textSpaces n = T.replicate n (T.singleton ' ')
23482335
-- >>> import Prettyprinter.Render.Text
23492336
-- >>> import Prettyprinter.Symbols.Ascii
23502337
-- >>> import Prettyprinter.Util as Util
2351-
-- >>> import Test.QuickCheck.Modifiers

prettyprinter/test/Testsuite/Main.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Data.Word
1616
import System.Timeout (timeout)
1717

1818
import Prettyprinter
19+
import qualified Prettyprinter.Internal as Internal
1920
import Prettyprinter.Internal.Debug
2021
import Prettyprinter.Render.Text
2122
import Prettyprinter.Render.Util.StackMachine (renderSimplyDecorated)
@@ -41,6 +42,7 @@ tests = testGroup "Tests"
4142
(fusionDoesNotChangeRendering Deep)
4243
]
4344
, testStripTrailingSpace
45+
, testSpaces
4446
, testGroup "Performance tests"
4547
[ testCase "Grouping performance"
4648
groupingPerformance
@@ -88,6 +90,24 @@ tests = testGroup "Tests"
8890
]
8991
]
9092

93+
testSpaces :: TestTree
94+
testSpaces = testGroup "Spaces"
95+
[ testProperty "n >= 0 ==> length (show (spaces n)) == n"
96+
(\(NonNegative n) -> length (show (Internal.spaces n)) == n)
97+
, testCase "spaces 1 is a Char ' '"
98+
(case Internal.spaces 1 of
99+
Internal.Char ' ' -> pure ()
100+
_ -> assertFailure "Expected Char ' '")
101+
, testCase "spaces 0 is Empty"
102+
(case Internal.spaces 0 of
103+
Internal.Empty -> pure ()
104+
_ -> assertFailure "Expected Empty")
105+
, testProperty "negative spaces are Empty"
106+
(\(Positive n) -> case Internal.spaces (-n) of
107+
Internal.Empty -> True
108+
_ -> False)
109+
]
110+
91111
fusionDoesNotChangeRendering :: FusionDepth -> Property
92112
fusionDoesNotChangeRendering depth
93113
= forAllShow (arbitrary :: Gen (Doc Int)) (show . diag) (\doc ->

0 commit comments

Comments
 (0)