| 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.27 |
| 6 |
|
| 7 |
package idna |
| 8 |
|
| 9 |
import ( |
| 10 |
"testing" |
| 11 |
|
| 12 |
"golang.org/x/text/internal/gen" |
| 13 |
"golang.org/x/text/internal/testtext" |
| 14 |
"golang.org/x/text/internal/ucd" |
| 15 |
) |
| 16 |
|
| 17 |
func TestConformance(t *testing.T) { |
| 18 |
testtext.SkipIfNotLong(t) |
| 19 |
|
| 20 |
r := gen.OpenUnicodeFile("", "", "idna/IdnaTestV2.txt") |
| 21 |
defer r.Close() |
| 22 |
|
| 23 |
section := "main" |
| 24 |
p := ucd.New(r) |
| 25 |
transitional := New(Transitional(true), VerifyDNSLength(true), BidiRule(), MapForLookup()) |
| 26 |
nonTransitional := New(VerifyDNSLength(true), BidiRule(), MapForLookup()) |
| 27 |
for p.Next() { |
| 28 |
var ( |
| 29 |
src = def(unescape(p.String(0)), "") |
| 30 |
toUnicode = def(unescape(p.String(1)), src) |
| 31 |
toUnicodeErr = p.String(2) |
| 32 |
toASCIIN = def(unescape(p.String(3)), toUnicode) |
| 33 |
toASCIINErr = def(p.String(4), toUnicodeErr) |
| 34 |
toASCIIT = def(unescape(p.String(5)), toASCIIN) |
| 35 |
toASCIITErr = def(p.String(6), toASCIINErr) |
| 36 |
) |
| 37 |
doTest(t, nonTransitional.ToUnicode, section+":ToUnicode", src, toUnicode, toUnicodeErr) |
| 38 |
doTest(t, nonTransitional.ToASCII, section+":ToASCII:N", src, toASCIIN, toASCIINErr) |
| 39 |
doTest(t, transitional.ToASCII, section+":ToASCII:T", src, toASCIIT, toASCIITErr) |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
func def(field, fallback string) string { |
| 44 |
if field == "" { |
| 45 |
return fallback |
| 46 |
} |
| 47 |
if field == `""` { |
| 48 |
return "" |
| 49 |
} |
| 50 |
return field |
| 51 |
} |