| 43 | } |
| 44 | |
| 45 | func testScanner(t *testing.T, n int, source string, tokens []token) { |
| 46 | s := scanner{r: strings.NewReader(source)} |
| 47 | for i, expected := range tokens { |
| 48 | if result := s.scan(); result != expected { |
| 49 | t.Errorf("[%d] expected token %s but found %s at %d", n, expected, result, i) |
| 50 | } |
| 51 | } |
| 52 | expected := token{t: tkEOS} |
| 53 | if result := s.scan(); result != expected { |
| 54 | t.Errorf("[%d] expected token %s but found %s", n, expected, result) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func (t token) String() string { |
| 59 | tok := string(t.t) |