2011-06-02 08:52:24 +08:00
|
|
|
//
|
2011-06-28 10:11:32 +08:00
|
|
|
// Blackfriday Markdown Processor
|
|
|
|
// Available at http://github.com/russross/blackfriday
|
|
|
|
//
|
|
|
|
// Copyright © 2011 Russ Ross <russ@russross.com>.
|
2011-06-29 01:30:10 +08:00
|
|
|
// Distributed under the Simplified BSD License.
|
2011-06-28 10:11:32 +08:00
|
|
|
// See README.md for details.
|
2011-06-02 08:52:24 +08:00
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Markdown 1.0.3 reference tests
|
|
|
|
//
|
|
|
|
|
|
|
|
package blackfriday
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2013-07-30 10:32:11 +08:00
|
|
|
func runMarkdownReference(input string, flag int) string {
|
2011-06-30 00:08:56 +08:00
|
|
|
renderer := HtmlRenderer(0, "", "")
|
2013-07-30 10:32:11 +08:00
|
|
|
return string(Markdown([]byte(input), renderer, flag))
|
2011-06-02 08:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-07-30 10:32:11 +08:00
|
|
|
func doTestsReference(t *testing.T, files []string, flag int) {
|
2011-07-04 00:51:07 +08:00
|
|
|
// catch and report panics
|
|
|
|
var candidate string
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
2016-07-16 01:52:01 +08:00
|
|
|
t.Errorf("\npanic while processing [%#v]: %s\n", candidate, err)
|
2011-07-04 00:51:07 +08:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2011-06-02 08:52:24 +08:00
|
|
|
for _, basename := range files {
|
2015-03-24 13:27:58 +08:00
|
|
|
filename := filepath.Join("testdata", basename+".text")
|
2011-07-04 00:51:07 +08:00
|
|
|
inputBytes, err := ioutil.ReadFile(filename)
|
2011-06-02 08:52:24 +08:00
|
|
|
if err != nil {
|
2011-07-04 00:51:07 +08:00
|
|
|
t.Errorf("Couldn't open '%s', error: %v\n", filename, err)
|
2011-06-02 08:52:24 +08:00
|
|
|
continue
|
|
|
|
}
|
2011-07-04 00:51:07 +08:00
|
|
|
input := string(inputBytes)
|
|
|
|
|
2015-03-24 13:27:58 +08:00
|
|
|
filename = filepath.Join("testdata", basename+".html")
|
2011-07-04 00:51:07 +08:00
|
|
|
expectedBytes, err := ioutil.ReadFile(filename)
|
2011-06-02 08:52:24 +08:00
|
|
|
if err != nil {
|
2011-07-04 00:51:07 +08:00
|
|
|
t.Errorf("Couldn't open '%s', error: %v\n", filename, err)
|
2011-06-02 08:52:24 +08:00
|
|
|
continue
|
|
|
|
}
|
2011-07-04 00:51:07 +08:00
|
|
|
expected := string(expectedBytes)
|
2011-06-02 08:52:24 +08:00
|
|
|
|
2014-03-31 04:30:38 +08:00
|
|
|
// fmt.Fprintf(os.Stderr, "processing %s ...", filename)
|
2013-07-30 10:32:11 +08:00
|
|
|
actual := string(runMarkdownReference(input, flag))
|
2011-06-02 08:52:24 +08:00
|
|
|
if actual != expected {
|
|
|
|
t.Errorf("\n [%#v]\nExpected[%#v]\nActual [%#v]",
|
|
|
|
basename+".text", expected, actual)
|
|
|
|
}
|
2014-03-31 04:30:38 +08:00
|
|
|
// fmt.Fprintf(os.Stderr, " ok\n")
|
2011-07-04 00:51:07 +08:00
|
|
|
|
2011-07-05 08:56:29 +08:00
|
|
|
// now test every prefix of every input to check for
|
2011-07-04 00:51:07 +08:00
|
|
|
// bounds checking
|
|
|
|
if !testing.Short() {
|
2014-03-31 04:29:24 +08:00
|
|
|
start, max := 0, len(input)
|
|
|
|
for end := start + 1; end <= max; end++ {
|
2011-07-04 00:51:07 +08:00
|
|
|
candidate = input[start:end]
|
2014-03-31 04:30:38 +08:00
|
|
|
// fmt.Fprintf(os.Stderr, " %s %d:%d/%d\n", filename, start, end, max)
|
2013-07-30 10:32:11 +08:00
|
|
|
_ = runMarkdownReference(candidate, flag)
|
2011-07-04 00:51:07 +08:00
|
|
|
}
|
|
|
|
}
|
2011-06-02 08:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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",
|
|
|
|
}
|
2013-07-30 10:32:11 +08:00
|
|
|
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)
|
2011-06-02 08:52:24 +08:00
|
|
|
}
|