Debian Codegraph @

internal/export/idna/gen_test.go

raw
1 // Copyright 2016 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 package idna
6
7 import (
8 "testing"
9 "unicode"
10
11 "golang.org/x/text/internal/gen"
12 "golang.org/x/text/internal/testtext"
13 "golang.org/x/text/internal/ucd"
14 )
15
16 func TestTables(t *testing.T) {
17 testtext.SkipIfNotLong(t)
18
19 lookup := func(r rune) info {
20 v, _ := trie.lookupString(string(r))
21 return info(v)
22 }
23
24 ucd.Parse(gen.OpenUnicodeFile("", "", "idna/IdnaMappingTable.txt"), func(p *ucd.Parser) {
25 r := p.Rune(0)
26 x := lookup(r)
27 if got, want := x.category(), catFromEntry(p); got != want {
28 t.Errorf("%U:category: got %x; want %x", r, got, want)
29 }
30
31 mapped := false
32 switch p.String(1) {
33 case "mapped", "disallowed_STD3_mapped", "deviation":
34 mapped = true
35 }
36 if x.isMapped() != mapped {
37 t.Errorf("%U:isMapped: got %v; want %v", r, x.isMapped(), mapped)
38 }
39 if !mapped {
40 return
41 }
42 want := string(p.Runes(2))
43 got := string(x.appendMapping(nil, string(r)))
44 if got != want {
45 t.Errorf("%U:mapping: got %+q; want %+q", r, got, want)
46 }
47
48 if x.isMapped() {
49 return
50 }
51 wantMark := unicode.In(r, unicode.Mark)
52 gotMark := x.isModifier()
53 if gotMark != wantMark {
54 t.Errorf("IsMark(%U) = %v; want %v", r, gotMark, wantMark)
55 }
56 })
57
58 ucd.Parse(gen.OpenUCDFile("UnicodeData.txt"), func(p *ucd.Parser) {
59 r := p.Rune(0)
60 x := lookup(r)
61 got := x.isViramaModifier()
62
63 const cccVirama = 9
64 want := p.Int(ucd.CanonicalCombiningClass) == cccVirama
65 if got != want {
66 t.Errorf("IsVirama(%U) = %v; want %v", r, got, want)
67 }
68
69 rtl := false
70 switch p.String(ucd.BidiClass) {
71 case "R", "AL", "AN":
72 rtl = true
73 }
74 if got := x.isBidi("A"); got != rtl && !x.isMapped() {
75 t.Errorf("IsBidi(%U) = %v; want %v", r, got, rtl)
76 }
77 })
78
79 ucd.Parse(gen.OpenUCDFile("extracted/DerivedJoiningType.txt"), func(p *ucd.Parser) {
80 r := p.Rune(0)
81 x := lookup(r)
82 if x.isMapped() {
83 return
84 }
85 got := x.joinType()
86 want := joinType[p.String(1)]
87 if got != want {
88 t.Errorf("JoinType(%U) = %x; want %x", r, got, want)
89 }
90 })
91 }