Bryan O'Sullivan avatar Bryan O'Sullivan committed f65d057

Add a test case for decimal rendering (issue 30)

Comments (0)

Files changed (1)

tests/Tests/Properties.hs

 import Control.Arrow ((***), second)
 import Control.Exception (catch)
 import Data.Char (chr, isDigit, isHexDigit, isLower, isSpace, isUpper, ord)
+import Data.Int (Int8)
 import Data.Monoid (Monoid(..))
 import Data.String (fromString)
 import Data.Text.Encoding.Error
 import qualified Data.Text.IO as T
 import qualified Data.Text.Lazy as TL
 import qualified Data.Text.Lazy.Builder as TB
+import qualified Data.Text.Lazy.Builder.Int as TB
 import qualified Data.Text.Lazy.Encoding as EL
 import qualified Data.Text.Lazy.Fusion as SL
 import qualified Data.Text.Lazy.IO as TL
 
 -- Builder.
 
-t_builderSingleton = id `eqP`
-                     (unpackS . TB.toLazyText . mconcat . map TB.singleton)
-t_builderFromText = L.concat `eq` (unpackS . TB.toLazyText . mconcat .
+tb_singleton = id `eqP`
+               (unpackS . TB.toLazyText . mconcat . map TB.singleton)
+tb_fromText = L.concat `eq` (unpackS . TB.toLazyText . mconcat .
                                    map (TB.fromText . packS))
-t_builderAssociative s1 s2 s3 =
+tb_associative s1 s2 s3 =
     TB.toLazyText (b1 `mappend` (b2 `mappend` b3)) ==
     TB.toLazyText ((b1 `mappend` b2) `mappend` b3)
   where b1 = TB.fromText (packS s1)
         b2 = TB.fromText (packS s2)
         b3 = TB.fromText (packS s3)
 
+-- Numeric builder stuff.
+
+tb_decimal :: (Integral a, Show a) => a -> Bool
+tb_decimal = (TB.toLazyText . TB.decimal) `eq` (TL.pack . show)
+
+tb_decimal_int8 (a::Int8) = tb_decimal a
+
 -- Reading.
 
 t_decimal (n::Int) s =
 -- themselves.
 shorten :: Int -> S.Stream a -> S.Stream a
 shorten n t@(S.Stream arr off len)
-    | n > 0     = S.Stream arr off (smaller (exactSize n) len) 
+    | n > 0     = S.Stream arr off (smaller (exactSize n) len)
     | otherwise = t
 
 tests :: Test
     ],
 
     testGroup "builder" [
-      testProperty "t_builderSingleton" t_builderSingleton,
-      testProperty "t_builderFromText" t_builderFromText,
-      testProperty "t_builderAssociative" t_builderAssociative
+      testProperty "tb_associative" tb_associative,
+      testProperty "tb_decimal_int8" tb_decimal_int8,
+      testProperty "tb_fromText" tb_fromText,
+      testProperty "tb_singleton" tb_singleton
     ],
 
     testGroup "read" [
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.