packages feed

wire-streams 0.1.0.0 → 0.1.1.0

raw patch · 5 files changed

+96/−101 lines, 5 filesdep +tastydep +tasty-quickcheckdep −Cabaldep −cabal-test-quickcheckdep ~QuickCheckdep ~basedep ~binary

Dependencies added: tasty, tasty-quickcheck

Dependencies removed: Cabal, cabal-test-quickcheck

Dependency ranges changed: QuickCheck, base, binary

Files

CHANGELOG view
@@ -1,3 +1,7 @@+# v0.1.1.0++Move tests to tasty.+ # v0.1.0.0  + Using binary-parsers package which speeds up binary code, remove cereal support since binary is much faster now.
− dist/build/encode-decode-binaryStub/encode-decode-binaryStub-tmp/encode-decode-binaryStub.hs
@@ -1,5 +0,0 @@-module Main ( main ) where-import Distribution.Simple.Test.LibV09 ( stubMain )-import EncodeDecodeBinary ( tests )-main :: IO ()-main = stubMain tests
− test/EncodeDecodeBinary.hs
@@ -1,87 +0,0 @@-{-# LANGUAGE ScopedTypeVariables #-}-module EncodeDecodeBinary ( tests ) where--import           Control.Exception                         (catch,evaluate)-import           Data.Binary                               (Binary)-import           Data.ByteString                           (ByteString)-import qualified Data.ByteString                           as S-import           Distribution.TestSuite                    (Test)-import           Distribution.TestSuite.QuickCheck         (testProperty)-import           System.IO.Streams                         (write)-import           System.IO.Streams.Binary                  (decodeInputStream,-                                                            encodeOutputStream,-                                                            DecodeException)-import           System.IO.Streams.List                    (outputToList,-                                                            fromList,-                                                            toList,-                                                            writeList)-import           Test.QuickCheck.Property                  (Property)-import           Test.QuickCheck.Monadic                   (monadicIO,-                                                            assert,-                                                            run)----- Using binary-streams, decode from a list of bytestrings-decode :: Binary a => [ByteString] -> IO [a]-decode ss = fromList ss >>= decodeInputStream >>= toList---- Using binary-streams, encode to a list of bytestrings-encode :: Binary a => [a] -> IO [ByteString]-encode xs = outputToList $ \os ->-  do-    bos <- encodeOutputStream os-    writeList xs bos-    write Nothing bos---- Encode something, then decode it and make sure we get the same thing back.-encodeDecodeEq :: (Binary a,Eq a) => [a] -> Property-encodeDecodeEq xs = monadicIO $ do-  xs' <- run go-  assert $ xs == xs'-  where go = encode xs >>= decode---- corrupt something, remove the last byte of the last bytestring-corrupt :: [ByteString] -> [ByteString]-corrupt = reverse . go . reverse-  where go (h:t) = ((S.reverse $ S.drop 1 $ S.reverse h):t)-        go [] = []---- Encode something, corrupt the encoded data, and make sure we get a--- decode error when we try do decode it.-encodeDecodeError :: forall a. (Binary a,Eq a) => [a] -> Property-encodeDecodeError [] = monadicIO $ return ()-encodeDecodeError xs = monadicIO $ do-  run $ catch go $ \(_ :: DecodeException) -> return ()-  where go =-         do-           bList <- encode xs-           (xs' :: [a]) <- decode $ corrupt bList-           evaluate xs'-           fail "decoding succeeded when it should fail"--tests :: IO [Test]-tests =- return [testProperty "encode-decode-equality Int"-         (encodeDecodeEq :: [Int] -> Property),-         testProperty "encode-decode-equality String"-         (encodeDecodeEq :: [String] -> Property),-         testProperty "encode-decode-equality Maybe Int"-         (encodeDecodeEq :: [Maybe Int] -> Property),-         testProperty "encode-decode-equality Either Int String"-         (encodeDecodeEq :: [Either Int String] -> Property),-         testProperty "encode-decode-equality (Int,Int)"-         (encodeDecodeEq :: [(Int,Int)] -> Property),-         testProperty "encode-decode-equality (String,String)"-         (encodeDecodeEq :: [(Int,Int)] -> Property),-         testProperty "encode-decode-error Int"-         (encodeDecodeError :: [Int] -> Property),-         testProperty "encode-decode-error String"-         (encodeDecodeError :: [String] -> Property),-         testProperty "encode-decode-error Maybe Int"-         (encodeDecodeError :: [Maybe Int] -> Property),-         testProperty "encode-decode-error Either Int String"-         (encodeDecodeError :: [Either Int String] -> Property),-         testProperty "encode-decode-error (Int,Int)"-         (encodeDecodeError :: [(Int,Int)] -> Property),-         testProperty "encode-decode-error (String,String)"-         (encodeDecodeError :: [(String,String)] -> Property)]
+ test/Test.hs view
@@ -0,0 +1,82 @@+{-# LANGUAGE ScopedTypeVariables #-}+module Main ( main ) where++import           Control.Exception        (catch, evaluate)+import           Data.Binary              (Binary)+import           Data.ByteString          (ByteString)+import qualified Data.ByteString          as S+import           System.IO.Streams        (write)+import           System.IO.Streams.Binary (DecodeException, decodeInputStream,+                                           encodeOutputStream)+import           System.IO.Streams.List   (fromList, outputToList, toList,+                                           writeList)+import           Test.QuickCheck.Monadic  (assert, monadicIO, run)+import           Test.QuickCheck.Property (Property)+import           Test.Tasty               (defaultMain, testGroup)+import           Test.Tasty.QuickCheck    (testProperty)+++-- Using binary-streams, decode from a list of bytestrings+decode :: Binary a => [ByteString] -> IO [a]+decode ss = fromList ss >>= decodeInputStream >>= toList++-- Using binary-streams, encode to a list of bytestrings+encode :: Binary a => [a] -> IO [ByteString]+encode xs = outputToList $ \os ->+  do+    bos <- encodeOutputStream os+    writeList xs bos+    write Nothing bos++-- Encode something, then decode it and make sure we get the same thing back.+encodeDecodeEq :: (Binary a,Eq a) => [a] -> Property+encodeDecodeEq xs = monadicIO $ do+  xs' <- run go+  assert $ xs == xs'+  where go = encode xs >>= decode++-- corrupt something, remove the last byte of the last bytestring+corrupt :: [ByteString] -> [ByteString]+corrupt = reverse . go . reverse+  where go (h:t) = ((S.reverse $ S.drop 1 $ S.reverse h):t)+        go [] = []++-- Encode something, corrupt the encoded data, and make sure we get a+-- decode error when we try do decode it.+encodeDecodeError :: forall a. (Binary a,Eq a) => [a] -> Property+encodeDecodeError [] = monadicIO $ return ()+encodeDecodeError xs = monadicIO $ do+  run $ catch go $ \(_ :: DecodeException) -> return ()+  where go =+         do+           bList <- encode xs+           (xs' :: [a]) <- decode $ corrupt bList+           evaluate xs'+           fail "decoding succeeded when it should fail"++main :: IO ()+main = defaultMain $ testGroup "tests" [+         testProperty "encode-decode-equality Int"+         (encodeDecodeEq :: [Int] -> Property),+         testProperty "encode-decode-equality String"+         (encodeDecodeEq :: [String] -> Property),+         testProperty "encode-decode-equality Maybe Int"+         (encodeDecodeEq :: [Maybe Int] -> Property),+         testProperty "encode-decode-equality Either Int String"+         (encodeDecodeEq :: [Either Int String] -> Property),+         testProperty "encode-decode-equality (Int,Int)"+         (encodeDecodeEq :: [(Int,Int)] -> Property),+         testProperty "encode-decode-equality (String,String)"+         (encodeDecodeEq :: [(Int,Int)] -> Property),+         testProperty "encode-decode-error Int"+         (encodeDecodeError :: [Int] -> Property),+         testProperty "encode-decode-error String"+         (encodeDecodeError :: [String] -> Property),+         testProperty "encode-decode-error Maybe Int"+         (encodeDecodeError :: [Maybe Int] -> Property),+         testProperty "encode-decode-error Either Int String"+         (encodeDecodeError :: [Either Int String] -> Property),+         testProperty "encode-decode-error (Int,Int)"+         (encodeDecodeError :: [(Int,Int)] -> Property),+         testProperty "encode-decode-error (String,String)"+         (encodeDecodeError :: [(String,String)] -> Property)]
wire-streams.cabal view
@@ -1,7 +1,7 @@ name:               wire-streams-version:            0.1.0.0-synopsis:           Use cereal or binary with io-streams.-description:        Use cereal or binary with io-streams.+version:            0.1.1.0+synopsis:           Fast binary io-streams adapter.+description:        Fast binary io-streams adapter.  license:            BSD3 license-file:       LICENSE@@ -30,17 +30,18 @@   ghc-options:      -Wall   default-language:     Haskell2010 -test-suite encode-decode-binary-  type:                 detailed-0.9-  test-module:          EncodeDecodeBinary+test-suite test+  type:                 exitcode-stdio-1.0+  main-is:              Test.hs   build-depends:        base                     ,   bytestring                     ,   binary                     ,   io-streams                     ,   wire-streams-                    ,   QuickCheck-                    ,   Cabal >= 1.10-                    ,   cabal-test-quickcheck+                    ,   QuickCheck >= 2.7+                    ,   tasty >= 0.11+                    ,   tasty-quickcheck >= 0.8+   hs-source-dirs:      test   default-language:    Haskell2010