-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use mrmime to validate email address
- Loading branch information
Showing
3 changed files
with
54 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
let validate_email_adress () = | ||
let open Pool_user in | ||
let check_result expected generated = | ||
let open Alcotest in | ||
let email = testable EmailAddress.pp EmailAddress.equal in | ||
check (result email Test_utils.error) "succeeds" expected generated | ||
in | ||
let valid_addresses = | ||
[ "[email protected]" | ||
; "[email protected]" | ||
; "[email protected]" | ||
; "[email protected]" | ||
; "[email protected]" | ||
; "[email protected]" | ||
; "[email protected]" | ||
; "[email protected]" | ||
] | ||
in | ||
let invalid_addresses = | ||
[ "plainaddress" | ||
; "email.example.com" | ||
; "[email protected]" | ||
; "verycommon;@example.com" | ||
; "[email protected]" | ||
; "very common;@example.com" | ||
; "[email protected]" | ||
; "p;@hotmail.com" | ||
] | ||
in | ||
let () = | ||
CCList.iter | ||
(fun email -> | ||
let expected = Ok (EmailAddress.of_string email) in | ||
let result = EmailAddress.create email in | ||
check_result expected result) | ||
valid_addresses | ||
in | ||
CCList.iter | ||
(fun email -> | ||
let expected = Error Pool_common.Message.(Invalid Field.EmailAddress) in | ||
let result = EmailAddress.create email in | ||
check_result expected result) | ||
invalid_addresses | ||
;; |