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