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 func TestFinderNext(t *testing.T) {
14 testCases := []struct {
24 {"pan", "anpanman", 2},
25 {"nnaaman", "anpanmanam", -1},
32 {"at that", "which finally halts. at that point", 22},
35 for _, tc := range testCases {
36 got := StringFind(tc.pat, tc.text)
39 t.Errorf("stringFind(%q, %q) got %d, want %d\n", tc.pat, tc.text, got, want)
44 func TestFinderCreation(t *testing.T) {
45 testCases := []struct {
52 [256]int{'a': 2, 'b': 1, 'c': 3},
57 [256]int{'i': 3, 'm': 7, 's': 1},
58 []int{15, 14, 13, 7, 11, 10, 7, 1},
60 // From http://www.cs.utexas.edu/~moore/publications/fstrpos.pdf
63 [256]int{'a': 2, 'b': 1, 'c': 6, 'x': 3},
64 []int{14, 13, 12, 11, 10, 9, 11, 10, 1},
68 [256]int{'a': 8, 'b': 7, 'c': 4, 'd': 3, 'e': 2, 'y': 1, 'x': 5},
69 []int{17, 16, 15, 14, 13, 12, 7, 10, 1},
73 for _, tc := range testCases {
74 bad, good := DumpTables(tc.pattern)
76 for i, got := range bad {
79 want = len(tc.pattern)
82 t.Errorf("boyerMoore(%q) bad['%c']: got %d want %d", tc.pattern, i, got, want)
86 if !reflect.DeepEqual(good, tc.suf) {
87 t.Errorf("boyerMoore(%q) got %v want %v", tc.pattern, good, tc.suf)