-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathhelpers_test.go
75 lines (70 loc) · 1.73 KB
/
helpers_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
72
73
74
75
package xlog
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/yuin/goldmark/text"
)
func TestBanner(t *testing.T) {
tcs := []struct {
name string
path string
content string
expected string
}{
{
name: "page in root and image is relative implicitly",
path: "home",
content: "",
expected: "/image.jpg",
},
{
name: "page in root and image is relative explicitly",
path: "home",
content: "",
expected: "/image.jpg",
},
{
name: "page in root and image is relative explicitly in subdir",
path: "home",
content: "",
expected: "/images/image.jpg",
},
{
name: "page in subdir and image is relative implicitly",
path: "posts/home",
content: "",
expected: "/posts/image.jpg",
},
{
name: "page in subdir and image is relative explicitly",
path: "posts/home",
content: "",
expected: "/posts/image.jpg",
},
{
name: "page in subdir and image is relative explicitly in subdir",
path: "posts/home",
content: "",
expected: "/posts/images/image.jpg",
},
{
name: "page in subdir and image is relative explicitly in parent",
path: "posts/home",
content: "",
expected: "/images/image.jpg",
},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
reader := text.NewReader([]byte(tc.content))
p := page{
name: tc.path,
lastUpdate: time.Time{},
ast: MarkdownConverter().Parser().Parse(reader),
content: (*Markdown)(&tc.content),
}
require.Equal(t, tc.expected, Banner(&p))
})
}
}