1package match 2 3import ( 4 "reflect" 5 "testing" 6) 7 8func TestSingleIndex(t *testing.T) { 9 for id, test := range []struct { 10 separators []rune 11 fixture string 12 index int 13 segments []int 14 }{ 15 { 16 []rune{'.'}, 17 ".abc", 18 1, 19 []int{1}, 20 }, 21 { 22 []rune{'.'}, 23 ".", 24 -1, 25 nil, 26 }, 27 } { 28 p := NewSingle(test.separators) 29 index, segments := p.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 39func BenchmarkIndexSingle(b *testing.B) { 40 m := NewSingle(bench_separators) 41 42 for i := 0; i < b.N; i++ { 43 _, s := m.Index(bench_pattern) 44 releaseSegments(s) 45 } 46} 47 48func BenchmarkIndexSingleParallel(b *testing.B) { 49 m := NewSingle(bench_separators) 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