email-validate 2.1.0 → 2.1.1
raw patch · 3 files changed
+21/−5 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- email-validate.cabal +2/−2
- src/Text/Email/Parser.hs +6/−2
- tests/Main.hs +13/−1
email-validate.cabal view
@@ -1,5 +1,5 @@ name: email-validate -version: 2.1.0 +version: 2.1.1 license: BSD3 license-file: LICENSE author: George Pollard <porges@porg.es> @@ -19,7 +19,7 @@ source-repository this type: git location: git://github.com/Porges/email-validate-hs.git - tag: v2.1.0 + tag: v2.1.1 library build-depends:
src/Text/Email/Parser.hs view
@@ -29,10 +29,14 @@ show = show . toByteString instance Read EmailAddress where - readsPrec _ s = go (parse addrSpec $ BS.pack s) where + readsPrec _ ('"':s) = go (parse addrSpec $ BS.pack s) where go (Fail _ _ _) = [] go (Partial f) = go (f BS.empty) - go (Done r adr) = [(adr, BS.unpack r)] + go (Done r adr) = + case BS.unpack r of + ('"':r') -> [(adr, r')] + _ -> [] + readsPrec _ _ = [] -- | Converts an email address back to a ByteString toByteString :: EmailAddress -> ByteString
tests/Main.hs view
@@ -20,6 +20,7 @@ tests = [ testGroup "EmailAddress Show/Read instances" [ testProperty "showLikeByteString" prop_showLikeByteString, + testProperty "showAndReadBackWithoutQuoteFails" prop_showAndReadBackWithoutQuoteFails, testProperty "showAndReadBack" prop_showAndReadBack ], testGroup "QuickCheck Text.Email.Validate" [ @@ -58,7 +59,18 @@ prop_showLikeByteString email = show (toByteString email) == show email prop_showAndReadBack :: EmailAddress -> Bool -prop_showAndReadBack email = read (read (show email)) == email +prop_showAndReadBack email = read (show email) == email + +readMaybe :: String -> Maybe EmailAddress +readMaybe s = case reads s of + [(x, "")] -> Just x + _ -> Nothing + +prop_showAndReadBackWithoutQuoteFails :: EmailAddress -> Bool +prop_showAndReadBackWithoutQuoteFails email = + readMaybe (init s) == Nothing && + readMaybe (tail s) == Nothing + where s = show email --unitTest (x, y, z) = if not (isValid (BS.pack x) == y) then "" else (x ++" became "++ (case emailAddress (BS.pack x) of {Nothing -> "fail"; Just em -> show em}) ++": Should be "++show y ++", got "++show (not y)++"\n\t"++z++"\n")