-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from nao1215/nchika/add-email-tag
Add email tag
- Loading branch information
Showing
9 changed files
with
88 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -528,4 +528,41 @@ ABC | |
} | ||
} | ||
}) | ||
|
||
t.Run("validate email", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
input := `email | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
admin@mailserver1 | ||
badあ@example.com | ||
` | ||
|
||
c, err := NewCSV(bytes.NewBufferString(input)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
type email struct { | ||
Email string `validate:"email"` | ||
} | ||
|
||
emails := make([]email, 0) | ||
errs := c.Decode(&emails) | ||
for i, err := range errs { | ||
switch i { | ||
case 0: | ||
if err.Error() != "line:6 column email: target is not a valid email address: value=admin@mailserver1" { | ||
t.Errorf("CSV.Decode() got errors: %v", err) | ||
} | ||
case 1: | ||
if err.Error() != "line:7 column email: target is not a valid email address: value=badあ@example.com" { | ||
t.Errorf("CSV.Decode() got errors: %v", err) | ||
} | ||
} | ||
} | ||
}) | ||
} |
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 |
---|---|---|
|
@@ -72,3 +72,6 @@ | |
|
||
- id: "ErrASCII" | ||
translation: "値がASCII文字ではありません" | ||
|
||
- id: "ErrEmail" | ||
translation: "値がメールアドレスではありません" |
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
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