From 52d0b5284170588b24573164e60f99a4001f9b9d Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Fri, 28 Sep 2012 23:50:52 +0200 Subject: save modification - no idea --- Test/Layer2.hs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Test/Layer2.hs (limited to 'Test') 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 + + + -- cgit v1.2.1