Added pAuthorLine and tests

This commit is contained in:
2014-02-27 23:59:58 -07:00
parent 81fa9981d7
commit 89a146a36c
2 changed files with 91 additions and 6 deletions

View File

@@ -92,3 +92,43 @@ headerParseSpec = do
parseOnly pTitle "A two-line level 4 title\n++\n"
`shouldBe` Right (4, "A two-line level 4 title")
describe "Document Author" $ do
describe "pAuthorLine" $ do
it "parses a line with just a first name" $
parseOnly pAuthorLine "Joe\n"
`shouldBe` Right (Author ["Joe"] Nothing Nothing Nothing)
it "parses a line with a two-word first name" $
parseOnly pAuthorLine "Joe_Dee\n"
`shouldBe` Right (Author ["Joe", "Dee"] Nothing Nothing Nothing)
it "parses a line with a first and last name" $
parseOnly pAuthorLine "Joe Bloggs\n"
`shouldBe` Right (Author ["Joe"] Nothing (Just ["Bloggs"]) Nothing)
it "parses a line with two first and two last names" $
parseOnly pAuthorLine "Joe_Dee de_Winter\n"
`shouldBe`
Right (Author ["Joe", "Dee"] Nothing (Just ["de", "Winter"]) Nothing)
it "parses a first, middle, and last name" $
parseOnly pAuthorLine "Joe Jay Bloggs\n"
`shouldBe`
Right (Author ["Joe"] (Just ["Jay"]) (Just ["Bloggs"]) Nothing)
it "parses multiple first, middle, and last names" $
parseOnly pAuthorLine "Joe_Dee Dee_Ann de_Winter\n"
`shouldBe`
Right (Author ["Joe", "Dee"]
(Just ["Dee", "Ann"])
(Just ["de", "Winter"]) Nothing)
it "parses first name and email address" $
parseOnly pAuthorLine "Joe <JoeBloggs@mail.com>\n"
`shouldBe`
Right (Author ["Joe"] Nothing Nothing (Just "JoeBloggs@mail.com"))
it "parses first and last names and email address" $
parseOnly pAuthorLine "Joe Bloggs <JoeBloggs@mail.com>\n"
`shouldBe`
Right (Author ["Joe"] Nothing (Just ["Bloggs"]) (Just "JoeBloggs@mail.com"))
it "Parses first, middle and last names and email address" $
parseOnly pAuthorLine "Joe Jay Bloggs <JoeBloggs@mail.com>\n"
`shouldBe`
Right (Author ["Joe"]
(Just ["Jay"])
(Just ["Bloggs"]) (Just "JoeBloggs@mail.com"))