8func TestParseDomain(t *testing.T) {
9 test := func(lax bool, s string, exp Domain, expErr error) {
14 dom, err = ParseDomainLax(s)
16 dom, err = ParseDomain(s)
18 if (err == nil) != (expErr == nil) || expErr != nil && !errors.Is(err, expErr) {
19 t.Fatalf("parse domain %q: err %v, expected %v", s, err, expErr)
21 if expErr == nil && dom != exp {
22 t.Fatalf("parse domain %q: got %#v, epxected %#v", s, dom, exp)
26 // We rely on normalization of names throughout the code base.
27 test(false, "xmox.nl", Domain{"xmox.nl", ""}, nil)
28 test(false, "XMOX.NL", Domain{"xmox.nl", ""}, nil)
29 test(false, "TEST☺.XMOX.NL", Domain{"xn--test-3o3b.xmox.nl", "test☺.xmox.nl"}, nil)
30 test(false, "TEST☺.XMOX.NL", Domain{"xn--test-3o3b.xmox.nl", "test☺.xmox.nl"}, nil)
31 test(false, "ℂᵤⓇℒ。𝐒🄴", Domain{"curl.se", ""}, nil) // https://daniel.haxx.se/blog/2022/12/14/idn-is-crazy/
32 test(false, "xmox.nl.", Domain{}, errTrailingDot)
34 test(false, "_underscore.xmox.nl", Domain{}, errIDNA)
35 test(true, "_underscore.xmox.NL", Domain{ASCII: "_underscore.xmox.nl"}, nil)
36 test(true, "_underscore.☺.xmox.nl", Domain{}, errUnderscore)
37 test(true, "_underscore.xn--test-3o3b.xmox.nl", Domain{}, errUnderscore)