1
0
Fork 0
mirror of https://git.sr.ht/~rjarry/aerc synced 2025-02-22 23:23:57 +01:00
aerc/worker/lib/foldermap_test.go
Koni Marti 822bd3620a lib: parse query-map and folder-map files
Combine the query-map and folder-map parsing functionality. Add tests.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
2023-06-22 10:55:25 +02:00

54 lines
1 KiB
Go

package lib_test
import (
"reflect"
"strings"
"testing"
"git.sr.ht/~rjarry/aerc/worker/lib"
)
func TestFolderMap(t *testing.T) {
text := `#this is comment
Sent = [Gmail]/Sent
# a comment between entries
Spam=[Gmail]/Spam # this is comment after the values
`
fmap, order, err := lib.ParseFolderMap(strings.NewReader(text))
if err != nil {
t.Errorf("parsing failed: %v", err)
}
want_map := map[string]string{
"Sent": "[Gmail]/Sent",
"Spam": "[Gmail]/Spam",
}
want_order := []string{"Sent", "Spam"}
if !reflect.DeepEqual(order, want_order) {
t.Errorf("order is not correct; want: %v, got: %v",
want_order, order)
}
if !reflect.DeepEqual(fmap, want_map) {
t.Errorf("map is not correct; want: %v, got: %v",
want_map, fmap)
}
}
func TestFolderMap_ExpectFails(t *testing.T) {
tests := []string{
`key = `,
` = value`,
` = `,
`key = #value`,
}
for _, text := range tests {
_, _, err := lib.ParseFolderMap(strings.NewReader(text))
if err == nil {
t.Errorf("expected to fail, but it did not: %v", text)
}
}
}