Skip to content

Commit dcd0286

Browse files
committed
Add complex filter tests
1 parent d4c7322 commit dcd0286

File tree

1 file changed

+48
-14
lines changed

1 file changed

+48
-14
lines changed

klog/service/filter/filter_test.go

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,27 @@ import (
1212
func sampleRecordsForQuerying() []klog.Record {
1313
rs, _, err := parser.NewSerialParser().Parse(`
1414
1999-12-30
15-
Hello World #foo
15+
Hello World #foo #first
1616
1717
1999-12-31
18-
5h #bar [300]
18+
5h #bar [300]
1919
2020
2000-01-01
21-
#foo
22-
1:30-1:45 [14]
23-
6h #bar [360]
24-
-30m [-30]
21+
#foo #third
22+
1:30-1:45 [15]
23+
6h #bar [360]
24+
-30m [-30]
2525
2626
2000-01-02
27-
#foo
28-
7h [420]
27+
#foo #fourth
28+
7h #xyz [420]
2929
3030
2000-01-03
31-
#foo=a
32-
4h #bar=1 [240]
33-
3h #bar=2 [180]
34-
12:00-? [0]
31+
#foo=a #fifth
32+
12:00-16:00 [240]
33+
#bar=1
34+
3h #bar=2 [180]
35+
12:00-? [0]
3536
`)
3637
if err != nil {
3738
panic(err)
@@ -166,7 +167,7 @@ func TestQueryWithEntryTypes(t *testing.T) {
166167
{klog.Ɀ_Date_(1999, 12, 31), []int{300}},
167168
{klog.Ɀ_Date_(2000, 1, 1), []int{360, -30}},
168169
{klog.Ɀ_Date_(2000, 1, 2), []int{420}},
169-
{klog.Ɀ_Date_(2000, 1, 3), []int{240, 180}},
170+
{klog.Ɀ_Date_(2000, 1, 3), []int{180}},
170171
}, rs)
171172
}
172173
{
@@ -183,14 +184,15 @@ func TestQueryWithEntryTypes(t *testing.T) {
183184
{klog.Ɀ_Date_(1999, 12, 31), []int{300}},
184185
{klog.Ɀ_Date_(2000, 1, 1), []int{360}},
185186
{klog.Ɀ_Date_(2000, 1, 2), []int{420}},
186-
{klog.Ɀ_Date_(2000, 1, 3), []int{240, 180}},
187+
{klog.Ɀ_Date_(2000, 1, 3), []int{180}},
187188
}, rs)
188189
}
189190
{
190191
rs, hprws := Filter(IsEntryType{ENTRY_TYPE_RANGE}, sampleRecordsForQuerying())
191192
assert.True(t, hprws)
192193
assertResult(t, []expect{
193194
{klog.Ɀ_Date_(2000, 1, 1), []int{15}},
195+
{klog.Ɀ_Date_(2000, 1, 3), []int{240}},
194196
}, rs)
195197
}
196198
{
@@ -201,3 +203,35 @@ func TestQueryWithEntryTypes(t *testing.T) {
201203
}, rs)
202204
}
203205
}
206+
207+
func TestComplexFilterQueries(t *testing.T) {
208+
{
209+
rs, hprws := Filter(Or{[]Predicate{
210+
IsInDateRange{From: klog.Ɀ_Date_(2000, 1, 2), To: nil},
211+
HasTag{klog.NewTagOrPanic("first", "")},
212+
And{[]Predicate{
213+
Not{HasTag{klog.NewTagOrPanic("something", "1")}},
214+
IsEntryType{ENTRY_TYPE_RANGE},
215+
}},
216+
}}, sampleRecordsForQuerying())
217+
assert.True(t, hprws)
218+
assertResult(t, []expect{
219+
{klog.Ɀ_Date_(1999, 12, 30), []int{}},
220+
{klog.Ɀ_Date_(2000, 1, 1), []int{15}},
221+
{klog.Ɀ_Date_(2000, 1, 2), []int{420}},
222+
{klog.Ɀ_Date_(2000, 1, 3), []int{240, 180, 0}},
223+
}, rs)
224+
}
225+
{
226+
rs, hprws := Filter(And{[]Predicate{
227+
IsInDateRange{From: klog.Ɀ_Date_(2000, 1, 1), To: klog.Ɀ_Date_(2000, 1, 3)},
228+
HasTag{klog.NewTagOrPanic("bar", "")},
229+
Not{HasTag{klog.NewTagOrPanic("third", "")}},
230+
IsEntryType{ENTRY_TYPE_RANGE},
231+
}}, sampleRecordsForQuerying())
232+
assert.True(t, hprws)
233+
assertResult(t, []expect{
234+
{klog.Ɀ_Date_(2000, 1, 3), []int{240}},
235+
}, rs)
236+
}
237+
}

0 commit comments

Comments
 (0)