MCPcopy
hub / github.com/tdewolff/minify / TestBuffer

Function TestBuffer

xml/buffer_test.go:11–37  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func 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 z := NewTokenBuffer(xml.NewLexer(parse.NewInputString(s)))
15
16 tok := z.Shift()
17 test.That(t, string(tok.Text) == "p", "first token is <p>")
18 test.That(t, z.pos == 0, "shift first token and restore position")
19 test.That(t, len(z.buf) == 0, "shift first token and restore length")
20
21 test.That(t, string(z.Peek(2).Text) == "href", "third token is href")
22 test.That(t, z.pos == 0, "don't change position after peeking")
23 test.That(t, len(z.buf) == 3, "two tokens after peeking")
24
25 test.That(t, string(z.Peek(8).Text) == "p", "ninth token is <p>")
26 test.That(t, z.pos == 0, "don't change position after peeking")
27 test.That(t, len(z.buf) == 9, "nine tokens after peeking")
28
29 test.That(t, z.Peek(9).TokenType == xml.ErrorToken, "tenth token is an error")
30 test.That(t, z.Peek(9) == z.Peek(10), "tenth and eleventh token are EOF")
31 test.That(t, len(z.buf) == 10, "ten tokens after peeking")
32
33 _ = z.Shift()
34 tok = z.Shift()
35 test.That(t, string(tok.Text) == "a", "third token is <a>")
36 test.That(t, z.pos == 2, "don't change position after peeking")
37}

Callers

nothing calls this directly

Calls 5

ShiftMethod · 0.95
PeekMethod · 0.95
lenFunction · 0.85
NewTokenBufferFunction · 0.70
stringFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…