1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-19 14:57:04 +00:00

test: Add small miscellaneous tests

This patch extends various packages and integration tests, increasing
test coverage. They're small enough that it's not worth splitting them
up, as it would add a lot of noise to the history.
This commit is contained in:
Alberto Bertogli
2018-03-02 16:14:10 +00:00
parent d80c76f746
commit 0611b7a7fc
7 changed files with 149 additions and 9 deletions

View File

@@ -78,11 +78,10 @@ func TestAddr(t *testing.T) {
if err != nil {
t.Errorf("%q error: %v", c.user, err)
}
}
invalid := []string{
"á é@i", "henry\u2163@throne",
"á é@i", "henry\u2163@throne", "a@xn---",
}
for _, u := range invalid {
nu, err := Addr(u)
@@ -94,3 +93,38 @@ func TestAddr(t *testing.T) {
}
}
}
func TestDomainToUnicode(t *testing.T) {
valid := []struct{ domain, expected string }{
{"<>", "<>"},
{"a@b", "a@b"},
{"a@Ñ", "a@ñ"},
{"xn--lca@xn--lca", "xn--lca@ñ"}, // Punycode is for 'Ñ'.
{"a@e\u0301", "a@é"}, // Transform to NFC form.
// Degenerate case, we don't expect to ever produce this; at least
// check it does not crash.
{"", "@"},
}
for _, c := range valid {
got, err := DomainToUnicode(c.domain)
if got != c.expected {
t.Errorf("DomainToUnicode(%q) = %q, expected %q",
c.domain, got, c.expected)
}
if err != nil {
t.Errorf("DomainToUnicode(%q) error: %v", c.domain, err)
}
}
invalid := []string{"a@xn---", "a@xn--xyz-ñ"}
for _, u := range invalid {
got, err := DomainToUnicode(u)
if err == nil {
t.Errorf("expected DomainToUnicode(%+q) to fail, but did not", u)
}
if got != u {
t.Errorf("%+q failed norm, but returned %+q", u, got)
}
}
}