-
Notifications
You must be signed in to change notification settings - Fork 12
/
document_test.go
88 lines (82 loc) · 2.68 KB
/
document_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
package asciidocgo
import (
"reflect"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
var dm = new(Document).Monitor()
var dnm = new(Document)
var dnmini = NewDocument([]string{}, map[string]string{})
var notMonitoredError = &NotMonitoredError{"test"}
var monitorFNames = []string{"ReadTime", "ParseTime", "LoadTime", "RenderTime", "LoadRenderTime", "WriteTime", "TotalTime"}
func TestDocumentMonitor(t *testing.T) {
Convey("A Document can be monitored", t, func() {
Convey("By default, a Document is not monitored", func() {
So(dnm.IsMonitored(), ShouldBeFalse)
So(dnmini.IsMonitored(), ShouldBeFalse)
})
Convey("A monitored Document is monitored", func() {
So(dm.IsMonitored(), ShouldBeTrue)
})
})
Convey("A non-monitored Document should return error when accessing times", t, func() {
defer func() {
if x := recover(); x != nil {
So(x, ShouldBeNil)
}
}()
dtype := reflect.ValueOf(dnm)
for _, fname := range monitorFNames {
dfunc := dtype.MethodByName(fname)
ret := dfunc.Call([]reflect.Value{})
err := ret[1].Interface().(error)
So(err, ShouldNotBeNil)
So(err, ShouldHaveSameTypeAs, notMonitoredError)
So(err.Error(), ShouldContainSubstring, "not monitored")
}
})
Convey("A monitored empty Document should return 0 when accessing times", t, func() {
defer func() {
if x := recover(); x != nil {
So(x, ShouldBeNil)
}
}()
dtype := reflect.ValueOf(dm)
for _, fname := range monitorFNames {
dfunc := dtype.MethodByName(fname)
ret := dfunc.Call([]reflect.Value{})
time := ret[0].Int()
err := ret[1].Interface()
So(err, ShouldBeNil)
So(time, ShouldBeZeroValue)
}
})
Convey("Load time equals read time + parse time", t, func() {
loadTime, _ := dm.LoadTime()
readTime, _ := dm.ReadTime()
parseTime, _ := dm.ParseTime()
So(loadTime, ShouldEqual, readTime+parseTime)
})
Convey("LoadRender time equals load time + render time", t, func() {
loadRenderTime, _ := dm.LoadRenderTime()
loadTime, _ := dm.LoadTime()
renderTime, _ := dm.ReadTime()
So(loadRenderTime, ShouldEqual, loadTime+renderTime)
})
Convey("Total time equals LoadRender time + write time", t, func() {
totalTime, _ := dm.TotalTime()
loadRenderTime, _ := dm.LoadRenderTime()
writeTime, _ := dm.WriteTime()
So(totalTime, ShouldEqual, loadRenderTime+writeTime)
})
}
func TestDocumentInitialization(t *testing.T) {
Convey("A Document can be initialized", t, func() {
Convey("By default, a Document has no data, no options", func() {
So(&Document{}, ShouldNotBeNil)
})
Convey("A Document take an array of strings as data, and a map as options", func() {
So(NewDocument([]string{}, map[string]string{}), ShouldNotBeNil)
})
})
}