@@ -16,6 +16,7 @@ import Data.Word
1616import System.Timeout (timeout )
1717
1818import Prettyprinter
19+ import qualified Prettyprinter.Internal as Internal
1920import Prettyprinter.Internal.Debug
2021import Prettyprinter.Render.Text
2122import 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+
91111fusionDoesNotChangeRendering :: FusionDepth -> Property
92112fusionDoesNotChangeRendering depth
93113 = forAllShow (arbitrary :: Gen (Doc Int )) (show . diag) (\ doc ->
0 commit comments