all repos — grayfriday @ a658caacc6244df1b6a760c6a571e579a2327b57

blackfriday fork with a few changes

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
commit

a658caacc6244df1b6a760c6a571e579a2327b57

parent

b069de6276dd481b9f2af5e04315e85c53e35ff0

2 files changed, 18 insertions(+), 16 deletions(-)

jump to
M block_test.goblock_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.gotest_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) } } }