diff options
author | bep <bjorn.erik.pedersen@gmail.com> | 2015-05-03 19:54:17 +0200 |
---|---|---|
committer | bep <bjorn.erik.pedersen@gmail.com> | 2015-05-03 19:54:23 +0200 |
commit | bee6a69846f476013e78c32d55f6c508ed8f1a99 (patch) | |
tree | 848ec15f48bce9f7f3ed1c093a92ca23fea3edaa /transform/chain_test.go | |
parent | be6482603ee8ac3516ae19ceebb35662f038b25e (diff) |
canonifyurls in srcset
Speed is about the same as before, uses slightly less memory:
```
benchmark old ns/op new ns/op delta
BenchmarkAbsURL 17302 17713 +2.38%
BenchmarkXMLAbsURL 9463 9470 +0.07%
benchmark old allocs new allocs delta
BenchmarkAbsURL 28 24 -14.29%
BenchmarkXMLAbsURL 14 12 -14.29%
benchmark old bytes new bytes delta
BenchmarkAbsURL 3422 3144 -8.12%
BenchmarkXMLAbsURL 1985 1864 -6.10%
```
Fixes #1059
Diffstat (limited to 'transform/chain_test.go')
-rw-r--r-- | transform/chain_test.go | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/transform/chain_test.go b/transform/chain_test.go index 683ac77c1..242d571e7 100644 --- a/transform/chain_test.go +++ b/transform/chain_test.go @@ -25,8 +25,42 @@ const REPLACE_2 = "ᚠᛇᚻ ᛒᛦᚦ ᚠᚱᚩᚠᚢᚱ\nᚠᛁᚱᚪ ᚷᛖ // Issue: 816, schemaless links combined with others const REPLACE_SCHEMALESS_HTML = `Pre. src='//schemaless' src='/normal' <a href="//schemaless">Schemaless</a>. <a href="/normal">normal</a>. Post.` const REPLACE_SCHEMALESS_HTML_CORRECT = `Pre. src='//schemaless' src='http://base/normal' <a href="//schemaless">Schemaless</a>. <a href="http://base/normal">normal</a>. Post.` -const REPLACE_SCHEMALESS_XML = `Pre. src="//schemaless" src="/normal" <a href='//schemaless'>Schemaless</a>. <a href='/normal'>normal</a>. Post.` -const REPLACE_SCHEMALESS_XML_CORRECT = `Pre. src="//schemaless" src="http://base/normal" <a href='//schemaless'>Schemaless</a>. <a href='http://base/normal'>normal</a>. Post.` +const REPLACE_SCHEMALESS_XML = `Pre. src='//schemaless' src='/normal' <a href='//schemaless'>Schemaless</a>. <a href='/normal'>normal</a>. Post.` +const REPLACE_SCHEMALESS_XML_CORRECT = `Pre. src='//schemaless' src='http://base/normal' <a href='//schemaless'>Schemaless</a>. <a href='http://base/normal'>normal</a>. Post.` + +// srcset= +const SRCSET_BASIC = `Pre. <img srcset="/img/small.jpg 200w /img/big.jpg 700w" alt="text" src="/img/foo.jpg">` +const SRCSET_BASIC_CORRECT = `Pre. <img srcset="http://base/img/small.jpg 200w http://base/img/big.jpg 700w" alt="text" src="http://base/img/foo.jpg">` +const SRCSET_SINGLE_QUOTE = `Pre. <img srcset='/img/small.jpg 200w /img/big.jpg 700w' alt="text" src="/img/foo.jpg"> POST.` +const SRCSET_SINGLE_QUOTE_CORRECT = `Pre. <img srcset='http://base/img/small.jpg 200w http://base/img/big.jpg 700w' alt="text" src="http://base/img/foo.jpg"> POST.` +const SRCSET_XML_BASIC = `Pre. <img srcset="/img/small.jpg 200w /img/big.jpg 700w" alt="text" src="/img/foo.jpg">` +const SRCSET_XML_BASIC_CORRECT = `Pre. <img srcset="http://base/img/small.jpg 200w http://base/img/big.jpg 700w" alt="text" src="http://base/img/foo.jpg">` +const SRCSET_XML_SINGLE_QUOTE = `Pre. <img srcset="/img/small.jpg 200w /img/big.jpg 700w" alt="text" src="/img/foo.jpg">` +const SRCSET_XML_SINGLE_QUOTE_CORRECT = `Pre. <img srcset="http://base/img/small.jpg 200w http://base/img/big.jpg 700w" alt="text" src="http://base/img/foo.jpg">` +const SRCSET_VARIATIONS = `Pre. +Missing start quote: <img srcset=/img/small.jpg 200w /img/big.jpg 700w" alt="text"> src='/img/foo.jpg'> FOO. +<img srcset='/img.jpg'> +schemaless: <img srcset='//img.jpg' src='//basic.jpg'> +schemaless2: <img srcset="//img.jpg" src="//basic.jpg2> POST +` +const SRCSET_VARIATIONS_CORRECT = `Pre. +Missing start quote: <img srcset=/img/small.jpg 200w /img/big.jpg 700w" alt="text"> src='http://base/img/foo.jpg'> FOO. +<img srcset='http://base/img.jpg'> +schemaless: <img srcset='//img.jpg' src='//basic.jpg'> +schemaless2: <img srcset="//img.jpg" src="//basic.jpg2> POST +` +const SRCSET_XML_VARIATIONS = `Pre. +Missing start quote: <img srcset=/img/small.jpg 200w /img/big.jpg 700w" alt="text"> src='/img/foo.jpg'> FOO. +<img srcset='/img.jpg'> +schemaless: <img srcset='//img.jpg' src='//basic.jpg'> +schemaless2: <img srcset="//img.jpg" src="//basic.jpg2> POST +` +const SRCSET_XML_VARIATIONS_CORRECT = `Pre. +Missing start quote: <img srcset=/img/small.jpg 200w /img/big.jpg 700w" alt="text"> src='http://base/img/foo.jpg'> FOO. +<img srcset='http://base/img.jpg'> +schemaless: <img srcset='//img.jpg' src='//basic.jpg'> +schemaless2: <img srcset="//img.jpg" src="//basic.jpg2> POST +` var abs_url_bench_tests = []test{ {H5_JS_CONTENT_DOUBLE_QUOTE, CORRECT_OUTPUT_SRC_HREF_DQ}, @@ -46,6 +80,12 @@ var abs_url_tests = append(abs_url_bench_tests, append(sanity_tests, extra_tests var extra_tests_xml = []test{{REPLACE_SCHEMALESS_XML, REPLACE_SCHEMALESS_XML_CORRECT}} var xml_abs_url_tests = append(xml_abs_url_bench_tests, append(sanity_tests, extra_tests_xml...)...) +var srcset_tests = []test{{SRCSET_BASIC, SRCSET_BASIC_CORRECT}, {SRCSET_SINGLE_QUOTE, SRCSET_SINGLE_QUOTE_CORRECT}, {SRCSET_VARIATIONS, SRCSET_VARIATIONS_CORRECT}} +var srcset_xml_tests = []test{ + {SRCSET_XML_BASIC, SRCSET_XML_BASIC_CORRECT}, + {SRCSET_XML_SINGLE_QUOTE, SRCSET_XML_SINGLE_QUOTE_CORRECT}, + {SRCSET_XML_VARIATIONS, SRCSET_XML_VARIATIONS_CORRECT}} + func TestChainZeroTransformers(t *testing.T) { tr := NewChain() in := new(bytes.Buffer) @@ -102,6 +142,21 @@ func TestAbsURL(t *testing.T) { } +func TestAbsURLSrcSet(t *testing.T) { + absURL, _ := absURLFromURL("http://base") + tr := NewChain(absURL...) + + apply(t.Errorf, tr, srcset_tests) +} + +func TestAbsXMLURLSrcSet(t *testing.T) { + absURLInXML, _ := absURLInXMLFromURL("http://base") + tr := NewChain(absURLInXML...) + + apply(t.Errorf, tr, srcset_xml_tests) + +} + func BenchmarkXMLAbsURL(b *testing.B) { absURLInXML, _ := absURLInXMLFromURL("http://base") tr := NewChain(absURLInXML...) |