-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewlist_test.go
162 lines (140 loc) · 3.38 KB
/
viewlist_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
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
/*
Copyright © 2019, 2024 M.Watermann, 10247 Berlin, Germany
All rights reserved
EMail : <support@mwat.de>
*/
package nele
import (
"io"
"os"
"testing"
"time"
)
func Test_NewViewList(t *testing.T) {
prep4Tests()
vl1 := make(TViewList, 16)
tests := []struct {
name string
want *TViewList
}{
{"1", &vl1},
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got, _ := NewViewList(); got.equals(tt.want) {
t.Errorf("%q: NewViewList() = \n%v\n>>> want >>>\n%v",
tt.name, got, tt.want)
}
})
}
} // Test_NewViewList()
func Test_TViewList_add(t *testing.T) {
prep4Tests()
vw1, _ := NewView("index")
vl1, _ := NewViewList()
rl1, _ := NewViewList()
vl1.add(vw1)
tests := []struct {
name string
vl *TViewList
view *TView
want *TViewList
}{
{" 1", vl1, vw1, rl1},
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.vl.add(tt.view); !got.equals(tt.want) {
t.Errorf("TViewList.add() = %v, want %v", got, tt.want)
}
})
}
} // Test_TViewList_add()
func Test_TViewList_equals(t *testing.T) {
prep4Tests()
vl0, _ := NewViewList()
tv1, _ := NewView("index")
vl1, _ := NewViewList()
vl1.add(tv1)
tv2, _ := NewView("503")
vl2, _ := NewViewList()
vl2.add(tv2)
tests := []struct {
name string
mList *TViewList
oList *TViewList
want bool
}{
// since all viewlists contain all views,
// all tests will return true ...
{"0", vl0, vl0, true},
{"1", vl0, vl1, true},
{"2", vl0, vl2, true},
{"3", vl2, vl2, true},
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.mList.equals(tt.oList); got != tt.want {
t.Errorf("%q: TViewList.equals() = %v, want %v",
tt.name, got, tt.want)
}
})
}
} // Test_TViewList_equals()
func TestTViewList_render(t *testing.T) {
prepareTestFiles()
vname1, vname2 := "index", "article"
vw1, _ := NewView(vname1)
vw2, _ := NewView(vname2)
vl1, _ := NewViewList()
vl1.add(vw1).
add(vw2)
id1 := time2id(time.Date(2019, 3, 19, 0, 0, 0, 0, time.Local))
p1 := NewPosting(id1, "ViewList_render: Oh dear! This is a first posting.")
id2 := time2id(time.Date(2019, 5, 4, 0, 0, 0, 0, time.Local))
p2 := NewPosting(id2, "ViewList_render: Hi there! This is another posting.")
id3 := time2id(time.Date(2019, 4, 14, 0, 0, 0, 0, time.Local))
p3 := NewPosting(id3, "ViewList_render: Oh dear! This is a single posting.")
pl1 := NewPostList().
Add(p1).
Add(p2)
dl1 := NewTemplateData().
Set("Lang", "en").
Set("Title", "this is the index title").
Set("Postings", *pl1)
pl2 := NewPostList().
Add(p3)
dl2 := NewTemplateData().
Set("Lang", "en").
Set("Title", "this is the article title").
Set("Postings", *pl2)
type tArgs struct {
aName string
aData *TemplateData
}
tests := []struct {
name string
vl *TViewList
args tArgs
aWriter io.Writer
wantErr bool
}{
{" 1", vl1, tArgs{vname1, dl1}, os.Stdout, false},
{" 2", vl1, tArgs{vname2, dl2}, os.Stdout, false},
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.vl.render(tt.args.aName, tt.aWriter, tt.args.aData)
if (err != nil) != tt.wantErr {
t.Errorf("%q: TViewList.render() error = %v, wantErr %v",
tt.name, err, tt.wantErr)
return
}
})
}
} // TestTViewList_render()
/* _EoF_ */