| 1 | package match |
| 2 | |
| 3 | import ( |
| 4 | "reflect" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestAnyOfIndex(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 | "abc", |
| 22 | 0, |
| 23 | []int{0, 1, 2, 3}, |
| 24 | }, |
| 25 | { |
| 26 | Matchers{ |
| 27 | NewPrefix("b"), |
| 28 | NewSuffix("c"), |
| 29 | }, |
| 30 | "abc", |
| 31 | 0, |
| 32 | []int{3}, |
| 33 | }, |
| 34 | { |
| 35 | Matchers{ |
| 36 | NewList([]rune("[def]"), false), |
| 37 | NewList([]rune("[abc]"), false), |
| 38 | }, |
| 39 | "abcdef", |
| 40 | 0, |
| 41 | []int{1}, |
| 42 | }, |
| 43 | } { |
| 44 | everyOf := NewAnyOf(test.matchers...) |
| 45 | index, segments := everyOf.Index(test.fixture) |
| 46 | if index != test.index { |
| 47 | t.Errorf("#%d unexpected index: exp: %d, act: %d", id, test.index, index) |
| 48 | } |
| 49 | if !reflect.DeepEqual(segments, test.segments) { |
| 50 | t.Errorf("#%d unexpected segments: exp: %v, act: %v", id, test.segments, segments) |
| 51 | } |
| 52 | } |
| 53 | } |