all repos — grayfriday @ 0774c060d74766118a136c287377ee95c9cd7cc2

blackfriday fork with a few changes

Get rid of unnecessary test helpers
Vytautas Ĺ altenis vytas@rtfb.lt
Mon, 04 Apr 2016 14:00:26 +0300
commit

0774c060d74766118a136c287377ee95c9cd7cc2

parent

f35fae8188b283b28b2d3e4c3159e13c0b36440f

2 files changed, 22 insertions(+), 40 deletions(-)

jump to
M block_test.goblock_test.go

@@ -252,10 +252,11 @@ HeaderIDPrefix: "PRE:",

HeaderIDSuffix: ":POST", } - doTestsBlockWithRunner(t, tests, TestParams{ + doTestsParam(t, tests, TestParams{ Options: Options{Extensions: HeaderIDs}, + HTMLFlags: UseXHTML, HTMLRendererParameters: parameters, - }, runMarkdownBlock) + }) } func TestPrefixAutoHeaderIdExtension(t *testing.T) {

@@ -363,10 +364,11 @@ HeaderIDPrefix: "PRE:",

HeaderIDSuffix: ":POST", } - doTestsBlockWithRunner(t, tests, TestParams{ + doTestsParam(t, tests, TestParams{ Options: Options{Extensions: AutoHeaderIDs}, + HTMLFlags: UseXHTML, HTMLRendererParameters: parameters, - }, runMarkdownBlock) + }) } func TestPrefixMultipleHeaderExtensions(t *testing.T) {
M test_helpers.gotest_helpers.go

@@ -42,33 +42,26 @@ }

suite(&candidate) } -func runMarkdownBlockWithRenderer(input string, extensions Extensions, renderer Renderer) string { - return string(Markdown([]byte(input), renderer, extensions)) -} - -func runMarkdownBlock(input string, params TestParams) string { - renderer := HTMLRendererWithParameters(params.HTMLFlags|UseXHTML, +func runMarkdown(input string, params TestParams) string { + renderer := HTMLRendererWithParameters(params.HTMLFlags, params.Options.Extensions, "", "", params.HTMLRendererParameters) - return runMarkdownBlockWithRenderer(input, params.Options.Extensions, renderer) + return string(MarkdownOptions([]byte(input), renderer, params.Options)) } func doTestsBlock(t *testing.T, tests []string, extensions Extensions) { - doTestsBlockWithRunner(t, tests, TestParams{ - Options: Options{Extensions: extensions}, - }, runMarkdownBlock) + doTestsParam(t, tests, TestParams{ + Options: Options{Extensions: extensions}, + HTMLFlags: UseXHTML, + }) } -func doTestsBlockWithRunner(t *testing.T, tests []string, params TestParams, runner func(string, TestParams) string) { - doTestsWithRunner(t, tests, params, runner) -} - -func doTestsWithRunner(t *testing.T, tests []string, params TestParams, runner func(string, TestParams) string) { +func doTestsParam(t *testing.T, tests []string, params TestParams) { execRecoverableTestSuite(t, tests, params, func(candidate *string) { for i := 0; i+1 < len(tests); i += 2 { input := tests[i] *candidate = input expected := tests[i+1] - actual := runner(*candidate, params) + actual := runMarkdown(*candidate, params) if actual != expected { t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]", candidate, expected, actual)

@@ -79,23 +72,12 @@ if !testing.Short() {

for start := 0; start < len(input); start++ { for end := start + 1; end <= len(input); end++ { *candidate = input[start:end] - runner(*candidate, params) + runMarkdown(*candidate, params) } } } } }) -} - -func runMarkdownInline(input string, params TestParams) string { - opts := params.Options - opts.Extensions |= Autolink - opts.Extensions |= Strikethrough - - renderer := HTMLRendererWithParameters(params.HTMLFlags|UseXHTML, - opts.Extensions, "", "", params.HTMLRendererParameters) - - return string(MarkdownOptions([]byte(input), renderer, opts)) } func doTestsInline(t *testing.T, tests []string) {

@@ -132,7 +114,10 @@ })

} func doTestsInlineParam(t *testing.T, tests []string, params TestParams) { - doTestsWithRunner(t, tests, params, runMarkdownInline) + params.Options.Extensions |= Autolink + params.Options.Extensions |= Strikethrough + params.HTMLFlags |= UseXHTML + doTestsParam(t, tests, params) } func transformLinks(tests []string, prefix string) []string {

@@ -149,11 +134,6 @@ }

return newTests } -func runMarkdownReference(input string, params TestParams) string { - renderer := HTMLRenderer(0, params.Options.Extensions, "", "") - return string(Markdown([]byte(input), renderer, params.Options.Extensions)) -} - func doTestsReference(t *testing.T, files []string, flag Extensions) { params := TestParams{Options: Options{Extensions: flag}} execRecoverableTestSuite(t, files, params, func(candidate *string) {

@@ -174,7 +154,7 @@ continue

} expected := string(expectedBytes) - actual := string(runMarkdownReference(input, params)) + actual := string(runMarkdown(input, params)) if actual != expected { t.Errorf("\n [%#v]\nExpected[%#v]\nActual [%#v]", basename+".text", expected, actual)

@@ -186,7 +166,7 @@ if !testing.Short() {

start, max := 0, len(input) for end := start + 1; end <= max; end++ { *candidate = input[start:end] - _ = runMarkdownReference(*candidate, params) + runMarkdown(*candidate, params) } } }