@@ -38,6 +38,20 @@ tests =
3838 , testGroup "getByteString"
3939 [ testProperty "prop_getByteString_negative" prop_getByteString_negative ]
4040
41+ , testGroup "getLazyByteString"
42+ [ testProperty "getLazyByteString == getByteString"
43+ prop_getLazyByteString_equal_to_ByteString
44+ , testProperty "getLazyByteString == getByteString (with shift)"
45+ prop_getLazyByteString_equal_to_ByteString2
46+ ]
47+
48+ , testGroup "isEmpty"
49+ [ testProperty "prop_isEmptyOfEmptyEmpty" prop_isEmptyOfEmptyEmpty
50+ , testProperty "prop_isEmptyOfNonEmptyEmpty" prop_isEmptyOfNonEmptyEmpty
51+ , testProperty "prop_isEmptyOfConsumedEmpty" prop_isEmptyOfConsumedEmpty
52+ , testProperty "prop_isEmptyOfNotConsumedNotEmpty" prop_isEmptyOfNotConsumedNotEmpty
53+ ]
54+
4155 , testGroup "Fail"
4256 [ testProperty "monadic fail" prop_fail ]
4357
@@ -105,6 +119,35 @@ tests =
105119 ]
106120 ]
107121
122+prop_isEmptyOfEmptyEmpty :: Bool
123+prop_isEmptyOfEmptyEmpty = runGet (runBitGet isEmpty) L.empty
124+
125+prop_isEmptyOfNonEmptyEmpty :: L.ByteString -> Property
126+prop_isEmptyOfNonEmptyEmpty bs =
127+ not (L.null bs) ==> not (runGet (runBitGet isEmpty) bs)
128+
129+prop_isEmptyOfConsumedEmpty :: L.ByteString -> Property
130+prop_isEmptyOfConsumedEmpty bs =
131+ not (L.null bs) ==>
132+ runGet (runBitGet (getByteString n >> isEmpty)) bs
133+ where n = fromIntegral $ L.length bs
134+
135+prop_isEmptyOfNotConsumedNotEmpty :: L.ByteString -> Int -> Property
136+prop_isEmptyOfNotConsumedNotEmpty bs n =
137+ (fromIntegral n) < L.length bs && not (L.null bs) ==>
138+ not (runGet (runBitGet (getByteString n >> isEmpty)) bs)
139+
140+prop_getLazyByteString_equal_to_ByteString :: L.ByteString -> Int -> Property
141+prop_getLazyByteString_equal_to_ByteString bs n =
142+ (fromIntegral n) <= L.length bs ==>
143+ runGet (runBitGet (getLazyByteString (fromIntegral n))) bs ==
144+ (L.fromChunks . (:[]) $ runGet (runBitGet (getByteString n)) bs)
145+
146+prop_getLazyByteString_equal_to_ByteString2 :: L.ByteString -> Int -> Property
147+prop_getLazyByteString_equal_to_ByteString2 bs n =
148+ (L.length bs > 1) && (fromIntegral n) < L.length bs ==>
149+ runGet (runBitGet (getWord8 2 >> getLazyByteString (fromIntegral n))) bs ==
150+ (L.fromChunks . (:[]) $ runGet (runBitGet (getWord8 2 >> getByteString n)) bs)
108151
109152prop_getByteString_negative :: Int -> Property
110153prop_getByteString_negative n =