2013-10-01 17:26:21 -04:00
|
|
|
package transform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
const H5_JS_CONTENT_ABS_URL_WITH_NAV = "<!DOCTYPE html><html><head><script src=\"/foobar.js\"></script></head><body><nav><ul><li hugo-nav=\"section_0\"></li><li hugo-nav=\"section_1\"></li></ul></nav><article>content <a href=\"/foobar\">foobar</a>. Follow up</article></body></html>"
|
|
|
|
|
2013-11-05 17:28:06 -05:00
|
|
|
const CORRECT_OUTPUT_SRC_HREF_WITH_NAV = "<!DOCTYPE html><html><head><script src=\"http://two/foobar.js\"></script></head><body><nav><ul><li hugo-nav=\"section_0\"></li><li hugo-nav=\"section_1\"></li></ul></nav><article>content <a href=\"http://two/foobar\">foobar</a>. Follow up</article></body></html>"
|
2013-10-01 17:26:21 -04:00
|
|
|
|
2014-12-18 14:59:39 -05:00
|
|
|
const H5_XML_CONTENT_ABS_URL = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?><feed xmlns=\"http://www.w3.org/2005/Atom\"><entry><content type=\"html\"><p><a href="/foobar">foobar</a></p> <p>A video: <iframe src='/foo'></iframe></p></content></entry></feed>"
|
|
|
|
|
|
|
|
const CORRECT_OUTPUT_SRC_HREF_IN_XML = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?><feed xmlns=\"http://www.w3.org/2005/Atom\"><entry><content type=\"html\"><p><a href="http://xml/foobar">foobar</a></p> <p>A video: <iframe src='http://xml/foo'></iframe></p></content></entry></feed>"
|
|
|
|
|
2013-10-01 22:59:35 -04:00
|
|
|
var two_chain_tests = []test{
|
2013-10-01 17:26:21 -04:00
|
|
|
{H5_JS_CONTENT_ABS_URL_WITH_NAV, CORRECT_OUTPUT_SRC_HREF_WITH_NAV},
|
|
|
|
}
|
|
|
|
|
2014-12-18 14:59:39 -05:00
|
|
|
var xml_abs_url_tests = []test{
|
|
|
|
{H5_XML_CONTENT_ABS_URL, CORRECT_OUTPUT_SRC_HREF_IN_XML},
|
|
|
|
}
|
|
|
|
|
2013-11-05 17:28:06 -05:00
|
|
|
func TestChainZeroTransformers(t *testing.T) {
|
|
|
|
tr := NewChain()
|
|
|
|
in := new(bytes.Buffer)
|
|
|
|
out := new(bytes.Buffer)
|
|
|
|
if err := tr.Apply(in, out); err != nil {
|
|
|
|
t.Errorf("A zero transformer chain returned an error.")
|
|
|
|
}
|
2013-10-29 23:24:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkChain(b *testing.B) {
|
2013-11-01 01:14:11 -04:00
|
|
|
absURL, _ := AbsURL("http://two")
|
2013-11-05 17:28:06 -05:00
|
|
|
tr := NewChain(absURL...)
|
2013-11-01 01:14:11 -04:00
|
|
|
|
|
|
|
b.ResetTimer()
|
2013-10-29 23:24:29 -04:00
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
apply(b.Errorf, tr, two_chain_tests)
|
|
|
|
}
|
2013-10-01 17:26:21 -04:00
|
|
|
}
|
2014-12-18 14:59:39 -05:00
|
|
|
|
|
|
|
func TestXMLAbsUrl(t *testing.T) {
|
|
|
|
absURLInXML, _ := AbsURLInXML("http://xml")
|
|
|
|
tr := NewChain(absURLInXML...)
|
|
|
|
apply(t.Errorf, tr, xml_abs_url_tests)
|
|
|
|
}
|