all repos — grayfriday @ cf6bfc9d6d9f0d0279ff7660e0095b21b7df8c86

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, flag int) string {
 23	renderer := HtmlRenderer(0, "", "")
 24	return string(Markdown([]byte(input), renderer, flag))
 25}
 26
 27func doTestsReference(t *testing.T, files []string, flag int) {
 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		// fmt.Fprintf(os.Stderr, "processing %s ...", filename)
 54		actual := string(runMarkdownReference(input, flag))
 55		if actual != expected {
 56			t.Errorf("\n    [%#v]\nExpected[%#v]\nActual  [%#v]",
 57				basename+".text", expected, actual)
 58		}
 59		// fmt.Fprintf(os.Stderr, " ok\n")
 60
 61		// now test every prefix of every input to check for
 62		// bounds checking
 63		if !testing.Short() {
 64			start, max := 0, len(input)
 65			for end := start + 1; end <= max; end++ {
 66				candidate = input[start:end]
 67				// fmt.Fprintf(os.Stderr, "  %s %d:%d/%d\n", filename, start, end, max)
 68				_ = runMarkdownReference(candidate, flag)
 69			}
 70		}
 71	}
 72}
 73
 74func TestReference(t *testing.T) {
 75	files := []string{
 76		"Amps and angle encoding",
 77		"Auto links",
 78		"Backslash escapes",
 79		"Blockquotes with code blocks",
 80		"Code Blocks",
 81		"Code Spans",
 82		"Hard-wrapped paragraphs with list-like lines",
 83		"Horizontal rules",
 84		"Inline HTML (Advanced)",
 85		"Inline HTML (Simple)",
 86		"Inline HTML comments",
 87		"Links, inline style",
 88		"Links, reference style",
 89		"Links, shortcut references",
 90		"Literal quotes in titles",
 91		"Markdown Documentation - Basics",
 92		"Markdown Documentation - Syntax",
 93		"Nested blockquotes",
 94		"Ordered and unordered lists",
 95		"Strong and em together",
 96		"Tabs",
 97		"Tidyness",
 98	}
 99	doTestsReference(t, files, 0)
100}
101
102func TestReference_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
103	files := []string{
104		"Amps and angle encoding",
105		"Auto links",
106		"Backslash escapes",
107		"Blockquotes with code blocks",
108		"Code Blocks",
109		"Code Spans",
110		"Hard-wrapped paragraphs with list-like lines no empty line before block",
111		"Horizontal rules",
112		"Inline HTML (Advanced)",
113		"Inline HTML (Simple)",
114		"Inline HTML comments",
115		"Links, inline style",
116		"Links, reference style",
117		"Links, shortcut references",
118		"Literal quotes in titles",
119		"Markdown Documentation - Basics",
120		"Markdown Documentation - Syntax",
121		"Nested blockquotes",
122		"Ordered and unordered lists",
123		"Strong and em together",
124		"Tabs",
125		"Tidyness",
126	}
127	doTestsReference(t, files, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)
128}