1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
package markdown
import (
"io/ioutil"
"path/filepath"
"testing"
"github.com/gomarkdown/markdown/parser"
)
// Markdown 1.0.3 reference tests
var (
refFiles = []string{
"Amps and angle encoding",
"Auto links",
"Backslash escapes",
"Blockquotes with code blocks",
"Code Blocks",
"Code Spans",
"Horizontal rules",
"Inline HTML (Advanced)",
"Inline HTML (Simple)",
"Inline HTML comments",
"Links, inline style",
"Links, reference style",
"Links, shortcut references",
"Literal quotes in titles",
"Markdown Documentation - Basics",
"Markdown Documentation - Syntax",
"Nested blockquotes",
"Ordered and unordered lists",
"Strong and em together",
"Tabs",
"Tidyness",
// New tests added for gomarkdown
"Entities",
}
)
func TestReference(t *testing.T) {
files := append(refFiles, "Hard-wrapped paragraphs with list-like lines")
doTestsReference(t, files, 0)
}
func TestReference_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
files := append(refFiles, "Hard-wrapped paragraphs with list-like lines no empty line before block")
doTestsReference(t, files, parser.NoEmptyLineBeforeBlock)
}
// benchResultAnchor is an anchor variable to store the result of a benchmarked
// code so that compiler could never optimize away the call to runMarkdown()
var benchResultAnchor string
func benchFile(b *testing.B, basename string) {
params := TestParams{extensions: parser.CommonExtensions}
filename := filepath.Join("testdata", basename+".text")
inputBytes, err := ioutil.ReadFile(filename)
if err != nil {
b.Errorf("Couldn't open '%s', error: %v\n", filename, err)
return
}
test := string(inputBytes)
b.ResetTimer()
for n := 0; n < b.N; n++ {
benchResultAnchor = runMarkdown(test, params)
}
}
func BenchmarkReferenceAmps(b *testing.B) {
benchFile(b, "Amps and angle encoding")
}
func BenchmarkReferenceAutoLinks(b *testing.B) {
benchFile(b, "Auto links")
}
func BenchmarkReferenceBackslashEscapes(b *testing.B) {
benchFile(b, "Backslash escapes")
}
func BenchmarkReferenceBlockquotesWithCodeBlocks(b *testing.B) {
benchFile(b, "Blockquotes with code blocks")
}
func BenchmarkReferenceCodeBlocks(b *testing.B) {
benchFile(b, "Code Blocks")
}
func BenchmarkReferenceCodeSpans(b *testing.B) {
benchFile(b, "Code Spans")
}
func BenchmarkReferenceHardWrappedPara(b *testing.B) {
benchFile(b, "Hard-wrapped paragraphs with list-like lines")
}
func BenchmarkReferenceHorizontalRules(b *testing.B) {
benchFile(b, "Horizontal rules")
}
func BenchmarkReferenceInlineHTMLAdvances(b *testing.B) {
benchFile(b, "Inline HTML (Advanced)")
}
func BenchmarkReferenceInlineHTMLSimple(b *testing.B) {
benchFile(b, "Inline HTML (Simple)")
}
func BenchmarkReferenceInlineHTMLComments(b *testing.B) {
benchFile(b, "Inline HTML comments")
}
func BenchmarkReferenceLinksInline(b *testing.B) {
benchFile(b, "Links, inline style")
}
func BenchmarkReferenceLinksReference(b *testing.B) {
benchFile(b, "Links, reference style")
}
func BenchmarkReferenceLinksShortcut(b *testing.B) {
benchFile(b, "Links, shortcut references")
}
func BenchmarkReferenceLiterQuotesInTitles(b *testing.B) {
benchFile(b, "Literal quotes in titles")
}
func BenchmarkReferenceMarkdownBasics(b *testing.B) {
benchFile(b, "Markdown Documentation - Basics")
}
func BenchmarkReferenceMarkdownSyntax(b *testing.B) {
benchFile(b, "Markdown Documentation - Syntax")
}
func BenchmarkReferenceNestedBlockquotes(b *testing.B) {
benchFile(b, "Nested blockquotes")
}
func BenchmarkReferenceOrderedAndUnorderedLists(b *testing.B) {
benchFile(b, "Ordered and unordered lists")
}
func BenchmarkReferenceStrongAndEm(b *testing.B) {
benchFile(b, "Strong and em together")
}
func BenchmarkReferenceTabs(b *testing.B) {
benchFile(b, "Tabs")
}
func BenchmarkReferenceTidyness(b *testing.B) {
benchFile(b, "Tidyness")
}
func BenchmarkReference(b *testing.B) {
params := TestParams{extensions: parser.CommonExtensions}
files := append(refFiles, "Hard-wrapped paragraphs with list-like lines")
var tests []string
for _, basename := range files {
filename := filepath.Join("testdata", basename+".text")
inputBytes, err := ioutil.ReadFile(filename)
if err != nil {
b.Errorf("Couldn't open '%s', error: %v\n", filename, err)
continue
}
tests = append(tests, string(inputBytes))
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
for _, test := range tests {
benchResultAnchor = runMarkdown(test, params)
}
}
}
|