blob: b1bc6fa225ca474a47442f1e5ddfac39ec5d1c4b [file] [log] [blame]
Nigel Tao7db922b2012-12-14 08:44:53 +11001// 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
5package idna
6
7import (
8 "testing"
9)
10
11var 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
26func 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.