| 23 | ) |
| 24 | |
| 25 | func TestScanToken(t *testing.T) { |
| 26 | testCases := []struct { |
| 27 | input string |
| 28 | idx int |
| 29 | retTok token |
| 30 | retIdx int |
| 31 | }{ |
| 32 | { |
| 33 | input: "foo bar", |
| 34 | idx: 1, |
| 35 | retTok: token{Value: 'o', Kind: tokenKindChar}, |
| 36 | retIdx: 2, |
| 37 | }, |
| 38 | { |
| 39 | input: "foo bar", |
| 40 | idx: 6, |
| 41 | retTok: token{Value: 'r', Kind: tokenKindChar}, |
| 42 | retIdx: -1, |
| 43 | }, |
| 44 | { |
| 45 | input: "foo <bar>", |
| 46 | idx: 4, |
| 47 | retTok: token{Value: '<', Kind: tokenKindChar}, |
| 48 | retIdx: 5, |
| 49 | }, |
| 50 | { |
| 51 | input: "foo <dnotehL>", |
| 52 | idx: 4, |
| 53 | retTok: token{Value: '<', Kind: tokenKindChar}, |
| 54 | retIdx: 5, |
| 55 | }, |
| 56 | { |
| 57 | input: "foo <dnotehl>bar</dnotehl> foo bar", |
| 58 | idx: 4, |
| 59 | retTok: token{Kind: tokenKindHLBegin}, |
| 60 | retIdx: 13, |
| 61 | }, |
| 62 | { |
| 63 | input: "foo <dnotehl>bar</dnotehl> <dnotehl>foo</dnotehl> bar", |
| 64 | idx: 4, |
| 65 | retTok: token{Kind: tokenKindHLBegin}, |
| 66 | retIdx: 13, |
| 67 | }, |
| 68 | { |
| 69 | input: "foo <dnotehl>bar</dnotehl> <dnotehl>foo</dnotehl> bar", |
| 70 | idx: 27, |
| 71 | retTok: token{Kind: tokenKindHLBegin}, |
| 72 | retIdx: 36, |
| 73 | }, |
| 74 | { |
| 75 | input: "foo <dnotehl>bar</dnotehl> foo bar", |
| 76 | idx: 13, |
| 77 | retTok: token{Value: 'b', Kind: tokenKindChar}, |
| 78 | retIdx: 14, |
| 79 | }, |
| 80 | { |
| 81 | input: "foo <dnotehl>bar</dnotehl> foo bar", |
| 82 | idx: 16, |