package transform
import (
"bytes"
"strings"
"testing"
)
const H5_JS_CONTENT_DOUBLE_QUOTE = "
content foobar. Follow up"
const H5_JS_CONTENT_SINGLE_QUOTE = "content foobar. Follow up"
const H5_JS_CONTENT_ABS_URL = "content foobar. Follow up"
// URL doesn't recognize authorities. BUG?
//const H5_JS_CONTENT_ABS_URL = "content foobar. Follow up"
const CORRECT_OUTPUT_SRC_HREF_DQ = "content foobar. Follow up"
const CORRECT_OUTPUT_SRC_HREF_SQ = "content foobar. Follow up"
func TestAbsUrlify(t *testing.T) {
tr, _ := AbsURL("http://base")
chain := NewChain(tr...)
apply(t.Errorf, chain, abs_url_tests)
}
type test struct {
content string
expected string
}
var abs_url_tests = []test{
{H5_JS_CONTENT_DOUBLE_QUOTE, CORRECT_OUTPUT_SRC_HREF_DQ},
{H5_JS_CONTENT_SINGLE_QUOTE, CORRECT_OUTPUT_SRC_HREF_SQ},
{H5_JS_CONTENT_ABS_URL, H5_JS_CONTENT_ABS_URL},
}
type errorf func(string, ...interface{})
func apply(ef errorf, tr chain, tests []test) {
for _, test := range tests {
out := new(bytes.Buffer)
err := tr.Apply(out, strings.NewReader(test.content))
if err != nil {
ef("Unexpected error: %s", err)
}
if test.expected != string(out.Bytes()) {
ef("Expected:\n%s\nGot:\n%s", test.expected, string(out.Bytes()))
}
}
}