...
1 package rangetable
2
3 import (
4 "reflect"
5 "testing"
6 "unicode"
7 )
8
9 var (
10 empty = &unicode.RangeTable{}
11 many = &unicode.RangeTable{
12 R16: []unicode.Range16{{0, 0xffff, 5}},
13 R32: []unicode.Range32{{0x10004, 0x10009, 5}},
14 LatinOffset: 0,
15 }
16 )
17
18 func TestVisit(t *testing.T) {
19 Visit(empty, func(got rune) {
20 t.Error("call from empty RangeTable")
21 })
22
23 var want rune
24 Visit(many, func(got rune) {
25 if got != want {
26 t.Errorf("got %U; want %U", got, want)
27 }
28 want += 5
29 })
30 if want -= 5; want != 0x10009 {
31 t.Errorf("last run was %U; want U+10009", want)
32 }
33 }
34
35 func TestNew(t *testing.T) {
36 for i, rt := range []*unicode.RangeTable{
37 empty,
38 unicode.Co,
39 unicode.Letter,
40 unicode.ASCII_Hex_Digit,
41 many,
42 maxRuneTable,
43 } {
44 var got, want []rune
45 Visit(rt, func(r rune) {
46 want = append(want, r)
47 })
48 Visit(New(want...), func(r rune) {
49 got = append(got, r)
50 })
51 if !reflect.DeepEqual(got, want) {
52 t.Errorf("%d:\ngot %v;\nwant %v", i, got, want)
53 }
54 }
55 }
56
View as plain text