mirror of
https://github.com/danog/blackfriday.git
synced 2024-11-26 20:14:43 +01:00
96537c6eaa
These will be helpful for catching regressions or changes in behavior to edge cases such as empty input, or specifically crafted inputs that may cause panics, etc. Move test for issue #172 there since it's a document-level test, not an inline one. Add test for issue #173. Make some things more consistent. Don't use a named receiver in methods that don't use it. This makes the code more readable since one can more quickly tell the inputs to the method.
129 lines
3.2 KiB
Go
129 lines
3.2 KiB
Go
//
|
|
// Blackfriday Markdown Processor
|
|
// Available at http://github.com/russross/blackfriday
|
|
//
|
|
// Copyright © 2011 Russ Ross <russ@russross.com>.
|
|
// Distributed under the Simplified BSD License.
|
|
// See README.md for details.
|
|
//
|
|
|
|
//
|
|
// Markdown 1.0.3 reference tests
|
|
//
|
|
|
|
package blackfriday
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func runMarkdownReference(input string, flag int) string {
|
|
renderer := HtmlRenderer(0, "", "")
|
|
return string(Markdown([]byte(input), renderer, flag))
|
|
}
|
|
|
|
func doTestsReference(t *testing.T, files []string, flag int) {
|
|
// catch and report panics
|
|
var candidate string
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
t.Errorf("\npanic while processing [%#v]: %s\n", candidate, err)
|
|
}
|
|
}()
|
|
|
|
for _, basename := range files {
|
|
filename := filepath.Join("testdata", basename+".text")
|
|
inputBytes, err := ioutil.ReadFile(filename)
|
|
if err != nil {
|
|
t.Errorf("Couldn't open '%s', error: %v\n", filename, err)
|
|
continue
|
|
}
|
|
input := string(inputBytes)
|
|
|
|
filename = filepath.Join("testdata", basename+".html")
|
|
expectedBytes, err := ioutil.ReadFile(filename)
|
|
if err != nil {
|
|
t.Errorf("Couldn't open '%s', error: %v\n", filename, err)
|
|
continue
|
|
}
|
|
expected := string(expectedBytes)
|
|
|
|
// fmt.Fprintf(os.Stderr, "processing %s ...", filename)
|
|
actual := string(runMarkdownReference(input, flag))
|
|
if actual != expected {
|
|
t.Errorf("\n [%#v]\nExpected[%#v]\nActual [%#v]",
|
|
basename+".text", expected, actual)
|
|
}
|
|
// fmt.Fprintf(os.Stderr, " ok\n")
|
|
|
|
// now test every prefix of every input to check for
|
|
// bounds checking
|
|
if !testing.Short() {
|
|
start, max := 0, len(input)
|
|
for end := start + 1; end <= max; end++ {
|
|
candidate = input[start:end]
|
|
// fmt.Fprintf(os.Stderr, " %s %d:%d/%d\n", filename, start, end, max)
|
|
_ = runMarkdownReference(candidate, flag)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestReference(t *testing.T) {
|
|
files := []string{
|
|
"Amps and angle encoding",
|
|
"Auto links",
|
|
"Backslash escapes",
|
|
"Blockquotes with code blocks",
|
|
"Code Blocks",
|
|
"Code Spans",
|
|
"Hard-wrapped paragraphs with list-like lines",
|
|
"Horizontal rules",
|
|
"Inline HTML (Advanced)",
|
|
"Inline HTML (Simple)",
|
|
"Inline HTML comments",
|
|
"Links, inline style",
|
|
"Links, reference style",
|
|
"Links, shortcut references",
|
|
"Literal quotes in titles",
|
|
"Markdown Documentation - Basics",
|
|
"Markdown Documentation - Syntax",
|
|
"Nested blockquotes",
|
|
"Ordered and unordered lists",
|
|
"Strong and em together",
|
|
"Tabs",
|
|
"Tidyness",
|
|
}
|
|
doTestsReference(t, files, 0)
|
|
}
|
|
|
|
func TestReference_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
|
|
files := []string{
|
|
"Amps and angle encoding",
|
|
"Auto links",
|
|
"Backslash escapes",
|
|
"Blockquotes with code blocks",
|
|
"Code Blocks",
|
|
"Code Spans",
|
|
"Hard-wrapped paragraphs with list-like lines no empty line before block",
|
|
"Horizontal rules",
|
|
"Inline HTML (Advanced)",
|
|
"Inline HTML (Simple)",
|
|
"Inline HTML comments",
|
|
"Links, inline style",
|
|
"Links, reference style",
|
|
"Links, shortcut references",
|
|
"Literal quotes in titles",
|
|
"Markdown Documentation - Basics",
|
|
"Markdown Documentation - Syntax",
|
|
"Nested blockquotes",
|
|
"Ordered and unordered lists",
|
|
"Strong and em together",
|
|
"Tabs",
|
|
"Tidyness",
|
|
}
|
|
doTestsReference(t, files, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)
|
|
}
|