1 // Copyright 2012 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.
11 // We take the smallest, largest and an arbitrary value for each
12 // of the UTF-8 sequence lengths.
13 var testRunes = []rune{
14 0x01, 0x0C, 0x7F, // 1-byte sequences
15 0x80, 0x100, 0x7FF, // 2-byte sequences
16 0x800, 0x999, 0xFFFF, // 3-byte sequences
17 0x10000, 0x10101, 0x10FFFF, // 4-byte sequences
18 0x200, 0x201, 0x202, 0x210, 0x215, // five entries in one sparse block
21 // Test cases for illegal runes.
22 type trietest struct {
27 var tests = []trietest{
31 {1, []byte{t2, tx - 1}},
33 {2, []byte{t3, tx, tx - 1}},
34 {2, []byte{t3, tx, t2}},
35 {1, []byte{t3, tx - 1, tx}},
36 {3, []byte{t4, tx, tx, tx - 1}},
37 {3, []byte{t4, tx, tx, t2}},
38 {1, []byte{t4, t2, tx, tx - 1}},
39 {2, []byte{t4, tx, t2, tx - 1}},
44 {0, []byte{t4, tx, tx}},
46 // we only support UTF-8 up to utf8.UTFMax bytes (4 bytes)
47 {1, []byte{t5, tx, tx, tx, tx}},
48 {1, []byte{t6, tx, tx, tx, tx, tx}},
51 func TestLookupTrie(t *testing.T) {
52 for i, r := range testRunes {
53 b := []byte(string(r))
54 v, sz := testTrie.lookup(b)
56 t.Errorf("lookup(%U): found value %#x, expected %#x", r, v, i)
59 t.Errorf("lookup(%U): found size %d, expected %d", r, sz, len(b))
62 for i, tt := range tests {
63 v, sz := testTrie.lookup(tt.bytes)
65 t.Errorf("lookup of illegal rune, case %d: found value %#x, expected 0", i, v)
68 t.Errorf("lookup of illegal rune, case %d: found size %d, expected %d", i, sz, tt.size)
73 // test data is taken from exp/collate/locale/build/trie_test.go
74 var testValues = [832]uint32{
79 0x0140: 0x0000000c, 0x0141: 0x0000000d, 0x0142: 0x0000000e,
91 var testLookup = [640]uint16{
92 0x0e0: 0x05, 0x0e6: 0x06,
94 0x140: 0x08, 0x144: 0x09,
98 0x242: 0x01, 0x244: 0x02,
103 0x270: 0x04, 0x274: 0x06,
106 var testTrie = Trie{testLookup[6*blockSize:], testValues[:], testLookup[:], testValues[:]}