caerbannog 0.6.0.5 → 0.6.1.0
raw patch · 3 files changed
+23/−3 lines, 3 filesdep ~randomPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: random
API changes (from Hackage documentation)
+ Data.Binary.Bits.Get: instance GHC.Base.Alternative Data.Binary.Bits.Get.BitGet
Files
- caerbannog.cabal +2/−2
- src/lib/Data/Binary/Bits/Get.hs +5/−1
- src/test/Main.hs +16/−0
caerbannog.cabal view
@@ -1,7 +1,7 @@ cabal-version: >= 1.10 name: caerbannog-version: 0.6.0.5+version: 0.6.1.0 synopsis: That rabbit's got a vicious streak a mile wide! description: Caerbannog is a drop in replacement for the @binary-bits@ package. Unlike@@ -55,7 +55,7 @@ , bytestring , hspec >= 2.7.6 && < 2.9 , QuickCheck >= 2.13.2 && < 2.15- , random >= 1.1 && < 1.2+ , random >= 1.1 && < 1.3 default-language: Haskell98 hs-source-dirs: src/test main-is: Main.hs
src/lib/Data/Binary/Bits/Get.hs view
@@ -83,7 +83,7 @@ import Data.Bits import Data.Word-import Control.Applicative+import Control.Applicative as Appl import Prelude as P @@ -346,6 +346,10 @@ instance Applicative BitGet where pure x = B $ \s -> return (s,x) fm <*> m = fm >>= \f -> m >>= \v -> return (f v)++instance Alternative BitGet where+ empty = B (const Appl.empty)+ (B f1) <|> (B f2) = B (\s -> f1 s <|> f2 s) -- | Run a 'BitGet' within the Binary packages 'Get' monad. If a byte has -- been partially consumed it will be discarded once 'runBitGet' is finished.
src/test/Main.hs view
@@ -6,6 +6,7 @@ import Data.Bits ((.|.)) import Test.QuickCheck ((==>)) +import qualified Control.Applicative as Appl import qualified Data.Binary as Binary import qualified Data.Binary.Bits as BB import qualified Data.Binary.Bits.Get as BB@@ -46,6 +47,10 @@ Hspec.describe "Fail" $ do Hspec.it "monadic fail" $ QC.property prop_fail + Hspec.describe "Applicative" $ do+ Hspec.it "left identity" $ QC.property prop_alternativeLeftIdentity+ Hspec.it "right identity" $ QC.property prop_alternativeRightIdentity+ Hspec.describe "prop_bitput_with_get_from_binary" $ do Hspec.it "Word8" $ QC.property (prop_bitput_with_get_from_binary :: W [Word.Word8] -> QC.Property) Hspec.it "Word16" $ QC.property (prop_bitput_with_get_from_binary :: W [Word.Word16] -> QC.Property)@@ -232,6 +237,17 @@ , errMsg == errMsg0 ] _ -> False++-- | Test Alternative instance.+prop_alternativeLeftIdentity :: L.ByteString -> QC.Property+prop_alternativeLeftIdentity lbs = QC.property $+ Binary.runGet (BB.runBitGet (Appl.empty Appl.<|> BB.getLazyByteString n)) lbs == lbs+ where n = fromIntegral $ L.length lbs++prop_alternativeRightIdentity :: L.ByteString -> QC.Property+prop_alternativeRightIdentity lbs = QC.property $+ Binary.runGet (BB.runBitGet (BB.getLazyByteString n Appl.<|> Appl.empty)) lbs == lbs+ where n = fromIntegral $ L.length lbs -- | number of bits required to write @v@ bitreq :: (Num b, Num a, Bits.Bits a, Ord a) => a -> b