Use TestParams in block tests The different testing function interfaces get unified a bit closer, runnerWithRendererParameters completely eliminated.
Vytautas Ĺ altenis vytas@rtfb.lt
Mon, 04 Apr 2016 11:45:36 +0300
2 files changed,
18 insertions(+),
16 deletions(-)
M
block_test.go
→
block_test.go
@@ -252,7 +252,10 @@ HeaderIDPrefix: "PRE:",
HeaderIDSuffix: ":POST", } - doTestsBlockWithRunner(t, tests, HeaderIDs, runnerWithRendererParameters(parameters)) + doTestsBlockWithRunner(t, tests, TestParams{ + Options: Options{Extensions: HeaderIDs}, + HTMLRendererParameters: parameters, + }, runMarkdownBlock) } func TestPrefixAutoHeaderIdExtension(t *testing.T) {@@ -360,7 +363,10 @@ HeaderIDPrefix: "PRE:",
HeaderIDSuffix: ":POST", } - doTestsBlockWithRunner(t, tests, AutoHeaderIDs, runnerWithRendererParameters(parameters)) + doTestsBlockWithRunner(t, tests, TestParams{ + Options: Options{Extensions: AutoHeaderIDs}, + HTMLRendererParameters: parameters, + }, runMarkdownBlock) } func TestPrefixMultipleHeaderExtensions(t *testing.T) {
M
test_helpers.go
→
test_helpers.go
@@ -30,23 +30,19 @@ func runMarkdownBlockWithRenderer(input string, extensions Extensions, renderer Renderer) string {
return string(Markdown([]byte(input), renderer, extensions)) } -func runMarkdownBlock(input string, extensions Extensions) string { - renderer := HTMLRenderer(UseXHTML, extensions, "", "") - return runMarkdownBlockWithRenderer(input, 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 runMarkdownBlock(input string, params TestParams) string { + renderer := HTMLRendererWithParameters(params.HTMLFlags|UseXHTML, + params.Options.Extensions, "", "", params.HTMLRendererParameters) + return runMarkdownBlockWithRenderer(input, params.Options.Extensions, renderer) } 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 var candidate string defer func() {@@ -59,7 +55,7 @@ for i := 0; i+1 < len(tests); i += 2 {
input := tests[i] candidate = input expected := tests[i+1] - actual := runner(candidate, extensions) + actual := runner(candidate, params) if actual != expected { t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]", candidate, expected, actual)@@ -70,7 +66,7 @@ if !testing.Short() {
for start := 0; start < len(input); start++ { for end := start + 1; end <= len(input); end++ { candidate = input[start:end] - _ = runMarkdownBlock(candidate, extensions) + _ = runMarkdownBlock(candidate, params) } } }