| 1 |
package imap |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
"time" |
| 6 |
|
| 7 |
"git.sr.ht/~rjarry/aerc/worker/types" |
| 8 |
) |
| 9 |
|
| 10 |
func Test_translateSearch_ByDate(t *testing.T) { |
| 11 |
tests := []struct { |
| 12 |
name string |
| 13 |
StartDate time.Time |
| 14 |
EndDate time.Time |
| 15 |
}{ |
| 16 |
{ |
| 17 |
name: "Only StartDate", |
| 18 |
StartDate: time.Now(), |
| 19 |
}, |
| 20 |
{ |
| 21 |
name: "Only EndDate", |
| 22 |
EndDate: time.Now(), |
| 23 |
}, |
| 24 |
{ |
| 25 |
name: "Both dates", |
| 26 |
StartDate: time.Now(), |
| 27 |
EndDate: time.Now(), |
| 28 |
}, |
| 29 |
} |
| 30 |
for _, test := range tests { |
| 31 |
crit := &types.SearchCriteria{ |
| 32 |
Match: &types.SearchCriteriaPart{ |
| 33 |
StartDate: test.StartDate, |
| 34 |
EndDate: test.EndDate, |
| 35 |
}, |
| 36 |
} |
| 37 |
sc := translateSearch(crit) |
| 38 |
if sc.SentSince != test.StartDate { |
| 39 |
t.Errorf("test '%s' failed: got: '%s', but wanted: '%s'", |
| 40 |
test.name, sc.SentSince, test.StartDate) |
| 41 |
} |
| 42 |
if sc.SentBefore != test.EndDate { |
| 43 |
t.Errorf("test '%s' failed: got: '%s', but wanted: '%s'", |
| 44 |
test.name, sc.SentBefore, test.EndDate) |
| 45 |
} |
| 46 |
} |
| 47 |
} |