-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder_test.go
71 lines (65 loc) · 1.64 KB
/
builder_test.go
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
package vss
import (
"fmt"
"testing"
"github.com/cbroglie/mustache"
)
func TestConvertMarkdownPathToHtmlPath(t *testing.T) {
tests := []struct {
name string
markdownPath string
expected string
}{
{
name: "converts .md to .html",
markdownPath: "example.md",
expected: "example.html",
},
{
name: "handles path contains a directory",
markdownPath: "docs/tutorial.md",
expected: "docs/tutorial.html",
},
{
name: "handles multiple .md extensions",
markdownPath: "docs/tutorial.md.md",
expected: "docs/tutorial.md.html",
},
{
name: "handles uppercase .MD extension",
markdownPath: "README.MD",
expected: "README.html",
},
{
name: "no handles .markdown extension",
markdownPath: "readme.markdown",
expected: "readme.markdown",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := convertMarkdownPathToHtmlPath(test.markdownPath)
if result != test.expected {
t.Errorf("expected %s, but got %s", test.expected, result)
}
})
}
}
func BenchmarkTemplateMapWithoutSize(b *testing.B) {
builder := new(Builder)
m := make(map[string]*mustache.Template)
for i := 0; i < b.N; i++ {
t, _ := mustache.ParseFile("testdata/test_template.html")
m[fmt.Sprintf("%d_test.html", i)] = t
}
builder.templateMap = m
}
func BenchmarkTemplateMapWithSize(b *testing.B) {
builder := new(Builder)
m := make(map[string]*mustache.Template, b.N)
for i := 0; i < b.N; i++ {
t, _ := mustache.ParseFile("testdata/test_template.html")
m[fmt.Sprintf("%d_test.html", i)] = t
}
builder.templateMap = m
}