1 // Copyright 2014 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.
9 // The code in this file generates captures and writes the tries generated in
10 // the examples to data_test.go. To invoke it, run:
11 // go test -tags=generate
13 // Making the generation code a "test" allows us to link in the necessary test
23 const tmpfile = "tmpout"
24 const dstfile = "data_test.go"
26 f, err := os.Create(tmpfile)
28 log.Fatalf("Could not create output file: %v", err)
30 defer os.Remove(tmpfile)
33 // We exit before this function returns, regardless of success or failure,
34 // so there's no need to save (and later restore) the existing genWriter
38 f.Write([]byte(header))
43 if err := exec.Command("gofmt", "-w", tmpfile).Run(); err != nil {
47 os.Rename(tmpfile, dstfile)
52 const header = `// This file is generated with "go test -tags generate". DO NOT EDIT!
58 // Stubs for generated tries. These are needed as we exclude data_test.go if
59 // the generate flag is set. This will clearly make the tests fail, but that
60 // is okay. It allows us to bootstrap.
64 func (t *trie) lookupString(string) (uint8, int) { return 0, 1 }
65 func (t *trie) lookupStringUnsafe(string) uint64 { return 0 }
67 func newRandTrie(i int) *trie { return &trie{} }
68 func newMultiTrie(i int) *trie { return &trie{} }