Parse headers from an email
This commit is contained in:
32
test/Test/Data/Email.hs
Normal file
32
test/Test/Data/Email.hs
Normal file
@ -0,0 +1,32 @@
|
||||
{-# 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"]]
|
||||
]
|
Reference in New Issue
Block a user