forked from rjhorniii/ical2org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ical2org_test.go
155 lines (131 loc) · 3.81 KB
/
ical2org_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
package main
import (
// "fmt"
"io/ioutil"
"os"
// "github.com/rjhorniii/ics-golang"
// "github.com/davecgh/go-spew/spew"
"testing"
//"github.com/davecgh/go-spew/spew"
)
func TestMultiple(t *testing.T) {
a := args{outfile: "tests/xx91596.org", count: true, args: []string{"tests/xx91596.ics", "tests/test-vcal-3.vcs", "tests/wg-29.ics"}}
process(a)
// order is unpredicatable so no comparison
}
func TestX91596(t *testing.T) {
a := args{outfile: "tests/xx91596.org", args: []string{"tests/xx91596.ics"}}
process(a)
// compare with org-correct output
if compareFiles(a.outfile, "tests/xx91596.org-correct", t) == false {
t.Fail()
}
}
func TestDeadline(t *testing.T) {
a := args{outfile: "tests/xx91596.org", dead: true, args: []string{"tests/xx91596.ics"}}
process(a)
// compare with org-dead
if compareFiles(a.outfile, "tests/xx91596.org-dead", t) == false {
t.Fail()
}
}
func TestSchedule(t *testing.T) {
a := args{outfile: "tests/xx91596.org", sched: true, args: []string{"tests/xx91596.ics"}}
process(a)
// compare with org-scheduled
if compareFiles(a.outfile, "tests/xx91596.org-scheduled", t) == false {
t.Fail()
}
}
func TestActive(t *testing.T) {
a := args{outfile: "tests/xx91596.org", active: true, args: []string{"tests/xx91596.ics"}}
process(a)
// compare with org-correct
if compareFiles(a.outfile, "tests/xx91596.org-correct", t) == false {
t.Fail()
}
}
func TestInactive(t *testing.T) {
a := args{outfile: "tests/xx91596.org", inactive: true, args: []string{"tests/xx91596.ics"}}
process(a)
// compare with org-inactive
if compareFiles(a.outfile, "tests/xx91596.org-inactive", t) == false {
t.Fail()
}
}
func TestDupflag(t *testing.T) {
a := args{outfile: "tests/xx91596.org", dupflag: true, args: []string{"tests/xx91596.ics", "tests/xx91596a.ics"}}
process(a)
// compare with org-correct
if compareFiles(a.outfile, "tests/xx91596.org-correct", t) == false {
t.Fail()
}
}
func TestDual(t *testing.T) {
a := args{outfile: "tests/xx91596.org", count: true, args: []string{"tests/xx91596.ics", "tests/xx91596a.ics"}}
process(a)
// compare with org-dual
if compareFiles(a.outfile, "tests/xx91596.org-dual", t) == false {
t.FailNow()
}
}
func TestAfterDate(t *testing.T) {
a := args{outfile: "tests/xx91596.org", afterfile: "2030-01-01", args: []string{"tests/xx91596.ics"}}
process(a)
// compare with empty
finfo, err := os.Stat(a.outfile)
if err != nil {
t.Fail()
}
if finfo.Size() != int64(0) {
t.Fail()
}
}
func TestAfterDuration(t *testing.T) {
// remove tests/xx91596.org
a := args{appfile: "tests/xx91596.org", afterfile: "-36h", args: []string{"tests/xx91596.ics"}}
err := os.Remove(a.appfile)
if !os.IsNotExist(err) && err != nil {
t.Error(err)
}
process(a)
// compare with org-correct
if compareFiles(a.appfile, "tests/xx91596.org-correct", t) == false {
t.Fail()
}
process(a)
// compare with org-dual
if compareFiles(a.appfile, "tests/xx91596.org-dual", t) == false {
t.Fail()
}
}
func TestLabel(t *testing.T) {
a := args{outfile: "tests/xx91596.org", label: "test-label", args: []string{"tests/xx91596.ics"}}
process(a)
// compare with org-inactive
if compareFiles(a.outfile, "tests/xx91596.org-labeled", t) == false {
t.Fail()
}
}
//
// file comparison function. This assumes files are small and memory is large.
// It reads the whole files into memory and then compares.
func compareFiles(fname1 string, fname2 string, t *testing.T) bool {
// per comment, better to not read an entire file into memory
// this is simply a trivial example.
f1, err1 := ioutil.ReadFile(fname1)
if err1 != nil {
t.Error(err1)
}
f2, err2 := ioutil.ReadFile(fname2)
if err2 != nil {
t.Error(err2)
}
str1 := string(f1)
str2 := string(f2)
if str1 != str2 {
// spew.Printf("test file: %v \n\ncomparison file %v\n", str1, str2)
return false
}
return true
}