@@ -29,7 +29,7 @@ import Numeric (showEFloat, showFFloat, showGFloat, showHex)
2929import Prelude hiding (replicate )
3030import Test.Framework (Test , testGroup )
3131import Test.Framework.Providers.QuickCheck2 (testProperty )
32- import Test.QuickCheck hiding ((.&.) )
32+ import Test.QuickCheck hiding ((.&.) , Small ( .. ) )
3333import Test.QuickCheck.Monadic
3434import Test.QuickCheck.Property (Property (.. ))
3535import Test.QuickCheck.Unicode (char )
@@ -849,6 +849,38 @@ tb_decimal_big_int64 (BigBounded (a::Int64)) = tb_decimal a
849849tb_decimal_big_word (BigBounded (a:: Word )) = tb_decimal a
850850tb_decimal_big_word64 (BigBounded (a:: Word64 )) = tb_decimal a
851851
852+ tb_paddedDecimal :: (Integral a , Show a ) => Small -> a -> Bool
853+ tb_paddedDecimal padLenSmall = (TB. toLazyText . TB. paddedDecimal padLen) `eq` (expected . fromIntegral )
854+ where
855+ padLen = fromIntegral padLenSmall
856+ expected :: Integer -> TL. Text
857+ expected a
858+ | abs a >= 10 ^ padLen = TL. pack (show a)
859+ | a < 0 = " -" `TL.append` expected (abs a)
860+ | otherwise =
861+ let
862+ shown = TL. pack (show a)
863+ in
864+ TL. replicate (fromIntegral padLen - TL. length shown) " 0" `TL.append` shown
865+
866+ tb_paddedDecimal_integer len (a:: Integer ) = tb_paddedDecimal len a
867+ tb_paddedDecimal_integer_big len (Big a) = tb_paddedDecimal len a
868+ tb_paddedDecimal_int len (a:: Int ) = tb_paddedDecimal len a
869+ tb_paddedDecimal_int8 len (a:: Int8 ) = tb_paddedDecimal len a
870+ tb_paddedDecimal_int16 len (a:: Int16 ) = tb_paddedDecimal len a
871+ tb_paddedDecimal_int32 len (a:: Int32 ) = tb_paddedDecimal len a
872+ tb_paddedDecimal_int64 len (a:: Int64 ) = tb_paddedDecimal len a
873+ tb_paddedDecimal_word len (a:: Word ) = tb_paddedDecimal len a
874+ tb_paddedDecimal_word8 len (a:: Word8 ) = tb_paddedDecimal len a
875+ tb_paddedDecimal_word16 len (a:: Word16 ) = tb_paddedDecimal len a
876+ tb_paddedDecimal_word32 len (a:: Word32 ) = tb_paddedDecimal len a
877+ tb_paddedDecimal_word64 len (a:: Word64 ) = tb_paddedDecimal len a
878+
879+ tb_paddedDecimal_big_int len (BigBounded (a:: Int )) = tb_paddedDecimal len a
880+ tb_paddedDecimal_big_int64 len (BigBounded (a:: Int64 )) = tb_paddedDecimal len a
881+ tb_paddedDecimal_big_word len (BigBounded (a:: Word )) = tb_paddedDecimal len a
882+ tb_paddedDecimal_big_word64 len (BigBounded (a:: Word64 )) = tb_paddedDecimal len a
883+
852884tb_hex :: (Integral a , Show a ) => a -> Bool
853885tb_hex = (TB. toLazyText . TB. hexadecimal) `eq` (TL. pack . flip showHex " " )
854886
@@ -1401,6 +1433,24 @@ tests =
14011433 testProperty " tb_decimal_big_int64" tb_decimal_big_int64,
14021434 testProperty " tb_decimal_big_word64" tb_decimal_big_word64
14031435 ],
1436+ testGroup " paddedDecimal" [
1437+ testProperty " tb_paddedDecimal_int" tb_paddedDecimal_int,
1438+ testProperty " tb_paddedDecimal_int8" tb_paddedDecimal_int8,
1439+ testProperty " tb_paddedDecimal_int16" tb_paddedDecimal_int16,
1440+ testProperty " tb_paddedDecimal_int32" tb_paddedDecimal_int32,
1441+ testProperty " tb_paddedDecimal_int64" tb_paddedDecimal_int64,
1442+ testProperty " tb_paddedDecimal_integer" tb_paddedDecimal_integer,
1443+ testProperty " tb_paddedDecimal_integer_big" tb_paddedDecimal_integer_big,
1444+ testProperty " tb_paddedDecimal_word" tb_paddedDecimal_word,
1445+ testProperty " tb_paddedDecimal_word8" tb_paddedDecimal_word8,
1446+ testProperty " tb_paddedDecimal_word16" tb_paddedDecimal_word16,
1447+ testProperty " tb_paddedDecimal_word32" tb_paddedDecimal_word32,
1448+ testProperty " tb_paddedDecimal_word64" tb_paddedDecimal_word64,
1449+ testProperty " tb_paddedDecimal_big_int" tb_paddedDecimal_big_int,
1450+ testProperty " tb_paddedDecimal_big_word" tb_paddedDecimal_big_word,
1451+ testProperty " tb_paddedDecimal_big_int64" tb_paddedDecimal_big_int64,
1452+ testProperty " tb_paddedDecimal_big_word64" tb_paddedDecimal_big_word64
1453+ ],
14041454 testGroup " hexadecimal" [
14051455 testProperty " tb_hexadecimal_int" tb_hexadecimal_int,
14061456 testProperty " tb_hexadecimal_int8" tb_hexadecimal_int8,
0 commit comments