internal/export/idna: hoist conformance test
in preparation to deal with the new file format
in Unicode 11.
Updates golang/go#27945
Change-Id: I424b3891e852c87bea536646a98a96aae2446294
Reviewed-on: https://go-review.googlesource.com/c/text/+/154441
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/internal/export/idna/conformance_test.go b/internal/export/idna/conformance_test.go
new file mode 100644
index 0000000..580123e
--- /dev/null
+++ b/internal/export/idna/conformance_test.go
@@ -0,0 +1,70 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package idna
+
+import (
+ "fmt"
+ "strings"
+ "testing"
+
+ "golang.org/x/text/internal/gen"
+ "golang.org/x/text/internal/testtext"
+ "golang.org/x/text/internal/ucd"
+)
+
+func TestConformance(t *testing.T) {
+ testtext.SkipIfNotLong(t)
+
+ r := gen.OpenUnicodeFile("idna", "", "IdnaTest.txt")
+ defer r.Close()
+
+ section := "main"
+ p := ucd.New(r)
+ transitional := New(Transitional(true), VerifyDNSLength(true), BidiRule(), MapForLookup())
+ nonTransitional := New(VerifyDNSLength(true), BidiRule(), MapForLookup())
+ for p.Next() {
+ // What to test
+ profiles := []*Profile{}
+ switch p.String(0) {
+ case "T":
+ profiles = append(profiles, transitional)
+ case "N":
+ profiles = append(profiles, nonTransitional)
+ case "B":
+ profiles = append(profiles, transitional)
+ profiles = append(profiles, nonTransitional)
+ }
+
+ src := unescape(p.String(1))
+
+ wantToUnicode := unescape(p.String(2))
+ if wantToUnicode == "" {
+ wantToUnicode = src
+ }
+ wantToASCII := unescape(p.String(3))
+ if wantToASCII == "" {
+ wantToASCII = wantToUnicode
+ }
+ wantErrToUnicode := ""
+ if strings.HasPrefix(wantToUnicode, "[") {
+ wantErrToUnicode = wantToUnicode
+ wantToUnicode = ""
+ }
+ wantErrToASCII := ""
+ if strings.HasPrefix(wantToASCII, "[") {
+ wantErrToASCII = wantToASCII
+ wantToASCII = ""
+ }
+
+ // TODO: also do IDNA tests.
+ // invalidInIDNA2008 := p.String(4) == "NV8"
+
+ for _, p := range profiles {
+ name := fmt.Sprintf("%s:%s", section, p)
+ doTest(t, p.ToUnicode, name+":ToUnicode", src, wantToUnicode, wantErrToUnicode)
+ doTest(t, p.ToASCII, name+":ToASCII", src, wantToASCII, wantErrToASCII)
+ }
+ }
+}
diff --git a/internal/export/idna/idna_test.go b/internal/export/idna/idna_test.go
index 6290cd2..7235452 100644
--- a/internal/export/idna/idna_test.go
+++ b/internal/export/idna/idna_test.go
@@ -10,9 +10,7 @@
"strings"
"testing"
- "golang.org/x/text/internal/gen"
"golang.org/x/text/internal/testtext"
- "golang.org/x/text/internal/ucd"
)
func TestAllocToUnicode(t *testing.T) {
@@ -101,68 +99,6 @@
})
}
-func TestConformance(t *testing.T) {
- testtext.SkipIfNotLong(t)
-
- r := gen.OpenUnicodeFile("idna", "", "IdnaTest.txt")
- defer r.Close()
-
- section := "main"
- started := false
- p := ucd.New(r, ucd.CommentHandler(func(s string) {
- if started {
- section = strings.ToLower(strings.Split(s, " ")[0])
- }
- }))
- transitional := New(Transitional(true), VerifyDNSLength(true), BidiRule(), MapForLookup())
- nonTransitional := New(VerifyDNSLength(true), BidiRule(), MapForLookup())
- for p.Next() {
- started = true
-
- // What to test
- profiles := []*Profile{}
- switch p.String(0) {
- case "T":
- profiles = append(profiles, transitional)
- case "N":
- profiles = append(profiles, nonTransitional)
- case "B":
- profiles = append(profiles, transitional)
- profiles = append(profiles, nonTransitional)
- }
-
- src := unescape(p.String(1))
-
- wantToUnicode := unescape(p.String(2))
- if wantToUnicode == "" {
- wantToUnicode = src
- }
- wantToASCII := unescape(p.String(3))
- if wantToASCII == "" {
- wantToASCII = wantToUnicode
- }
- wantErrToUnicode := ""
- if strings.HasPrefix(wantToUnicode, "[") {
- wantErrToUnicode = wantToUnicode
- wantToUnicode = ""
- }
- wantErrToASCII := ""
- if strings.HasPrefix(wantToASCII, "[") {
- wantErrToASCII = wantToASCII
- wantToASCII = ""
- }
-
- // TODO: also do IDNA tests.
- // invalidInIDNA2008 := p.String(4) == "NV8"
-
- for _, p := range profiles {
- name := fmt.Sprintf("%s:%s", section, p)
- doTest(t, p.ToUnicode, name+":ToUnicode", src, wantToUnicode, wantErrToUnicode)
- doTest(t, p.ToASCII, name+":ToASCII", src, wantToASCII, wantErrToASCII)
- }
- }
-}
-
func unescape(s string) string {
s, err := strconv.Unquote(`"` + s + `"`)
if err != nil {