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