-
Notifications
You must be signed in to change notification settings - Fork 18
/
is_domain_test.go
36 lines (33 loc) · 1.21 KB
/
is_domain_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package isdomain
import "testing"
func TestBasic(t *testing.T) {
cases := map[string]bool{
"foo.bar.baz.com": true,
"foo.bar.baz": false,
"foo.bar.baz.com.": true,
"com": false, // yeah yeah...
".": false, // yeah yeah...
"..": false,
".com": false,
".com.": false,
"com.": false,
"com..": false,
".foo.com.": false,
".foo.com": false,
"fo o.com": false,
"example.com": true,
"fjdoisajfdiosafdsa8fd8saf8dsa8fdsafdsa-fd-sa-fd-saf-dsa.org": true,
"fjdoisajfdiosafdsa8fd8saf8dsa8fdsafdsa-fd-sa-fd-saf-dsa.bit": true,
"fjdoisajfdiosafdsa8fd8saf8dsa8fdsafdsa-fd-sa-fd-saf-dsa.onion": true,
"a.b.c.d.e.f.g.h.i.j.k.l.museum": true,
"a.b.c.d.e.f.g.h.i.j.k.l": false,
"_dnslink.example.com": false,
"example._dnslink.com": false,
"example.com._dnslink": false,
}
for d, ok := range cases {
if IsDomain(d) != ok {
t.Errorf("Misclassification: %v should be %v", d, ok)
}
}
}