Use TestParams in block tests

The different testing function interfaces get unified a bit closer,
runnerWithRendererParameters completely eliminated.
This commit is contained in:
Vytautas Šaltenis 2016-04-04 11:45:36 +03:00
parent b069de6276
commit a658caacc6
2 changed files with 18 additions and 16 deletions

View File

@ -252,7 +252,10 @@ func TestPrefixHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) {
HeaderIDSuffix: ":POST", HeaderIDSuffix: ":POST",
} }
doTestsBlockWithRunner(t, tests, HeaderIDs, runnerWithRendererParameters(parameters)) doTestsBlockWithRunner(t, tests, TestParams{
Options: Options{Extensions: HeaderIDs},
HTMLRendererParameters: parameters,
}, runMarkdownBlock)
} }
func TestPrefixAutoHeaderIdExtension(t *testing.T) { func TestPrefixAutoHeaderIdExtension(t *testing.T) {
@ -360,7 +363,10 @@ func TestPrefixAutoHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) {
HeaderIDSuffix: ":POST", HeaderIDSuffix: ":POST",
} }
doTestsBlockWithRunner(t, tests, AutoHeaderIDs, runnerWithRendererParameters(parameters)) doTestsBlockWithRunner(t, tests, TestParams{
Options: Options{Extensions: AutoHeaderIDs},
HTMLRendererParameters: parameters,
}, runMarkdownBlock)
} }
func TestPrefixMultipleHeaderExtensions(t *testing.T) { func TestPrefixMultipleHeaderExtensions(t *testing.T) {

View File

@ -30,23 +30,19 @@ func runMarkdownBlockWithRenderer(input string, extensions Extensions, renderer
return string(Markdown([]byte(input), renderer, extensions)) return string(Markdown([]byte(input), renderer, extensions))
} }
func runMarkdownBlock(input string, extensions Extensions) string { func runMarkdownBlock(input string, params TestParams) string {
renderer := HTMLRenderer(UseXHTML, extensions, "", "") renderer := HTMLRendererWithParameters(params.HTMLFlags|UseXHTML,
return runMarkdownBlockWithRenderer(input, extensions, renderer) params.Options.Extensions, "", "", params.HTMLRendererParameters)
} return runMarkdownBlockWithRenderer(input, params.Options.Extensions, renderer)
func runnerWithRendererParameters(parameters HTMLRendererParameters) func(string, Extensions) string {
return func(input string, extensions Extensions) string {
renderer := HTMLRendererWithParameters(UseXHTML, extensions, "", "", parameters)
return runMarkdownBlockWithRenderer(input, extensions, renderer)
}
} }
func doTestsBlock(t *testing.T, tests []string, extensions Extensions) { func doTestsBlock(t *testing.T, tests []string, extensions Extensions) {
doTestsBlockWithRunner(t, tests, extensions, runMarkdownBlock) doTestsBlockWithRunner(t, tests, TestParams{
Options: Options{Extensions: extensions},
}, runMarkdownBlock)
} }
func doTestsBlockWithRunner(t *testing.T, tests []string, extensions Extensions, runner func(string, Extensions) string) { func doTestsBlockWithRunner(t *testing.T, tests []string, params TestParams, runner func(string, TestParams) string) {
// catch and report panics // catch and report panics
var candidate string var candidate string
defer func() { defer func() {
@ -59,7 +55,7 @@ func doTestsBlockWithRunner(t *testing.T, tests []string, extensions Extensions,
input := tests[i] input := tests[i]
candidate = input candidate = input
expected := tests[i+1] expected := tests[i+1]
actual := runner(candidate, extensions) actual := runner(candidate, params)
if actual != expected { if actual != expected {
t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]", t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]",
candidate, expected, actual) candidate, expected, actual)
@ -70,7 +66,7 @@ func doTestsBlockWithRunner(t *testing.T, tests []string, extensions Extensions,
for start := 0; start < len(input); start++ { for start := 0; start < len(input); start++ {
for end := start + 1; end <= len(input); end++ { for end := start + 1; end <= len(input); end++ {
candidate = input[start:end] candidate = input[start:end]
_ = runMarkdownBlock(candidate, extensions) _ = runMarkdownBlock(candidate, params)
} }
} }
} }