From 8ffb773f43c8dc54801ca1d111854e7e881c93c9 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 19 Nov 2017 21:10:04 -0800 Subject: First commit --- .../github.com/tdewolff/minify/xml/buffer_test.go | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 vendor/github.com/tdewolff/minify/xml/buffer_test.go (limited to 'vendor/github.com/tdewolff/minify/xml/buffer_test.go') diff --git a/vendor/github.com/tdewolff/minify/xml/buffer_test.go b/vendor/github.com/tdewolff/minify/xml/buffer_test.go new file mode 100644 index 0000000..019cb12 --- /dev/null +++ b/vendor/github.com/tdewolff/minify/xml/buffer_test.go @@ -0,0 +1,37 @@ +package xml // import "github.com/tdewolff/minify/xml" + +import ( + "bytes" + "testing" + + "github.com/tdewolff/parse/xml" + "github.com/tdewolff/test" +) + +func TestBuffer(t *testing.T) { + // 0 12 3 45 6 7 8 9 0 + s := `

texttext

` + z := NewTokenBuffer(xml.NewLexer(bytes.NewBufferString(s))) + + tok := z.Shift() + test.That(t, string(tok.Text) == "p", "first token is

") + test.That(t, z.pos == 0, "shift first token and restore position") + test.That(t, len(z.buf) == 0, "shift first token and restore length") + + test.That(t, string(z.Peek(2).Text) == "href", "third token is href") + test.That(t, z.pos == 0, "don't change position after peeking") + test.That(t, len(z.buf) == 3, "two tokens after peeking") + + test.That(t, string(z.Peek(8).Text) == "p", "ninth token is

") + test.That(t, z.pos == 0, "don't change position after peeking") + test.That(t, len(z.buf) == 9, "nine tokens after peeking") + + test.That(t, z.Peek(9).TokenType == xml.ErrorToken, "tenth token is an error") + test.That(t, z.Peek(9) == z.Peek(10), "tenth and eleventh token are EOF") + test.That(t, len(z.buf) == 10, "ten tokens after peeking") + + _ = z.Shift() + tok = z.Shift() + test.That(t, string(tok.Text) == "a", "third token is ") + test.That(t, z.pos == 2, "don't change position after peeking") +} -- cgit v1.2.3