(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestBuffer(t *testing.T) { |
| 12 | // 0 12 3 45 6 7 8 9 0 |
| 13 | s := `<p><a href="//url">text</a>text<!--comment--></p>` |
| 14 | r := parse.NewInputString(s) |
| 15 | z := NewTokenBuffer(r, html.NewLexer(r)) |
| 16 | |
| 17 | tok := z.Shift() |
| 18 | test.That(t, tok.Hash == P, "first token is <p>") |
| 19 | test.That(t, z.pos == 0, "shift first token and restore position") |
| 20 | test.That(t, len(z.buf) == 0, "shift first token and restore length") |
| 21 | |
| 22 | test.That(t, z.Peek(2).Hash == Href, "third token is href") |
| 23 | test.That(t, z.pos == 0, "don't change position after peeking") |
| 24 | test.That(t, len(z.buf) == 3, "two tokens after peeking") |
| 25 | |
| 26 | test.That(t, z.Peek(8).Hash == P, "ninth token is <p>") |
| 27 | test.That(t, z.pos == 0, "don't change position after peeking") |
| 28 | test.That(t, len(z.buf) == 9, "nine tokens after peeking") |
| 29 | |
| 30 | test.That(t, z.Peek(9).TokenType == html.ErrorToken, "tenth token is an error") |
| 31 | test.That(t, z.Peek(9) == z.Peek(10), "tenth and eleventh tokens are EOF") |
| 32 | test.That(t, len(z.buf) == 10, "ten tokens after peeking") |
| 33 | |
| 34 | _ = z.Shift() |
| 35 | tok = z.Shift() |
| 36 | test.That(t, tok.Hash == A, "third token is <a>") |
| 37 | test.That(t, z.pos == 2, "don't change position after peeking") |
| 38 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…