diff options
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 + + + |