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