forked from mna/trofaf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_test.go
More file actions
78 lines (72 loc) · 1.31 KB
/
gen_test.go
File metadata and controls
78 lines (72 loc) · 1.31 KB
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
package main
import (
"bytes"
"io/ioutil"
"log"
"sort"
"testing"
"time"
)
func mustParse(s string) time.Time {
t, err := time.Parse("2006-01-02", s)
if err != nil {
panic(err)
}
return t
}
func TestSort(t *testing.T) {
ps := make(sortablePosts, 5)
ps[0] = &LongPost{
ShortPost: &ShortPost{
Title: "a",
PubTime: mustParse("2012-01-07"),
},
}
ps[1] = &LongPost{
ShortPost: &ShortPost{
Title: "b",
PubTime: mustParse("2012-04-22"),
},
}
ps[2] = &LongPost{
ShortPost: &ShortPost{
Title: "c",
PubTime: mustParse("2012-01-01"),
},
}
ps[3] = &LongPost{
ShortPost: &ShortPost{
Title: "d",
PubTime: mustParse("2011-11-30"),
},
}
ps[4] = &LongPost{
ShortPost: &ShortPost{
Title: "e",
PubTime: mustParse("2012-12-01"),
},
}
sort.Sort(ps)
buf := bytes.NewBuffer(nil)
for _, p := range ps {
buf.WriteString(p.Title)
}
if buf.String() != "dcabe" {
t.Errorf("expected 'dcabe', got %s", buf.String())
}
}
func BenchmarkGenerateSite(b *testing.B) {
b.StopTimer()
log.SetOutput(ioutil.Discard)
Options.RecentPostsCount = 5
PublicDir = "./examples/amber/public"
PostsDir = "./examples/amber/posts"
TemplatesDir = "./examples/amber/templates"
b.StartTimer()
for i := 0; i < b.N; i++ {
err := generateSite()
if err != nil {
b.Fatal(err)
}
}
}