35 lines
818 B
Haskell
35 lines
818 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\
|
|
\Dkim: asd\n\
|
|
\To: you <you@example.com>\n\
|
|
\\n\n\
|
|
\From: foo bar <a mailto=\"me2@example.com\" />\n\
|
|
\asd\n"
|
|
|
|
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"]]
|
|
]
|