| 1 | package match |
| 2 | |
| 3 | import ( |
| 4 | "reflect" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestPrefixAnyIndex(t *testing.T) { |
| 9 | for id, test := range []struct { |
| 10 | prefix string |
| 11 | separators []rune |
| 12 | fixture string |
| 13 | index int |
| 14 | segments []int |
| 15 | }{ |
| 16 | { |
| 17 | "ab", |
| 18 | []rune{'.'}, |
| 19 | "ab", |
| 20 | 0, |
| 21 | []int{2}, |
| 22 | }, |
| 23 | { |
| 24 | "ab", |
| 25 | []rune{'.'}, |
| 26 | "abc", |
| 27 | 0, |
| 28 | []int{2, 3}, |
| 29 | }, |
| 30 | { |
| 31 | "ab", |
| 32 | []rune{'.'}, |
| 33 | "qw.abcd.efg", |
| 34 | 3, |
| 35 | []int{2, 3, 4}, |
| 36 | }, |
| 37 | } { |
| 38 | p := NewPrefixAny(test.prefix, test.separators) |
| 39 | index, segments := p.Index(test.fixture) |
| 40 | if index != test.index { |
| 41 | t.Errorf("#%d unexpected index: exp: %d, act: %d", id, test.index, index) |
| 42 | } |
| 43 | if !reflect.DeepEqual(segments, test.segments) { |
| 44 | t.Errorf("#%d unexpected segments: exp: %v, act: %v", id, test.segments, segments) |
| 45 | } |
| 46 | } |
| 47 | } |