mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
transform: Group vars and consts in chain_test
This commit is contained in:
parent
c7869fd772
commit
944090722e
1 changed files with 68 additions and 57 deletions
|
@ -22,93 +22,104 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
const h5JsContentDoubleQuote = "<!DOCTYPE html><html><head><script src=\"foobar.js\"></script><script src=\"/barfoo.js\"></script></head><body><nav><h1>title</h1></nav><article>content <a href=\"foobar\">foobar</a>. <a href=\"/foobar\">Follow up</a></article></body></html>"
|
const (
|
||||||
const h5JsContentSingleQuote = "<!DOCTYPE html><html><head><script src='foobar.js'></script><script src='/barfoo.js'></script></head><body><nav><h1>title</h1></nav><article>content <a href='foobar'>foobar</a>. <a href='/foobar'>Follow up</a></article></body></html>"
|
h5JsContentDoubleQuote = "<!DOCTYPE html><html><head><script src=\"foobar.js\"></script><script src=\"/barfoo.js\"></script></head><body><nav><h1>title</h1></nav><article>content <a href=\"foobar\">foobar</a>. <a href=\"/foobar\">Follow up</a></article></body></html>"
|
||||||
const h5JsContentAbsURL = "<!DOCTYPE html><html><head><script src=\"http://user@host:10234/foobar.js\"></script></head><body><nav><h1>title</h1></nav><article>content <a href=\"https://host/foobar\">foobar</a>. Follow up</article></body></html>"
|
h5JsContentSingleQuote = "<!DOCTYPE html><html><head><script src='foobar.js'></script><script src='/barfoo.js'></script></head><body><nav><h1>title</h1></nav><article>content <a href='foobar'>foobar</a>. <a href='/foobar'>Follow up</a></article></body></html>"
|
||||||
const h5JsContentAbsURLSchemaless = "<!DOCTYPE html><html><head><script src=\"//host/foobar.js\"></script><script src='//host2/barfoo.js'></head><body><nav><h1>title</h1></nav><article>content <a href=\"//host/foobar\">foobar</a>. <a href='//host2/foobar'>Follow up</a></article></body></html>"
|
h5JsContentAbsURL = "<!DOCTYPE html><html><head><script src=\"http://user@host:10234/foobar.js\"></script></head><body><nav><h1>title</h1></nav><article>content <a href=\"https://host/foobar\">foobar</a>. Follow up</article></body></html>"
|
||||||
const corectOutputSrcHrefDq = "<!DOCTYPE html><html><head><script src=\"foobar.js\"></script><script src=\"http://base/barfoo.js\"></script></head><body><nav><h1>title</h1></nav><article>content <a href=\"foobar\">foobar</a>. <a href=\"http://base/foobar\">Follow up</a></article></body></html>"
|
h5JsContentAbsURLSchemaless = "<!DOCTYPE html><html><head><script src=\"//host/foobar.js\"></script><script src='//host2/barfoo.js'></head><body><nav><h1>title</h1></nav><article>content <a href=\"//host/foobar\">foobar</a>. <a href='//host2/foobar'>Follow up</a></article></body></html>"
|
||||||
const corectOutputSrcHrefSq = "<!DOCTYPE html><html><head><script src='foobar.js'></script><script src='http://base/barfoo.js'></script></head><body><nav><h1>title</h1></nav><article>content <a href='foobar'>foobar</a>. <a href='http://base/foobar'>Follow up</a></article></body></html>"
|
corectOutputSrcHrefDq = "<!DOCTYPE html><html><head><script src=\"foobar.js\"></script><script src=\"http://base/barfoo.js\"></script></head><body><nav><h1>title</h1></nav><article>content <a href=\"foobar\">foobar</a>. <a href=\"http://base/foobar\">Follow up</a></article></body></html>"
|
||||||
|
corectOutputSrcHrefSq = "<!DOCTYPE html><html><head><script src='foobar.js'></script><script src='http://base/barfoo.js'></script></head><body><nav><h1>title</h1></nav><article>content <a href='foobar'>foobar</a>. <a href='http://base/foobar'>Follow up</a></article></body></html>"
|
||||||
|
|
||||||
const h5XMLXontentAbsURL = "<?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>"
|
h5XMLXontentAbsURL = "<?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 correctOutputSrcHrefInXML = "<?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://base/foobar">foobar</a></p> <p>A video: <iframe src='http://base/foo'></iframe></p></content></entry></feed>"
|
correctOutputSrcHrefInXML = "<?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://base/foobar">foobar</a></p> <p>A video: <iframe src='http://base/foo'></iframe></p></content></entry></feed>"
|
||||||
const h5XMLContentGuarded = "<?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>"
|
h5XMLContentGuarded = "<?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>"
|
||||||
|
)
|
||||||
|
|
||||||
// additional sanity tests for replacements testing
|
const (
|
||||||
const replace1 = "No replacements."
|
// additional sanity tests for replacements testing
|
||||||
const replace2 = "ᚠᛇᚻ ᛒᛦᚦ ᚠᚱᚩᚠᚢᚱ\nᚠᛁᚱᚪ ᚷᛖᚻᚹᛦᛚᚳᚢᛗ"
|
replace1 = "No replacements."
|
||||||
const replace3 = `End of file: src="/`
|
replace2 = "ᚠᛇᚻ ᛒᛦᚦ ᚠᚱᚩᚠᚢᚱ\nᚠᛁᚱᚪ ᚷᛖᚻᚹᛦᛚᚳᚢᛗ"
|
||||||
const replace4 = `End of file: srcset="/`
|
replace3 = `End of file: src="/`
|
||||||
const replace5 = `Srcsett with no closing quote: srcset="/img/small.jpg do be do be do.`
|
replace4 = `End of file: srcset="/`
|
||||||
|
replace5 = `Srcsett with no closing quote: srcset="/img/small.jpg do be do be do.`
|
||||||
|
|
||||||
// Issue: 816, schemaless links combined with others
|
// Issue: 816, schemaless links combined with others
|
||||||
const replaceSchemalessHTML = `Pre. src='//schemaless' src='/normal' <a href="//schemaless">Schemaless</a>. <a href="/normal">normal</a>. Post.`
|
replaceSchemalessHTML = `Pre. src='//schemaless' src='/normal' <a href="//schemaless">Schemaless</a>. <a href="/normal">normal</a>. Post.`
|
||||||
const replaceSchemalessHTMLCorrect = `Pre. src='//schemaless' src='http://base/normal' <a href="//schemaless">Schemaless</a>. <a href="http://base/normal">normal</a>. Post.`
|
replaceSchemalessHTMLCorrect = `Pre. src='//schemaless' src='http://base/normal' <a href="//schemaless">Schemaless</a>. <a href="http://base/normal">normal</a>. Post.`
|
||||||
const replaceSchemalessXML = `Pre. src='//schemaless' src='/normal' <a href='//schemaless'>Schemaless</a>. <a href='/normal'>normal</a>. Post.`
|
replaceSchemalessXML = `Pre. src='//schemaless' src='/normal' <a href='//schemaless'>Schemaless</a>. <a href='/normal'>normal</a>. Post.`
|
||||||
const replaceSchemalessXMLCorrect = `Pre. src='//schemaless' src='http://base/normal' <a href='//schemaless'>Schemaless</a>. <a href='http://base/normal'>normal</a>. Post.`
|
replaceSchemalessXMLCorrect = `Pre. src='//schemaless' src='http://base/normal' <a href='//schemaless'>Schemaless</a>. <a href='http://base/normal'>normal</a>. Post.`
|
||||||
|
)
|
||||||
|
|
||||||
// srcset=
|
const (
|
||||||
const srcsetBasic = `Pre. <img srcset="/img/small.jpg 200w, /img/medium.jpg 300w, /img/big.jpg 700w" alt="text" src="/img/foo.jpg">`
|
// srcset=
|
||||||
const srcsetBasicCorrect = `Pre. <img srcset="http://base/img/small.jpg 200w, http://base/img/medium.jpg 300w, http://base/img/big.jpg 700w" alt="text" src="http://base/img/foo.jpg">`
|
srcsetBasic = `Pre. <img srcset="/img/small.jpg 200w, /img/medium.jpg 300w, /img/big.jpg 700w" alt="text" src="/img/foo.jpg">`
|
||||||
const srcsetSingleQuote = `Pre. <img srcset='/img/small.jpg 200w, /img/big.jpg 700w' alt="text" src="/img/foo.jpg"> POST.`
|
srcsetBasicCorrect = `Pre. <img srcset="http://base/img/small.jpg 200w, http://base/img/medium.jpg 300w, http://base/img/big.jpg 700w" alt="text" src="http://base/img/foo.jpg">`
|
||||||
const srcsetSingleQuoteCorrect = `Pre. <img srcset='http://base/img/small.jpg 200w, http://base/img/big.jpg 700w' alt="text" src="http://base/img/foo.jpg"> POST.`
|
srcsetSingleQuote = `Pre. <img srcset='/img/small.jpg 200w, /img/big.jpg 700w' alt="text" src="/img/foo.jpg"> POST.`
|
||||||
const srcsetXMLBasic = `Pre. <img srcset="/img/small.jpg 200w, /img/big.jpg 700w" alt="text" src="/img/foo.jpg">`
|
srcsetSingleQuoteCorrect = `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 srcsetXMLBasicCorrect = `Pre. <img srcset="http://base/img/small.jpg 200w, http://base/img/big.jpg 700w" alt="text" src="http://base/img/foo.jpg">`
|
srcsetXMLBasic = `Pre. <img srcset="/img/small.jpg 200w, /img/big.jpg 700w" alt="text" src="/img/foo.jpg">`
|
||||||
const srcsetXMLSingleQuote = `Pre. <img srcset="/img/small.jpg 200w, /img/big.jpg 700w" alt="text" src="/img/foo.jpg">`
|
srcsetXMLBasicCorrect = `Pre. <img srcset="http://base/img/small.jpg 200w, http://base/img/big.jpg 700w" alt="text" src="http://base/img/foo.jpg">`
|
||||||
const srcsetXMLSingleQuoteCorrect = `Pre. <img srcset="http://base/img/small.jpg 200w, http://base/img/big.jpg 700w" alt="text" src="http://base/img/foo.jpg">`
|
srcsetXMLSingleQuote = `Pre. <img srcset="/img/small.jpg 200w, /img/big.jpg 700w" alt="text" src="/img/foo.jpg">`
|
||||||
const srcsetVariations = `Pre.
|
srcsetXMLSingleQuoteCorrect = `Pre. <img srcset="http://base/img/small.jpg 200w, http://base/img/big.jpg 700w" alt="text" src="http://base/img/foo.jpg">`
|
||||||
|
srcsetVariations = `Pre.
|
||||||
Missing start quote: <img srcset=/img/small.jpg 200w, /img/big.jpg 700w" alt="text"> src='/img/foo.jpg'> FOO.
|
Missing start quote: <img srcset=/img/small.jpg 200w, /img/big.jpg 700w" alt="text"> src='/img/foo.jpg'> FOO.
|
||||||
<img srcset='/img.jpg'>
|
<img srcset='/img.jpg'>
|
||||||
schemaless: <img srcset='//img.jpg' src='//basic.jpg'>
|
schemaless: <img srcset='//img.jpg' src='//basic.jpg'>
|
||||||
schemaless2: <img srcset="//img.jpg" src="//basic.jpg2> POST
|
schemaless2: <img srcset="//img.jpg" src="//basic.jpg2> POST
|
||||||
`
|
`
|
||||||
const srcsetVariationsCorrect = `Pre.
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
srcsetVariationsCorrect = `Pre.
|
||||||
Missing start quote: <img srcset=/img/small.jpg 200w, /img/big.jpg 700w" alt="text"> src='http://base/img/foo.jpg'> FOO.
|
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'>
|
<img srcset='http://base/img.jpg'>
|
||||||
schemaless: <img srcset='//img.jpg' src='//basic.jpg'>
|
schemaless: <img srcset='//img.jpg' src='//basic.jpg'>
|
||||||
schemaless2: <img srcset="//img.jpg" src="//basic.jpg2> POST
|
schemaless2: <img srcset="//img.jpg" src="//basic.jpg2> POST
|
||||||
`
|
`
|
||||||
const srcsetXMLVariations = `Pre.
|
srcsetXMLVariations = `Pre.
|
||||||
Missing start quote: <img srcset=/img/small.jpg 200w /img/big.jpg 700w" alt="text"> src='/img/foo.jpg'> FOO.
|
Missing start quote: <img srcset=/img/small.jpg 200w /img/big.jpg 700w" alt="text"> src='/img/foo.jpg'> FOO.
|
||||||
<img srcset='/img.jpg'>
|
<img srcset='/img.jpg'>
|
||||||
schemaless: <img srcset='//img.jpg' src='//basic.jpg'>
|
schemaless: <img srcset='//img.jpg' src='//basic.jpg'>
|
||||||
schemaless2: <img srcset="//img.jpg" src="//basic.jpg2> POST
|
schemaless2: <img srcset="//img.jpg" src="//basic.jpg2> POST
|
||||||
`
|
`
|
||||||
const srcsetXMLVariationsCorrect = `Pre.
|
srcsetXMLVariationsCorrect = `Pre.
|
||||||
Missing start quote: <img srcset=/img/small.jpg 200w /img/big.jpg 700w" alt="text"> src='http://base/img/foo.jpg'> FOO.
|
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'>
|
<img srcset='http://base/img.jpg'>
|
||||||
schemaless: <img srcset='//img.jpg' src='//basic.jpg'>
|
schemaless: <img srcset='//img.jpg' src='//basic.jpg'>
|
||||||
schemaless2: <img srcset="//img.jpg" src="//basic.jpg2> POST
|
schemaless2: <img srcset="//img.jpg" src="//basic.jpg2> POST
|
||||||
`
|
`
|
||||||
|
|
||||||
const relPathVariations = `PRE. a href="/img/small.jpg" POST.`
|
relPathVariations = `PRE. a href="/img/small.jpg" POST.`
|
||||||
const relPathVariationsCorrect = `PRE. a href="../../img/small.jpg" POST.`
|
relPathVariationsCorrect = `PRE. a href="../../img/small.jpg" POST.`
|
||||||
|
|
||||||
const testBaseURL = "http://base/"
|
testBaseURL = "http://base/"
|
||||||
|
)
|
||||||
|
|
||||||
var absURLlBenchTests = []test{
|
var (
|
||||||
{h5JsContentDoubleQuote, corectOutputSrcHrefDq},
|
absURLlBenchTests = []test{
|
||||||
{h5JsContentSingleQuote, corectOutputSrcHrefSq},
|
{h5JsContentDoubleQuote, corectOutputSrcHrefDq},
|
||||||
{h5JsContentAbsURL, h5JsContentAbsURL},
|
{h5JsContentSingleQuote, corectOutputSrcHrefSq},
|
||||||
{h5JsContentAbsURLSchemaless, h5JsContentAbsURLSchemaless},
|
{h5JsContentAbsURL, h5JsContentAbsURL},
|
||||||
}
|
{h5JsContentAbsURLSchemaless, h5JsContentAbsURLSchemaless},
|
||||||
|
}
|
||||||
|
|
||||||
var xmlAbsURLBenchTests = []test{
|
xmlAbsURLBenchTests = []test{
|
||||||
{h5XMLXontentAbsURL, correctOutputSrcHrefInXML},
|
{h5XMLXontentAbsURL, correctOutputSrcHrefInXML},
|
||||||
{h5XMLContentGuarded, h5XMLContentGuarded},
|
{h5XMLContentGuarded, h5XMLContentGuarded},
|
||||||
}
|
}
|
||||||
|
|
||||||
var sanityTests = []test{{replace1, replace1}, {replace2, replace2}, {replace3, replace3}, {replace3, replace3}, {replace5, replace5}}
|
sanityTests = []test{{replace1, replace1}, {replace2, replace2}, {replace3, replace3}, {replace3, replace3}, {replace5, replace5}}
|
||||||
var extraTestsHTML = []test{{replaceSchemalessHTML, replaceSchemalessHTMLCorrect}}
|
extraTestsHTML = []test{{replaceSchemalessHTML, replaceSchemalessHTMLCorrect}}
|
||||||
var absURLTests = append(absURLlBenchTests, append(sanityTests, extraTestsHTML...)...)
|
absURLTests = append(absURLlBenchTests, append(sanityTests, extraTestsHTML...)...)
|
||||||
var extraTestsXML = []test{{replaceSchemalessXML, replaceSchemalessXMLCorrect}}
|
extraTestsXML = []test{{replaceSchemalessXML, replaceSchemalessXMLCorrect}}
|
||||||
var xmlAbsURLTests = append(xmlAbsURLBenchTests, append(sanityTests, extraTestsXML...)...)
|
xmlAbsURLTests = append(xmlAbsURLBenchTests, append(sanityTests, extraTestsXML...)...)
|
||||||
var srcsetTests = []test{{srcsetBasic, srcsetBasicCorrect}, {srcsetSingleQuote, srcsetSingleQuoteCorrect}, {srcsetVariations, srcsetVariationsCorrect}}
|
srcsetTests = []test{{srcsetBasic, srcsetBasicCorrect}, {srcsetSingleQuote, srcsetSingleQuoteCorrect}, {srcsetVariations, srcsetVariationsCorrect}}
|
||||||
var srcsetXMLTests = []test{
|
srcsetXMLTests = []test{
|
||||||
{srcsetXMLBasic, srcsetXMLBasicCorrect},
|
{srcsetXMLBasic, srcsetXMLBasicCorrect},
|
||||||
{srcsetXMLSingleQuote, srcsetXMLSingleQuoteCorrect},
|
{srcsetXMLSingleQuote, srcsetXMLSingleQuoteCorrect},
|
||||||
{srcsetXMLVariations, srcsetXMLVariationsCorrect}}
|
{srcsetXMLVariations, srcsetXMLVariationsCorrect}}
|
||||||
|
|
||||||
var relurlTests = []test{{relPathVariations, relPathVariationsCorrect}}
|
relurlTests = []test{{relPathVariations, relPathVariationsCorrect}}
|
||||||
|
)
|
||||||
|
|
||||||
func TestChainZeroTransformers(t *testing.T) {
|
func TestChainZeroTransformers(t *testing.T) {
|
||||||
tr := NewChain()
|
tr := NewChain()
|
||||||
|
|
Loading…
Reference in a new issue