Browse files

Adding tests, updating LICENSE

  • Loading branch information...
1 parent 938e2d2 commit 4b003491a346b97bd1ad0ea0334dcada33b3351b @litherum committed Apr 6, 2012
Showing with 55 additions and 1 deletion.
  1. +1 −1 LICENSE
  2. +45 −0 Test/CerealConduit.hs
  3. +9 −0 cereal-conduit.cabal
View
2 LICENSE
@@ -1,7 +1,7 @@
The following license covers this documentation, and the source code, except
where otherwise indicated.
-Copyright 2010, Michael Snoyman. All rights reserved.
+Copyright 2012, Myles C. Maxfield. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
View
45 Test/CerealConduit.hs
@@ -0,0 +1,45 @@
+module Test.CerealConduit (tests) where
+
+import Control.Monad.Identity
+import Test.HUnit
+import qualified Data.Conduit as C
+import Data.Conduit.Cereal
+import Data.Conduit.List
+import Data.Serialize
+import qualified Data.ByteString as BS
+import Test.Framework.Providers.HUnit
+import System.Exit
+
+test1 :: Test
+test1 = TestCase (assertEqual "Handles starting with empty bytestring"
+ (Right 1)
+ (runIdentity $ (sourceList [BS.pack [], BS.pack [1]]) C.$$ (sinkGet getWord8)))
+
+test2 :: Test
+test2 = TestCase (assertEqual "Handles empty bytestring in middle"
+ (Right [1, 3])
+ (runIdentity $ (sourceList [BS.pack [1], BS.pack [], BS.pack [3]]) C.$$ (sinkGet (do
+ x <- getWord8
+ y <- getWord8
+ return [x, y]))))
+
+test3 :: Test
+test3 = TestCase (assertBool "Handles no data"
+ (case (runIdentity $ (sourceList []) C.$$ (sinkGet getWord8)) of
+ Right _ -> False
+ Left _ -> True))
+
+test4 :: Test
+test4 = TestCase (assertEqual "Consumes no data"
+ (Right ())
+ (runIdentity $ (sourceList [BS.pack [1]]) C.$$ (sinkGet $ return ())))
+
+hunittests = TestList [test1, test2, test3, test4]
+
+tests = hUnitTestToTests hunittests
+
+main = do
+ counts <- runTestTT hunittests
+ if errors counts == 0 && failures counts == 0
+ then exitSuccess
+ else exitFailure
View
9 cereal-conduit.cabal
@@ -21,6 +21,15 @@ library
exposed-modules: Data.Conduit.Cereal
ghc-options: -Wall
+Test-Suite test-cereal-conduit
+ type: exitcode-stdio-1.0
+ main-is: Test/CerealConduit.hs
+ build-depends: base >= 4 && < 5
+ , conduit >= 0.4.0 && < 0.5.0
+ , cereal >= 0.3.1.0
+ , mtl
+ , bytestring
+ , test-framework-hunit
source-repository head
type: git

0 comments on commit 4b00349

Please sign in to comment.