all repos — grayfriday @ 3b2b20c8cb0632a0442ea9694d170b8aea985549

blackfriday fork with a few changes

ref_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 TestReference(t *testing.T) {
 23	t.Parallel()
 24	files := []string{
 25		"Amps and angle encoding",
 26		"Auto links",
 27		"Backslash escapes",
 28		"Blockquotes with code blocks",
 29		"Code Blocks",
 30		"Code Spans",
 31		"Hard-wrapped paragraphs with list-like lines",
 32		"Horizontal rules",
 33		"Inline HTML (Advanced)",
 34		"Inline HTML (Simple)",
 35		"Inline HTML comments",
 36		"Links, inline style",
 37		"Links, reference style",
 38		"Links, shortcut references",
 39		"Literal quotes in titles",
 40		"Markdown Documentation - Basics",
 41		"Markdown Documentation - Syntax",
 42		"Nested blockquotes",
 43		"Ordered and unordered lists",
 44		"Strong and em together",
 45		"Tabs",
 46		"Tidyness",
 47	}
 48	doTestsReference(t, files, 0)
 49}
 50
 51func TestReference_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
 52	t.Parallel()
 53	files := []string{
 54		"Amps and angle encoding",
 55		"Auto links",
 56		"Backslash escapes",
 57		"Blockquotes with code blocks",
 58		"Code Blocks",
 59		"Code Spans",
 60		"Hard-wrapped paragraphs with list-like lines no empty line before block",
 61		"Horizontal rules",
 62		"Inline HTML (Advanced)",
 63		"Inline HTML (Simple)",
 64		"Inline HTML comments",
 65		"Links, inline style",
 66		"Links, reference style",
 67		"Links, shortcut references",
 68		"Literal quotes in titles",
 69		"Markdown Documentation - Basics",
 70		"Markdown Documentation - Syntax",
 71		"Nested blockquotes",
 72		"Ordered and unordered lists",
 73		"Strong and em together",
 74		"Tabs",
 75		"Tidyness",
 76	}
 77	doTestsReference(t, files, NoEmptyLineBeforeBlock)
 78}
 79
 80// benchResultAnchor is an anchor variable to store the result of a benchmarked
 81// code so that compiler could never optimize away the call to runMarkdown()
 82var benchResultAnchor string
 83
 84func BenchmarkReference(b *testing.B) {
 85	params := TestParams{extensions: CommonExtensions}
 86	files := []string{
 87		"Amps and angle encoding",
 88		"Auto links",
 89		"Backslash escapes",
 90		"Blockquotes with code blocks",
 91		"Code Blocks",
 92		"Code Spans",
 93		"Hard-wrapped paragraphs with list-like lines",
 94		"Horizontal rules",
 95		"Inline HTML (Advanced)",
 96		"Inline HTML (Simple)",
 97		"Inline HTML comments",
 98		"Links, inline style",
 99		"Links, reference style",
100		"Links, shortcut references",
101		"Literal quotes in titles",
102		"Markdown Documentation - Basics",
103		"Markdown Documentation - Syntax",
104		"Nested blockquotes",
105		"Ordered and unordered lists",
106		"Strong and em together",
107		"Tabs",
108		"Tidyness",
109	}
110	var tests []string
111	for _, basename := range files {
112		filename := filepath.Join("testdata", basename+".text")
113		inputBytes, err := ioutil.ReadFile(filename)
114		if err != nil {
115			b.Errorf("Couldn't open '%s', error: %v\n", filename, err)
116			continue
117		}
118		tests = append(tests, string(inputBytes))
119	}
120	b.ResetTimer()
121	for n := 0; n < b.N; n++ {
122		for _, test := range tests {
123			benchResultAnchor = runMarkdown(test, params)
124		}
125	}
126}