all repos — grayfriday @ ad7f7c56d58a2c7f75a14cdcaa8b8acd5dc4f141

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