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