...

Source file src/github.com/gobwas/glob/match/contains_test.go

Documentation: github.com/gobwas/glob/match

     1  package match
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestContainsIndex(t *testing.T) {
     9  	for id, test := range []struct {
    10  		prefix   string
    11  		not      bool
    12  		fixture  string
    13  		index    int
    14  		segments []int
    15  	}{
    16  		{
    17  			"ab",
    18  			false,
    19  			"abc",
    20  			0,
    21  			[]int{2, 3},
    22  		},
    23  		{
    24  			"ab",
    25  			false,
    26  			"fffabfff",
    27  			0,
    28  			[]int{5, 6, 7, 8},
    29  		},
    30  		{
    31  			"ab",
    32  			true,
    33  			"abc",
    34  			0,
    35  			[]int{0},
    36  		},
    37  		{
    38  			"ab",
    39  			true,
    40  			"fffabfff",
    41  			0,
    42  			[]int{0, 1, 2, 3},
    43  		},
    44  	} {
    45  		p := NewContains(test.prefix, test.not)
    46  		index, segments := p.Index(test.fixture)
    47  		if index != test.index {
    48  			t.Errorf("#%d unexpected index: exp: %d, act: %d", id, test.index, index)
    49  		}
    50  		if !reflect.DeepEqual(segments, test.segments) {
    51  			t.Errorf("#%d unexpected segments: exp: %v, act: %v", id, test.segments, segments)
    52  		}
    53  	}
    54  }
    55  
    56  func BenchmarkIndexContains(b *testing.B) {
    57  	m := NewContains(string(bench_separators), true)
    58  
    59  	for i := 0; i < b.N; i++ {
    60  		_, s := m.Index(bench_pattern)
    61  		releaseSegments(s)
    62  	}
    63  }
    64  
    65  func BenchmarkIndexContainsParallel(b *testing.B) {
    66  	m := NewContains(string(bench_separators), true)
    67  
    68  	b.RunParallel(func(pb *testing.PB) {
    69  		for pb.Next() {
    70  			_, s := m.Index(bench_pattern)
    71  			releaseSegments(s)
    72  		}
    73  	})
    74  }
    75  

View as plain text