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:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user