golang.org/x/text@v0.14.0/internal/export/idna/conformance_test.go (about) 1 // Copyright 2018 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 //go:build go1.10 6 7 package idna 8 9 import ( 10 "fmt" 11 "strings" 12 "testing" 13 14 "golang.org/x/text/internal/gen" 15 "golang.org/x/text/internal/testtext" 16 "golang.org/x/text/internal/ucd" 17 ) 18 19 func TestConformance(t *testing.T) { 20 testtext.SkipIfNotLong(t) 21 22 r := gen.OpenUnicodeFile("idna", "10.0.0", "IdnaTest.txt") 23 defer r.Close() 24 25 section := "main" 26 p := ucd.New(r) 27 transitional := New(Transitional(true), VerifyDNSLength(true), BidiRule(), MapForLookup()) 28 nonTransitional := New(VerifyDNSLength(true), BidiRule(), MapForLookup()) 29 for p.Next() { 30 // What to test 31 profiles := []*Profile{} 32 switch p.String(0) { 33 case "T": 34 profiles = append(profiles, transitional) 35 case "N": 36 profiles = append(profiles, nonTransitional) 37 case "B": 38 profiles = append(profiles, transitional) 39 profiles = append(profiles, nonTransitional) 40 } 41 42 src := unescape(p.String(1)) 43 44 wantToUnicode := unescape(p.String(2)) 45 if wantToUnicode == "" { 46 wantToUnicode = src 47 } 48 wantToASCII := unescape(p.String(3)) 49 if wantToASCII == "" { 50 wantToASCII = wantToUnicode 51 } 52 wantErrToUnicode := "" 53 if strings.HasPrefix(wantToUnicode, "[") { 54 wantErrToUnicode = wantToUnicode 55 wantToUnicode = "" 56 } 57 wantErrToASCII := "" 58 if strings.HasPrefix(wantToASCII, "[") { 59 wantErrToASCII = wantToASCII 60 wantToASCII = "" 61 } 62 63 // TODO: also do IDNA tests. 64 // invalidInIDNA2008 := p.String(4) == "NV8" 65 66 for _, p := range profiles { 67 name := fmt.Sprintf("%s:%s", section, p) 68 doTest(t, p.ToUnicode, name+":ToUnicode", src, wantToUnicode, wantErrToUnicode) 69 doTest(t, p.ToASCII, name+":ToASCII", src, wantToASCII, wantErrToASCII) 70 } 71 } 72 }