1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
package quicktemplate
import (
"testing"
)
func TestHTMLEscapeWriter(t *testing.T) {
testHTMLEscapeWriter(t, "", "")
testHTMLEscapeWriter(t, "foobar", "foobar")
testHTMLEscapeWriter(t, `<h1>fo'"bar&</h1>`, "<h1>fo'"bar&</h1>")
testHTMLEscapeWriter(t, "fo<b>bar привет\n\tbaz", "fo<b>bar привет\n\tbaz")
}
func testHTMLEscapeWriter(t *testing.T, s, expectedS string) {
bb := AcquireByteBuffer()
w := &htmlEscapeWriter{w: bb}
n, err := w.Write([]byte(s))
if err != nil {
t.Fatalf("unexpected error when writing %q: %s", s, err)
}
if n != len(s) {
t.Fatalf("unexpected n returned: %d. Expecting %d. s=%q", n, len(s), s)
}
if string(bb.B) != expectedS {
t.Fatalf("unexpected result: %q. Expecting %q", bb.B, expectedS)
}
ReleaseByteBuffer(bb)
}
|