on master help sign in
Add a test case for decimal rendering (issue 30)
fa37514Bryan O'Sullivan
tests/Tests/Properties.hs+18−8
@@ -16,6 +16,7 @@ import Text.Show.Functions ()
16import Control.Arrow ((***), second)
16import Control.Arrow ((***), second)
17import Control.Exception (catch)
17import Control.Exception (catch)
18import Data.Char (chr, isDigit, isHexDigit, isLower, isSpace, isUpper, ord)
18import Data.Char (chr, isDigit, isHexDigit, isLower, isSpace, isUpper, ord)
19+import Data.Int (Int8)
19import Data.Monoid (Monoid(..))
20import Data.Monoid (Monoid(..))
20import Data.String (fromString)
21import Data.String (fromString)
21import Data.Text.Encoding.Error
22import Data.Text.Encoding.Error
@@ -39,6 +40,7 @@ import qualified Data.Text.Fusion.Common as S
39import qualified Data.Text.IO as T
40import qualified Data.Text.IO as T
40import qualified Data.Text.Lazy as TL
41import qualified Data.Text.Lazy as TL
41import qualified Data.Text.Lazy.Builder as TB
42import qualified Data.Text.Lazy.Builder as TB
43+import qualified Data.Text.Lazy.Builder.Int as TB
42import qualified Data.Text.Lazy.Encoding as EL
44import qualified Data.Text.Lazy.Encoding as EL
43import qualified Data.Text.Lazy.Fusion as SL
45import qualified Data.Text.Lazy.Fusion as SL
44import qualified Data.Text.Lazy.IO as TL
46import qualified Data.Text.Lazy.IO as TL
@@ -610,17 +612,24 @@ shiftR_Word32 = shiftR :: Word32 -> Property
610
612
611-- Builder.
613-- Builder.
612
614
613−t_builderSingleton = id `eqP`
615+tb_singleton = id `eqP`
614− (unpackS . TB.toLazyText . mconcat . map TB.singleton)
616+ (unpackS . TB.toLazyText . mconcat . map TB.singleton)
615−t_builderFromText = L.concat `eq` (unpackS . TB.toLazyText . mconcat .
617+tb_fromText = L.concat `eq` (unpackS . TB.toLazyText . mconcat .
616 map (TB.fromText . packS))
618 map (TB.fromText . packS))
617−t_builderAssociative s1 s2 s3 =
619+tb_associative s1 s2 s3 =
618 TB.toLazyText (b1 `mappend` (b2 `mappend` b3)) ==
620 TB.toLazyText (b1 `mappend` (b2 `mappend` b3)) ==
619 TB.toLazyText ((b1 `mappend` b2) `mappend` b3)
621 TB.toLazyText ((b1 `mappend` b2) `mappend` b3)
620 where b1 = TB.fromText (packS s1)
622 where b1 = TB.fromText (packS s1)
621 b2 = TB.fromText (packS s2)
623 b2 = TB.fromText (packS s2)
622 b3 = TB.fromText (packS s3)
624 b3 = TB.fromText (packS s3)
623
625
626+-- Numeric builder stuff.
627+
628+tb_decimal :: (Integral a, Show a) => a -> Bool
629+tb_decimal = (TB.toLazyText . TB.decimal) `eq` (TL.pack . show)
630+
631+tb_decimal_int8 (a::Int8) = tb_decimal a
632+
624-- Reading.
633-- Reading.
625
634
626t_decimal (n::Int) s =
635t_decimal (n::Int) s =
@@ -691,7 +700,7 @@ s_filter_eq s = S.filter p t == S.streamList (filter p s)
691-- themselves.
700-- themselves.
692shorten :: Int -> S.Stream a -> S.Stream a
701shorten :: Int -> S.Stream a -> S.Stream a
693shorten n t@(S.Stream arr off len)
702shorten n t@(S.Stream arr off len)
694− | n > 0 = S.Stream arr off (smaller (exactSize n) len)
703+ | n > 0 = S.Stream arr off (smaller (exactSize n) len)
695 | otherwise = t
704 | otherwise = t
696
705
697tests :: Test
706tests :: Test
@@ -1080,9 +1089,10 @@ tests =
1080 ],
1089 ],
1081
1090
1082 testGroup "builder" [
1091 testGroup "builder" [
1083− testProperty "t_builderSingleton" t_builderSingleton,
1092+ testProperty "tb_associative" tb_associative,
1084− testProperty "t_builderFromText" t_builderFromText,
1093+ testProperty "tb_decimal_int8" tb_decimal_int8,
1085− testProperty "t_builderAssociative" t_builderAssociative
1094+ testProperty "tb_fromText" tb_fromText,
1095+ testProperty "tb_singleton" tb_singleton
1086 ],
1096 ],
1087
1097
1088 testGroup "read" [
1098 testGroup "read" [