@@ -43,6 +43,20 @@ tests =
43 , testGroup "getByteString"
43 , testGroup "getByteString"
44 [ testProperty "prop_getByteString_negative" prop_getByteString_negative ]
44 [ testProperty "prop_getByteString_negative" prop_getByteString_negative ]
46+ , testGroup "getLazyByteString"
47+ [ testProperty "getLazyByteString == getByteString"
48+ prop_getLazyByteString_equal_to_ByteString
49+ , testProperty "getLazyByteString == getByteString (with shift)"
50+ prop_getLazyByteString_equal_to_ByteString2
53+ , testGroup "isEmpty"
54+ [ testProperty "prop_isEmptyOfEmptyEmpty" prop_isEmptyOfEmptyEmpty
55+ , testProperty "prop_isEmptyOfNonEmptyEmpty" prop_isEmptyOfNonEmptyEmpty
56+ , testProperty "prop_isEmptyOfConsumedEmpty" prop_isEmptyOfConsumedEmpty
57+ , testProperty "prop_isEmptyOfNotConsumedNotEmpty" prop_isEmptyOfNotConsumedNotEmpty
46 , testGroup "Fail"
60 , testGroup "Fail"
47 [ testProperty "monadic fail" prop_fail ]
61 [ testProperty "monadic fail" prop_fail ]
@@ -110,6 +124,35 @@ tests =
127+prop_isEmptyOfEmptyEmpty :: Bool
128+prop_isEmptyOfEmptyEmpty = runGet (runBitGet isEmpty) L.empty
130+prop_isEmptyOfNonEmptyEmpty :: L.ByteString -> Property
131+prop_isEmptyOfNonEmptyEmpty bs =
132+ not (L.null bs) ==> not (runGet (runBitGet isEmpty) bs)
134+prop_isEmptyOfConsumedEmpty :: L.ByteString -> Property
135+prop_isEmptyOfConsumedEmpty bs =
137+ runGet (runBitGet (getByteString n >> isEmpty)) bs
138+ where n = fromIntegral $ L.length bs
140+prop_isEmptyOfNotConsumedNotEmpty :: L.ByteString -> Int -> Property
141+prop_isEmptyOfNotConsumedNotEmpty bs n =
142+ (fromIntegral n) < L.length bs && not (L.null bs) ==>
143+ not (runGet (runBitGet (getByteString n >> isEmpty)) bs)
145+prop_getLazyByteString_equal_to_ByteString :: L.ByteString -> Int -> Property
146+prop_getLazyByteString_equal_to_ByteString bs n =
147+ (fromIntegral n) <= L.length bs ==>
148+ runGet (runBitGet (getLazyByteString (fromIntegral n))) bs ==
149+ (L.fromChunks . (:[]) $ runGet (runBitGet (getByteString n)) bs)
151+prop_getLazyByteString_equal_to_ByteString2 :: L.ByteString -> Int -> Property
152+prop_getLazyByteString_equal_to_ByteString2 bs n =
153+ (L.length bs > 1) && (fromIntegral n) < L.length bs ==>
154+ runGet (runBitGet (getWord8 2 >> getLazyByteString (fromIntegral n))) bs ==
155+ (L.fromChunks . (:[]) $ runGet (runBitGet (getWord8 2 >> getByteString n)) bs)
114prop_getByteString_negative :: Int -> Property
157prop_getByteString_negative :: Int -> Property
115prop_getByteString_negative n =
158prop_getByteString_negative n =