@@ -62,23 +62,26 @@ func Test_ParseAndValidateEmailAddress_Given_EmailAddressesWithQuotesOrIpDomains
6262 }
6363}
6464
65- func Test_ParseAndValidateEmailAddress_Given_AddressWithUppercase_Should_ReturnError (t * testing.T ) {
65+ func Test_ParseAndValidateEmailAddress_Given_AddressWithUppercase_Should_NormalizeToLowercase (t * testing.T ) {
6666 ev := EmailValidator {}
6767
68- testCases := []string {
69- "John Doe <John.Doe@Example.com>" , // full name with angle brackets
70- " John.Doe@Example.com" , // leading whitespaces
71- "\t \t John.Doe@Example.com" , // leading tabs
72- "John.Doe@Example.com " , // trailing whitespaces
73- "John.Doe@Example.com\t " , // trailing tabs
74- "John.Doe+tag@Example.com" , // with plus tag
68+ testCases := []struct {
69+ input string
70+ expected string
71+ }{
72+ {"John Doe <John.Doe@Example.com>" , "john.doe@example.com" },
73+ {" John.Doe@Example.com" , "john.doe@example.com" },
74+ {"\t \t John.Doe@Example.com" , "john.doe@example.com" },
75+ {"John.Doe@Example.com " , "john.doe@example.com" },
76+ {"John.Doe@Example.com\t " , "john.doe@example.com" },
77+ {"John.Doe+tag@Example.com" , "john.doe+tag@example.com" },
7578 }
7679
7780 for _ , tc := range testCases {
78- valid , parsedAddress , err := ev .ParseAndValidateEmailAddress (tc )
81+ valid , parsedAddress , err := ev .ParseAndValidateEmailAddress (tc . input )
7982
80- require .False (t , valid )
81- require .Nil (t , parsedAddress )
82- require .Equal (t , "error_email_format_lowercase" , * err )
83+ require .True (t , valid )
84+ require .Nil (t , err )
85+ require .Equal (t , tc . expected , * parsedAddress )
8386 }
8487}
0 commit comments