addressbook/test/Test/Data/Email.hs

33 lines
749 B
Haskell

{-# LANGUAGE OverloadedLists #-}
module Test.Data.Email where
import Test.Tasty
import Test.Tasty.HUnit
import Data.ByteString.Lazy.Char8 (ByteString)
import qualified Data.Conduit.List as CL
import qualified Data.Conduit.Binary as CB
import Conduit
import Data.Email.Header
import Data.Email
sample :: ByteString
sample =
"Subject: Hello worldddd\n\
\From: me@example.com\n\
\To: you <you@example.com>\n\
\ \n\n \
\foo"
parseToList :: ByteString -> IO [Header]
parseToList _ = runConduit (CB.sourceLbs sample .| parseEmail .| CL.consume)
tests :: TestTree
tests = testGroup "Data.Email"
[ testCase "Can parse a sample email" $ do
got <- parseToList sample
got @?= [ From "me@example.com", To ["you@example.com"]]
]