1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
|