Skip to content

Commit 049753a

Browse files
Add Tag tests
Signed-off-by: Chris Cummer <[email protected]>
1 parent 66a9f87 commit 049753a

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.14
55
require (
66
github.com/ericaro/frontmatter v0.0.0-20200210094738-46863cd917e2
77
github.com/go-git/go-git/v5 v5.0.0
8-
github.com/google/go-cmp v0.3.0
98
github.com/olebedev/config v0.0.0-20190528211619-364964f3a8e4
109
github.com/stretchr/testify v1.4.0
1110
gopkg.in/yaml.v2 v2.2.8 // indirect

til_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,55 @@ import (
66
"github.com/stretchr/testify/assert"
77
)
88

9+
/* -------------------- Tag -------------------- */
10+
11+
func Test_Tag_NewTag(t *testing.T) {
12+
actual := NewTag("ada", &Page{Title: "test"})
13+
14+
assert.IsType(t, &Tag{}, actual)
15+
assert.Equal(t, "ada", actual.Name)
16+
assert.Equal(t, "test", actual.Pages[0].Title)
17+
}
18+
19+
func Test_Tag_AddPage(t *testing.T) {
20+
tag := NewTag("ada", &Page{Title: "test"})
21+
tag.AddPage(&Page{Title: "zombies"})
22+
23+
assert.Equal(t, 2, len(tag.Pages))
24+
assert.Equal(t, "zombies", tag.Pages[1].Title)
25+
}
26+
27+
func Test_Tag_IsValid(t *testing.T) {
28+
tests := []struct {
29+
name string
30+
title string
31+
expected bool
32+
}{
33+
{
34+
name: "when invalid",
35+
title: "",
36+
expected: false,
37+
},
38+
{
39+
name: "when valid",
40+
title: "test",
41+
expected: true,
42+
},
43+
}
44+
45+
for _, tt := range tests {
46+
t.Run(tt.name, func(t *testing.T) {
47+
tag := NewTag(tt.title, &Page{})
48+
49+
actual := tag.IsValid()
50+
51+
assert.Equal(t, tt.expected, actual)
52+
})
53+
}
54+
}
55+
56+
/* -------------------- TagMap -------------------- */
57+
958
func Test_NewTagMap(t *testing.T) {
1059
tests := []struct {
1160
name string

0 commit comments

Comments
 (0)