...
1 package match
2
3 import (
4 "reflect"
5 "testing"
6 )
7
8 func TestTextIndex(t *testing.T) {
9 for id, test := range []struct {
10 text string
11 fixture string
12 index int
13 segments []int
14 }{
15 {
16 "b",
17 "abc",
18 1,
19 []int{1},
20 },
21 {
22 "f",
23 "abcd",
24 -1,
25 nil,
26 },
27 } {
28 m := NewText(test.text)
29 index, segments := m.Index(test.fixture)
30 if index != test.index {
31 t.Errorf("#%d unexpected index: exp: %d, act: %d", id, test.index, index)
32 }
33 if !reflect.DeepEqual(segments, test.segments) {
34 t.Errorf("#%d unexpected segments: exp: %v, act: %v", id, test.segments, segments)
35 }
36 }
37 }
38
39 func BenchmarkIndexText(b *testing.B) {
40 m := NewText("foo")
41
42 for i := 0; i < b.N; i++ {
43 _, s := m.Index(bench_pattern)
44 releaseSegments(s)
45 }
46 }
47
48 func BenchmarkIndexTextParallel(b *testing.B) {
49 m := NewText("foo")
50
51 b.RunParallel(func(pb *testing.PB) {
52 for pb.Next() {
53 _, s := m.Index(bench_pattern)
54 releaseSegments(s)
55 }
56 })
57 }
58
View as plain text