on master help sign in
Fix an integer encoding bug, and add basic QuickCheck tests
commitdfa350c242186a670c330513838283d144aa118d authorBryan O'Sullivan <bos@mailrank.com> dateTue 22 Mar 2011, 07:42 (16 years ago) parenta6dc7ae
3 files changed+30−1
Data/Aeson/Encode/Int.hs+1−1 tests/Makefile+9 tests/Properties.hs+20
Data/Aeson/Encode/Int.hs+1−1
@@ -25,7 +25,7 @@ int i
2525 | otherwise = go i
2626 where
2727 go n | n < 10 = digit n
28− | otherwise = go (n `rem` 10) `mappend` digit (n `quot` 10)
28+ | otherwise = go (n `quot` 10) `mappend` digit (n `rem` 10)
2929
3030digit :: Int -> Builder
3131digit n = fromWord8 $! fromIntegral n + 48
tests/Makefilenew file+9
@@ -0,0 +1,9 @@
1+ghc := ghc
2+
3+all: qc
4+
5+qc: Properties.hs
6+ $(ghc) -o --make $@ $<
7+
8+clean:
9+ -rm -f qc *.o *.hi
tests/Properties.hsnew file+20
@@ -0,0 +1,20 @@
1+import Data.Aeson.Encode
2+import Data.Aeson.Types
3+import Data.Attoparsec.Number
4+import Test.Framework (defaultMain, testGroup)
5+import Test.Framework.Providers.QuickCheck2 (testProperty)
6+import Test.QuickCheck (Arbitrary(..))
7+import Test.QuickCheck.Monadic (assert, monadicIO, run)
8+import qualified Data.ByteString.Lazy.Char8 as L
9+
10+encodeDouble d = encode (Number (D d)) == L.pack (show d)
11+encodeInteger i = encode (Number (I i)) == L.pack (show i)
12+
13+main = defaultMain tests
14+
15+tests = [
16+ testGroup "encode" [
17+ testProperty "encodeDouble" encodeDouble
18+ , testProperty "encodeInteger" encodeInteger
19+ ]
20+ ]