-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathfilter_parser_test.go
178 lines (148 loc) · 5.81 KB
/
filter_parser_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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package main
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
// Test ...
func TestFilter(t *testing.T) {
assert.Equal(t, nil, Filter(""), "they should be equal")
}
func TestPriorityFilter(t *testing.T) {
assert.Equal(t, StringExpr{literal: "p1"}, Filter("p1"), "they should be equal")
}
func TestProjectFilter(t *testing.T) {
assert.Equal(t,
ProjectExpr{
isAll: false,
name: "Work",
},
Filter("#Work"), "they should be equal")
assert.Equal(t,
ProjectExpr{
isAll: true,
name: "Work",
},
Filter("##Work"), "they should be equal")
}
func TestLabelFilter(t *testing.T) {
assert.Equal(t,
LabelExpr{
name: "Test",
},
Filter("@Test"), "they should be equal")
assert.Equal(t,
LabelExpr{
name: "",
},
Filter("no labels"), "they should be equal")
}
func TestBoolInfixFilter(t *testing.T) {
assert.Equal(t,
BoolInfixOpExpr{
left: StringExpr{literal: "p1"},
operator: '|',
right: StringExpr{literal: "p2"},
},
Filter("p1 | p2"), "they should be equal")
assert.Equal(t,
BoolInfixOpExpr{
left: StringExpr{literal: "p1"},
operator: '&',
right: StringExpr{literal: "p2"},
},
Filter("p1 & p2"), "they should be equal")
assert.Equal(t,
BoolInfixOpExpr{
left: StringExpr{literal: "p1"},
operator: '&',
right: BoolInfixOpExpr{
left: StringExpr{literal: "p2"},
operator: '|',
right: StringExpr{literal: "p3"},
},
},
Filter("p1 & (p2 | p3 )"), "they should be equal")
}
func setNow(t time.Time) {
now = func() time.Time { return t }
}
func TestDateTimeFilter(t *testing.T) {
timeNow := time.Date(2017, time.January, 2, 1, 0, 0, 0, testTimeZone)
setNow(timeNow)
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(2017, time.October, 5, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("10/5/2017"), "they should be equal")
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(timeNow.Year(), time.January, 3, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("Jan 3"), "they should be equal")
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(timeNow.Year(), time.August, 8, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("8 August"), "they should be equal")
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(2020, time.February, 10, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("10 Feb 2020"), "they should be equal")
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(timeNow.Year(), time.May, 16, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("16/05"), "they should be equal")
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 16, 0, 0, 0, testTimeZone), allDay: false},
Filter("16:00"), "they should be equal")
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 16, 10, 3, 0, testTimeZone), allDay: false},
Filter("16:10:03"), "they should be equal")
//assert.Equal(t,
// DateExpr{operation: DUE_ON, datetime: time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 15, 0, 0, 0, testTimeZone), allDay: false},
// Filter("3pm"), "they should be equal")
//
//assert.Equal(t,
// DateExpr{operation: DUE_ON, datetime: time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 7, 0, 0, 0, testTimeZone), allDay: false},
// Filter("7am"), "they should be equal")
//
//assert.Equal(t,
// DateExpr{operation: DUE_ON, datetime: time.Date(2020, time.February, 10, 15, 0, 0, 0, testTimeZone), allDay: false},
// Filter("10 Feb 2020 3pm"), "they should be equal")
//
//assert.Equal(t,
// DateExpr{operation: DUE_ON, datetime: time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 7, 0, 0, 0, testTimeZone), allDay: false},
// Filter("7am"), "they should be equal")
}
func TestSpecialDateTimeFilter(t *testing.T) {
timeNow := time.Date(2017, time.January, 1, 1, 0, 0, 0, testTimeZone)
setNow(timeNow)
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(2017, time.January, 1, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("today"), "they should be equal")
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(2017, time.January, 1, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("tod"), "they should be equal")
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(2017, time.January, 1, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("Today"), "they should be equal")
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(2017, time.January, 2, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("tomorrow"), "they should be equal")
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(2017, time.January, 2, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("tom"), "they should be equal")
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(2016, time.December, 31, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("yesterday"), "they should be equal")
}
func TestDateTimeElapsedFilter(t *testing.T) {
timeNow := time.Date(2017, time.January, 2, 18, 0, 0, 0, testTimeZone)
setNow(timeNow)
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day()+1, 16, 0, 0, 0, testTimeZone), allDay: false},
Filter("16:00"), "they should be equal")
timeNow = time.Date(2017, time.May, 16, 23, 59, 59, 0, testTimeZone)
setNow(timeNow)
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(timeNow.Year(), time.May, 16, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("16/05"), "they should be equal")
timeNow = time.Date(2017, time.May, 17, 0, 0, 0, 0, testTimeZone)
setNow(timeNow)
assert.Equal(t,
DateExpr{operation: DUE_ON, datetime: time.Date(timeNow.Year()+1, time.May, 16, 0, 0, 0, 0, testTimeZone), allDay: true},
Filter("16/05"), "they should be equal")
}