all repos — grayfriday @ 472fe3a75661156c826b7b148cd4c0c0e28f84a9

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		actual := string(runMarkdownReference(input, flag))
 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, flag)
 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, 0)
 97}
 98
 99func TestReference_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
100	files := []string{
101		"Amps and angle encoding",
102		"Auto links",
103		"Backslash escapes",
104		"Blockquotes with code blocks",
105		"Code Blocks",
106		"Code Spans",
107		"Hard-wrapped paragraphs with list-like lines no empty line before block",
108		"Horizontal rules",
109		"Inline HTML (Advanced)",
110		"Inline HTML (Simple)",
111		"Inline HTML comments",
112		"Links, inline style",
113		"Links, reference style",
114		"Links, shortcut references",
115		"Literal quotes in titles",
116		"Markdown Documentation - Basics",
117		"Markdown Documentation - Syntax",
118		"Nested blockquotes",
119		"Ordered and unordered lists",
120		"Strong and em together",
121		"Tabs",
122		"Tidyness",
123	}
124	doTestsReference(t, files, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)
125}