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.
13 // We take the smallest, largest and an arbitrary value for each
14 // of the UTF-8 sequence lengths.
15 var testRunes = []rune{
16 0x01, 0x0C, 0x7F, // 1-byte sequences
17 0x80, 0x100, 0x7FF, // 2-byte sequences
18 0x800, 0x999, 0xFFFF, // 3-byte sequences
19 0x10000, 0x10101, 0x10FFFF, // 4-byte sequences
20 0x200, 0x201, 0x202, 0x210, 0x215, // five entries in one sparse block
23 func makeTestTrie(t *testing.T) trie {
25 for i, r := range testRunes {
26 n.insert(r, uint32(i))
28 idx := newTrieBuilder()
30 tr, err := idx.generate()
37 func TestGenerateTrie(t *testing.T) {
38 testdata := makeTestTrie(t)
39 buf := &bytes.Buffer{}
40 testdata.printArrays(buf, "test")
41 fmt.Fprintf(buf, "var testTrie = ")
42 testdata.printStruct(buf, &trieHandle{19, 0}, "test")
43 if output != buf.String() {
44 t.Error("output differs")
48 var output = `// testValues: 832 entries, 3328 bytes
49 // Block 2 is the null block.
50 var testValues = [832]uint32 {
51 // Block 0x0, offset 0x0
53 // Block 0x1, offset 0x40
55 // Block 0x2, offset 0x80
56 // Block 0x3, offset 0xc0
58 // Block 0x4, offset 0x100
60 // Block 0x5, offset 0x140
61 0x0140:0x0000000c, 0x0141:0x0000000d, 0x0142:0x0000000e,
64 // Block 0x6, offset 0x180
66 // Block 0x7, offset 0x1c0
68 // Block 0x8, offset 0x200
70 // Block 0x9, offset 0x240
72 // Block 0xa, offset 0x280
74 // Block 0xb, offset 0x2c0
76 // Block 0xc, offset 0x300
80 // testLookup: 640 entries, 1280 bytes
81 // Block 0 is the null block.
82 var testLookup = [640]uint16 {
83 // Block 0x0, offset 0x0
84 // Block 0x1, offset 0x40
85 // Block 0x2, offset 0x80
86 // Block 0x3, offset 0xc0
87 0x0e0:0x05, 0x0e6:0x06,
88 // Block 0x4, offset 0x100
90 // Block 0x5, offset 0x140
91 0x140:0x08, 0x144:0x09,
92 // Block 0x6, offset 0x180
94 // Block 0x7, offset 0x1c0
96 // Block 0x8, offset 0x200
98 // Block 0x9, offset 0x240
99 0x242:0x01, 0x244:0x02,
104 0x270:0x04, 0x274:0x06,
107 var testTrie = trie{ testLookup[1216:], testValues[0:], testLookup[:], testValues[:]}`