addressbook/test/Test/Data/Email.hs

35 lines
818 B
Haskell
Raw Normal View History

2020-12-10 22:22:46 +02:00
{-# 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\
2020-12-11 17:53:08 +02:00
\Dkim: asd\n\
2020-12-10 22:22:46 +02:00
\To: you <you@example.com>\n\
2020-12-11 17:53:08 +02:00
\\n\n\
\From: foo bar <a mailto=\"me2@example.com\" />\n\
\asd\n"
2020-12-10 22:22:46 +02:00
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"]]
]