| 1 | package match |
| 2 | |
| 3 | import ( |
| 4 | "reflect" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestEveryOfIndex(t *testing.T) { |
| 9 | for id, test := range []struct { |
| 10 | matchers Matchers |
| 11 | fixture string |
| 12 | index int |
| 13 | segments []int |
| 14 | }{ |
| 15 | { |
| 16 | Matchers{ |
| 17 | NewAny(nil), |
| 18 | NewText("b"), |
| 19 | NewText("c"), |
| 20 | }, |
| 21 | "dbc", |
| 22 | -1, |
| 23 | nil, |
| 24 | }, |
| 25 | { |
| 26 | Matchers{ |
| 27 | NewAny(nil), |
| 28 | NewPrefix("b"), |
| 29 | NewSuffix("c"), |
| 30 | }, |
| 31 | "abc", |
| 32 | 1, |
| 33 | []int{2}, |
| 34 | }, |
| 35 | } { |
| 36 | everyOf := NewEveryOf(test.matchers...) |
| 37 | index, segments := everyOf.Index(test.fixture) |
| 38 | if index != test.index { |
| 39 | t.Errorf("#%d unexpected index: exp: %d, act: %d", id, test.index, index) |
| 40 | } |
| 41 | if !reflect.DeepEqual(segments, test.segments) { |
| 42 | t.Errorf("#%d unexpected segments: exp: %v, act: %v", id, test.segments, segments) |
| 43 | } |
| 44 | } |
| 45 | } |