...

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

Documentation: github.com/gobwas/glob/match

     1  package match
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestListIndex(t *testing.T) {
     9  	for id, test := range []struct {
    10  		list     []rune
    11  		not      bool
    12  		fixture  string
    13  		index    int
    14  		segments []int
    15  	}{
    16  		{
    17  			[]rune("ab"),
    18  			false,
    19  			"abc",
    20  			0,
    21  			[]int{1},
    22  		},
    23  		{
    24  			[]rune("ab"),
    25  			true,
    26  			"fffabfff",
    27  			0,
    28  			[]int{1},
    29  		},
    30  	} {
    31  		p := NewList(test.list, test.not)
    32  		index, segments := p.Index(test.fixture)
    33  		if index != test.index {
    34  			t.Errorf("#%d unexpected index: exp: %d, act: %d", id, test.index, index)
    35  		}
    36  		if !reflect.DeepEqual(segments, test.segments) {
    37  			t.Errorf("#%d unexpected segments: exp: %v, act: %v", id, test.segments, segments)
    38  		}
    39  	}
    40  }
    41  
    42  func BenchmarkIndexList(b *testing.B) {
    43  	m := NewList([]rune("def"), false)
    44  
    45  	for i := 0; i < b.N; i++ {
    46  		m.Index(bench_pattern)
    47  	}
    48  }
    49  
    50  func BenchmarkIndexListParallel(b *testing.B) {
    51  	m := NewList([]rune("def"), false)
    52  
    53  	b.RunParallel(func(pb *testing.PB) {
    54  		for pb.Next() {
    55  			m.Index(bench_pattern)
    56  		}
    57  	})
    58  }
    59  

View as plain text