idna_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. package idna
  5. import (
  6. "testing"
  7. )
  8. var idnaTestCases = [...]struct {
  9. ascii, unicode string
  10. }{
  11. // Labels.
  12. {"books", "books"},
  13. {"xn--bcher-kva", "bücher"},
  14. // Domains.
  15. {"foo--xn--bar.org", "foo--xn--bar.org"},
  16. {"golang.org", "golang.org"},
  17. {"example.xn--p1ai", "example.рф"},
  18. {"xn--czrw28b.tw", "商業.tw"},
  19. {"www.xn--mller-kva.de", "www.müller.de"},
  20. }
  21. func TestIDNA(t *testing.T) {
  22. for _, tc := range idnaTestCases {
  23. if a, err := ToASCII(tc.unicode); err != nil {
  24. t.Errorf("ToASCII(%q): %v", tc.unicode, err)
  25. } else if a != tc.ascii {
  26. t.Errorf("ToASCII(%q): got %q, want %q", tc.unicode, a, tc.ascii)
  27. }
  28. if u, err := ToUnicode(tc.ascii); err != nil {
  29. t.Errorf("ToUnicode(%q): %v", tc.ascii, err)
  30. } else if u != tc.unicode {
  31. t.Errorf("ToUnicode(%q): got %q, want %q", tc.ascii, u, tc.unicode)
  32. }
  33. }
  34. }
  35. // TODO(nigeltao): test errors, once we've specified when ToASCII and ToUnicode
  36. // return errors.