all repos — grayfriday @ fb923cdb7885cc75de960e11e527c6c0b1405923

blackfriday fork with a few changes

upskirtref_test.go (view raw)

 1//
 2// Blackfriday Markdown Processor
 3// Available at http://github.com/russross/blackfriday
 4//
 5// Copyright © 2011 Russ Ross <russ@russross.com>.
 6// Distributed under the Simplified BSD License.
 7// See README.md for details.
 8//
 9
10//
11// Markdown 1.0.3 reference tests
12//
13
14package blackfriday
15
16import (
17	"io/ioutil"
18	"path/filepath"
19	"testing"
20)
21
22func runMarkdownReference(input string) string {
23	renderer := HtmlRenderer(0, "", "")
24	return string(Markdown([]byte(input), renderer, 0))
25}
26
27func doTestsReference(t *testing.T, files []string) {
28	// catch and report panics
29	var candidate string
30	defer func() {
31		if err := recover(); err != nil {
32			t.Errorf("\npanic while processing [%#v]\n", candidate)
33		}
34	}()
35
36	for _, basename := range files {
37		filename := filepath.Join("upskirtref", basename+".text")
38		inputBytes, err := ioutil.ReadFile(filename)
39		if err != nil {
40			t.Errorf("Couldn't open '%s', error: %v\n", filename, err)
41			continue
42		}
43		input := string(inputBytes)
44
45		filename = filepath.Join("upskirtref", basename+".html")
46		expectedBytes, err := ioutil.ReadFile(filename)
47		if err != nil {
48			t.Errorf("Couldn't open '%s', error: %v\n", filename, err)
49			continue
50		}
51		expected := string(expectedBytes)
52
53		actual := string(runMarkdownReference(input))
54		if actual != expected {
55			t.Errorf("\n    [%#v]\nExpected[%#v]\nActual  [%#v]",
56				basename+".text", expected, actual)
57		}
58
59		// now test every prefix of every input to check for
60		// bounds checking
61		if !testing.Short() {
62			start := 0
63			for end := start + 1; end <= len(input); end++ {
64				candidate = input[start:end]
65				_ = runMarkdownReference(candidate)
66			}
67		}
68	}
69}
70
71func TestReference(t *testing.T) {
72	files := []string{
73		"Amps and angle encoding",
74		"Auto links",
75		"Backslash escapes",
76		"Blockquotes with code blocks",
77		"Code Blocks",
78		"Code Spans",
79		"Hard-wrapped paragraphs with list-like lines",
80		"Horizontal rules",
81		"Inline HTML (Advanced)",
82		"Inline HTML (Simple)",
83		"Inline HTML comments",
84		"Links, inline style",
85		"Links, reference style",
86		"Links, shortcut references",
87		"Literal quotes in titles",
88		"Markdown Documentation - Basics",
89		"Markdown Documentation - Syntax",
90		"Nested blockquotes",
91		"Ordered and unordered lists",
92		"Strong and em together",
93		"Tabs",
94		"Tidyness",
95	}
96	doTestsReference(t, files)
97}