@@ -39,5 +39,70 @@ func TestIDNA(t *testing.T) {
39
39
}
40
40
}
41
41
42
+ func TestIDNASeparators (t * testing.T ) {
43
+ type subCase struct {
44
+ unicode string
45
+ wantASCII string
46
+ wantErr bool
47
+ }
48
+
49
+ testCases := []struct {
50
+ name string
51
+ profile * Profile
52
+ subCases []subCase
53
+ }{
54
+ {
55
+ name : "Punycode" , profile : Punycode ,
56
+ subCases : []subCase {
57
+ {"example\u3002 jp" , "xn--examplejp-ck3h" , false },
58
+ {"東京\uFF0E jp" , "xn--jp-l92cn98g071o" , false },
59
+ {"大阪\uFF61 jp" , "xn--jp-ku9cz72u463f" , false },
60
+ },
61
+ },
62
+ {
63
+ name : "Lookup" , profile : Lookup ,
64
+ subCases : []subCase {
65
+ {"example\u3002 jp" , "example.jp" , false },
66
+ {"東京\uFF0E jp" , "xn--1lqs71d.jp" , false },
67
+ {"大阪\uFF61 jp" , "xn--pssu33l.jp" , false },
68
+ },
69
+ },
70
+ {
71
+ name : "Display" , profile : Display ,
72
+ subCases : []subCase {
73
+ {"example\u3002 jp" , "example.jp" , false },
74
+ {"東京\uFF0E jp" , "xn--1lqs71d.jp" , false },
75
+ {"大阪\uFF61 jp" , "xn--pssu33l.jp" , false },
76
+ },
77
+ },
78
+ {
79
+ name : "Registration" , profile : Registration ,
80
+ subCases : []subCase {
81
+ {"example\u3002 jp" , "" , true },
82
+ {"東京\uFF0E jp" , "" , true },
83
+ {"大阪\uFF61 jp" , "" , true },
84
+ },
85
+ },
86
+ }
87
+ for _ , tc := range testCases {
88
+ t .Run (tc .name , func (t * testing.T ) {
89
+ for _ , c := range tc .subCases {
90
+ gotA , err := tc .profile .ToASCII (c .unicode )
91
+ if c .wantErr {
92
+ if err == nil {
93
+ t .Errorf ("ToASCII(%q): got no error, but an error expected" , c .unicode )
94
+ }
95
+ } else {
96
+ if err != nil {
97
+ t .Errorf ("ToASCII(%q): got err=%v, but no error expected" , c .unicode , err )
98
+ } else if gotA != c .wantASCII {
99
+ t .Errorf ("ToASCII(%q): got %q, want %q" , c .unicode , gotA , c .wantASCII )
100
+ }
101
+ }
102
+ }
103
+ })
104
+ }
105
+ }
106
+
42
107
// TODO(nigeltao): test errors, once we've specified when ToASCII and ToUnicode
43
108
// return errors.
0 commit comments