diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2012-09-28 23:50:52 +0200 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2012-09-28 23:50:52 +0200 |
commit | 52d0b5284170588b24573164e60f99a4001f9b9d (patch) | |
tree | 45685caa51c80da564035e65717a19b9ca5b5298 /Test/Layer2.hs | |
parent | 1270abb4ce6842d3b66f792d23358b97a530c4d5 (diff) | |
download | haskell-ebus-master.tar.gz haskell-ebus-master.zip |
Diffstat (limited to 'Test/Layer2.hs')
-rw-r--r-- | Test/Layer2.hs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Test/Layer2.hs b/Test/Layer2.hs new file mode 100644 index 0000000..d50535f --- /dev/null +++ b/Test/Layer2.hs @@ -0,0 +1,57 @@ +module Test.Layer2 (tests) where + +import Data.ByteString (ByteString, pack) +import Data.Enumerator (Enumerator, Iteratee, enumLists, run, ($$)) +import Data.Word (Word8) +import Data.Attoparsec.Enumerator (iterParser, ParseError, errorContexts) +import Control.Exception (SomeException) + +import Network.EBus.Layer2 + +import Data.Either +import Test.HUnit +import Test.HUnit.Base + +import Control.Monad + +tests = [TestCase testcase] + + + + +testcase :: IO() +testcase = do + let x = parsePackageFromList [170,170,241,254,5,3,8,1,1,16,255,88,255,60,9,247] + join $ liftM foooo x + -- where + -- testResults :: (Monad m) => m(Either SomeException EbusPacket) -> m() + -- testResults s = do + -- let z = case s of + -- Right x -> print "true" + -- Left y -> print "false" + -- if z then print "foo" else print "bl" + where foooo xs = do + case xs of + Right _ -> print "success" + Left e -> fail (show e) + + +-- * Utils + +-- | Take a list and parse as ebus datastream +parsePackageFromList :: [Word8] -> IO (Either SomeException EbusPacket) +parsePackageFromList xs = + run ( listEnumerator xs $$ parserIteratee ) + + +-- | Transform List xs into a Enumerator +listEnumerator :: [Word8] -> Enumerator ByteString IO a +listEnumerator xs = enumLists l + where l::[[ByteString]] + l = [[pack xs]] + +parserIteratee :: Iteratee ByteString IO EbusPacket +parserIteratee = iterParser ebusParserLayer2 + + + |