OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / net / idna / idna_test.go
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package idna
6
7 import (
8         "testing"
9 )
10
11 var idnaTestCases = [...]struct {
12         ascii, unicode string
13 }{
14         // Labels.
15         {"books", "books"},
16         {"xn--bcher-kva", "bücher"},
17
18         // Domains.
19         {"foo--xn--bar.org", "foo--xn--bar.org"},
20         {"golang.org", "golang.org"},
21         {"example.xn--p1ai", "example.рф"},
22         {"xn--czrw28b.tw", "商業.tw"},
23         {"www.xn--mller-kva.de", "www.müller.de"},
24 }
25
26 func TestIDNA(t *testing.T) {
27         for _, tc := range idnaTestCases {
28                 if a, err := ToASCII(tc.unicode); err != nil {
29                         t.Errorf("ToASCII(%q): %v", tc.unicode, err)
30                 } else if a != tc.ascii {
31                         t.Errorf("ToASCII(%q): got %q, want %q", tc.unicode, a, tc.ascii)
32                 }
33
34                 if u, err := ToUnicode(tc.ascii); err != nil {
35                         t.Errorf("ToUnicode(%q): %v", tc.ascii, err)
36                 } else if u != tc.unicode {
37                         t.Errorf("ToUnicode(%q): got %q, want %q", tc.ascii, u, tc.unicode)
38                 }
39         }
40 }
41
42 // TODO(nigeltao): test errors, once we've specified when ToASCII and ToUnicode
43 // return errors.