1
2
3
4
5 package bidi
6
7 import (
8 "testing"
9
10 "golang.org/x/text/internal/gen"
11 "golang.org/x/text/internal/testtext"
12 "golang.org/x/text/internal/ucd"
13 )
14
15 var labels = []string{
16 AL: "AL",
17 AN: "AN",
18 B: "B",
19 BN: "BN",
20 CS: "CS",
21 EN: "EN",
22 ES: "ES",
23 ET: "ET",
24 L: "L",
25 NSM: "NSM",
26 ON: "ON",
27 R: "R",
28 S: "S",
29 WS: "WS",
30
31 LRO: "LRO",
32 RLO: "RLO",
33 LRE: "LRE",
34 RLE: "RLE",
35 PDF: "PDF",
36 LRI: "LRI",
37 RLI: "RLI",
38 FSI: "FSI",
39 PDI: "PDI",
40 }
41
42 func TestTables(t *testing.T) {
43 testtext.SkipIfNotLong(t)
44
45 ucd.Parse(gen.OpenUCDFile("BidiBrackets.txt"), func(p *ucd.Parser) {
46 r1 := p.Rune(0)
47 want := p.Rune(1)
48
49 e, _ := LookupRune(r1)
50 if got := e.reverseBracket(r1); got != want {
51 t.Errorf("Reverse(%U) = %U; want %U", r1, got, want)
52 }
53 })
54
55 done := map[rune]bool{}
56 test := func(name string, r rune, want string) {
57 str := string(r)
58 e, _ := LookupString(str)
59 if got := labels[e.Class()]; got != want {
60 t.Errorf("%s:%U: got %s; want %s", name, r, got, want)
61 }
62 if e2, sz := LookupRune(r); e != e2 || sz != len(str) {
63 t.Errorf("LookupRune(%U) = %v, %d; want %v, %d", r, e2, e, sz, len(str))
64 }
65 if e2, sz := Lookup([]byte(str)); e != e2 || sz != len(str) {
66 t.Errorf("Lookup(%U) = %v, %d; want %v, %d", r, e2, e, sz, len(str))
67 }
68 done[r] = true
69 }
70
71
72 ucd.Parse(gen.OpenUCDFile("extracted/DerivedBidiClass.txt"), func(p *ucd.Parser) {
73 r := p.Rune(0)
74 test("derived", r, p.String(1))
75 })
76 visitDefaults(func(r rune, c Class) {
77 if !done[r] {
78 test("default", r, labels[c])
79 }
80 })
81
82 }
83
View as plain text