diff --git a/inline_test.go b/inline_test.go index 445c2c0..e16cab9 100644 --- a/inline_test.go +++ b/inline_test.go @@ -99,38 +99,41 @@ func TestReferenceOverride(t *testing.T) { "test [ref5][]\n", "
test Moo
\n", } - doTestsInlineParam(t, tests, Options{ - ReferenceOverride: func(reference string) (rv *Reference, overridden bool) { - switch reference { - case "ref1": - // just an overriden reference exists without definition - return &Reference{ - Link: "http://www.ref1.com/", - Title: "Reference 1"}, true - case "ref2": - // overridden exists and reference defined - return &Reference{ - Link: "http://www.overridden.com/", - Title: "Reference Overridden"}, true - case "ref3": - // not overridden and reference defined + doTestsInlineParam(t, tests, TestParams{ + Options: Options{ + ReferenceOverride: func(reference string) (rv *Reference, overridden bool) { + switch reference { + case "ref1": + // just an overriden reference exists without definition + return &Reference{ + Link: "http://www.ref1.com/", + Title: "Reference 1"}, true + case "ref2": + // overridden exists and reference defined + return &Reference{ + Link: "http://www.overridden.com/", + Title: "Reference Overridden"}, true + case "ref3": + // not overridden and reference defined + return nil, false + case "ref4": + // overridden missing and defined + return nil, true + case "!(*http.ServeMux).ServeHTTP": + return &Reference{ + Link: "http://localhost:6060/pkg/net/http/#ServeMux.ServeHTTP", + Title: "ServeHTTP docs"}, true + case "ref5": + return &Reference{ + Link: "http://www.ref5.com/", + Title: "Reference 5", + Text: "Moo", + }, true + } return nil, false - case "ref4": - // overridden missing and defined - return nil, true - case "!(*http.ServeMux).ServeHTTP": - return &Reference{ - Link: "http://localhost:6060/pkg/net/http/#ServeMux.ServeHTTP", - Title: "ServeHTTP docs"}, true - case "ref5": - return &Reference{ - Link: "http://www.ref5.com/", - Title: "Reference 5", - Text: "Moo", - }, true - } - return nil, false - }}, 0, HTMLRendererParameters{}) + }, + }, + }) } func TestStrong(t *testing.T) { @@ -340,9 +343,8 @@ func TestLineBreak(t *testing.T) { "this has an \nextra space\n", "this has an
\nextra space
blahblah\n\nrhubarb
\n", } - doTestsInlineParam(t, tests, Options{Extensions: Smartypants | SmartypantsDashes}, 0, HTMLRendererParameters{}) + doTestsInlineParam(t, tests, TestParams{ + Options: Options{ + Extensions: Smartypants | SmartypantsDashes, + }, + }) } func TestSmartDoubleQuotes(t *testing.T) { @@ -1012,7 +1028,11 @@ func TestSmartDoubleQuotes(t *testing.T) { "two pair of \"some\" quoted \"text\".\n", "two pair of “some” quoted “text”.
\n"} - doTestsInlineParam(t, tests, Options{Extensions: Smartypants}, 0, HTMLRendererParameters{}) + doTestsInlineParam(t, tests, TestParams{ + Options: Options{ + Extensions: Smartypants, + }, + }) } func TestSmartAngledDoubleQuotes(t *testing.T) { @@ -1024,7 +1044,11 @@ func TestSmartAngledDoubleQuotes(t *testing.T) { "two pair of \"some\" quoted \"text\".\n", "two pair of «some» quoted «text».
\n"} - doTestsInlineParam(t, tests, Options{Extensions: Smartypants | SmartypantsAngledQuotes}, 0, HTMLRendererParameters{}) + doTestsInlineParam(t, tests, TestParams{ + Options: Options{ + Extensions: Smartypants | SmartypantsAngledQuotes, + }, + }) } func TestSmartFractions(t *testing.T) { @@ -1034,7 +1058,11 @@ func TestSmartFractions(t *testing.T) { "1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.\n", "1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.
\n"} - doTestsInlineParam(t, tests, Options{Extensions: Smartypants}, 0, HTMLRendererParameters{}) + doTestsInlineParam(t, tests, TestParams{ + Options: Options{ + Extensions: Smartypants, + }, + }) tests = []string{ "1/2, 2/3, 81/100 and 1000000/1048576.\n", @@ -1042,7 +1070,11 @@ func TestSmartFractions(t *testing.T) { "1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.\n", "1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.
\n"} - doTestsInlineParam(t, tests, Options{Extensions: Smartypants | SmartypantsFractions}, 0, HTMLRendererParameters{}) + doTestsInlineParam(t, tests, TestParams{ + Options: Options{ + Extensions: Smartypants | SmartypantsFractions, + }, + }) } func TestDisableSmartDashes(t *testing.T) { @@ -1053,7 +1085,7 @@ func TestDisableSmartDashes(t *testing.T) { "foo -- bar
\n", "foo --- bar\n", "foo --- bar
\n", - }, Options{}, 0, HTMLRendererParameters{}) + }, TestParams{}) doTestsInlineParam(t, []string{ "foo - bar\n", "foo – bar
\n", @@ -1061,7 +1093,7 @@ func TestDisableSmartDashes(t *testing.T) { "foo — bar
\n", "foo --- bar\n", "foo —– bar
\n", - }, Options{Extensions: Smartypants | SmartypantsDashes}, 0, HTMLRendererParameters{}) + }, TestParams{Options: Options{Extensions: Smartypants | SmartypantsDashes}}) doTestsInlineParam(t, []string{ "foo - bar\n", "foo - bar
\n", @@ -1069,8 +1101,11 @@ func TestDisableSmartDashes(t *testing.T) { "foo – bar
\n", "foo --- bar\n", "foo — bar
\n", - }, Options{Extensions: Smartypants | SmartypantsLatexDashes | SmartypantsDashes}, 0, - HTMLRendererParameters{}) + }, TestParams{ + Options: Options{ + Extensions: Smartypants | SmartypantsLatexDashes | SmartypantsDashes, + }, + }) doTestsInlineParam(t, []string{ "foo - bar\n", "foo - bar
\n", @@ -1078,7 +1113,6 @@ func TestDisableSmartDashes(t *testing.T) { "foo -- bar
\n", "foo --- bar\n", "foo --- bar
\n", - }, Options{Extensions: Smartypants | SmartypantsLatexDashes}, - 0, - HTMLRendererParameters{}) + }, TestParams{ + Options: Options{Extensions: Smartypants | SmartypantsLatexDashes}}) } diff --git a/test_helpers.go b/test_helpers.go index 8f91c08..22c3fa1 100644 --- a/test_helpers.go +++ b/test_helpers.go @@ -20,6 +20,12 @@ import ( "testing" ) +type TestParams struct { + Options + HTMLFlags + HTMLRendererParameters +} + func runMarkdownBlockWithRenderer(input string, extensions Extensions, renderer Renderer) string { return string(Markdown([]byte(input), renderer, extensions)) } @@ -71,19 +77,19 @@ func doTestsBlockWithRunner(t *testing.T, tests []string, extensions Extensions, } } -func runMarkdownInline(input string, opts Options, htmlFlags HTMLFlags, params HTMLRendererParameters) string { +func runMarkdownInline(input string, params TestParams) string { + opts := params.Options opts.Extensions |= Autolink opts.Extensions |= Strikethrough - htmlFlags |= UseXHTML - - renderer := HTMLRendererWithParameters(htmlFlags, opts.Extensions, "", "", params) + renderer := HTMLRendererWithParameters(params.HTMLFlags|UseXHTML, + opts.Extensions, "", "", params.HTMLRendererParameters) return string(MarkdownOptions([]byte(input), renderer, opts)) } func doTestsInline(t *testing.T, tests []string) { - doTestsInlineParam(t, tests, Options{}, 0, HTMLRendererParameters{}) + doTestsInlineParam(t, tests, TestParams{}) } func doLinkTestsInline(t *testing.T, tests []string) { @@ -92,22 +98,30 @@ func doLinkTestsInline(t *testing.T, tests []string) { prefix := "http://localhost" params := HTMLRendererParameters{AbsolutePrefix: prefix} transformTests := transformLinks(tests, prefix) - doTestsInlineParam(t, transformTests, Options{}, 0, params) - doTestsInlineParam(t, transformTests, Options{}, CommonHtmlFlags, params) + doTestsInlineParam(t, transformTests, TestParams{ + HTMLRendererParameters: params, + }) + doTestsInlineParam(t, transformTests, TestParams{ + HTMLFlags: CommonHtmlFlags, + HTMLRendererParameters: params, + }) } func doSafeTestsInline(t *testing.T, tests []string) { - doTestsInlineParam(t, tests, Options{}, Safelink, HTMLRendererParameters{}) + doTestsInlineParam(t, tests, TestParams{HTMLFlags: Safelink}) // All the links in this test should not have the prefix appended, so // just rerun it with different parameters and the same expectations. prefix := "http://localhost" params := HTMLRendererParameters{AbsolutePrefix: prefix} transformTests := transformLinks(tests, prefix) - doTestsInlineParam(t, transformTests, Options{}, Safelink, params) + doTestsInlineParam(t, transformTests, TestParams{ + HTMLFlags: Safelink, + HTMLRendererParameters: params, + }) } -func doTestsInlineParam(t *testing.T, tests []string, opts Options, htmlFlags HTMLFlags, params HTMLRendererParameters) { +func doTestsInlineParam(t *testing.T, tests []string, params TestParams) { // catch and report panics var candidate string defer func() { @@ -120,7 +134,7 @@ func doTestsInlineParam(t *testing.T, tests []string, opts Options, htmlFlags HT input := tests[i] candidate = input expected := tests[i+1] - actual := runMarkdownInline(candidate, opts, htmlFlags, params) + actual := runMarkdownInline(candidate, params) if actual != expected { t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]", candidate, expected, actual) @@ -131,7 +145,7 @@ func doTestsInlineParam(t *testing.T, tests []string, opts Options, htmlFlags HT for start := 0; start < len(input); start++ { for end := start + 1; end <= len(input); end++ { candidate = input[start:end] - _ = runMarkdownInline(candidate, opts, htmlFlags, params) + runMarkdownInline(candidate, params) } } }