aboutsummaryrefslogtreecommitdiffstats
path: root/worker/lib/foldermap_test.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-06-21 22:13:03 +0200
committerRobin Jarry <robin@jarry.cc>2023-06-22 10:55:25 +0200
commit822bd3620a456fefcdb828f2768c0677e4442f05 (patch)
treece304de9f3e88599b557c4c3576d2656a5831348 /worker/lib/foldermap_test.go
parent0f37a0ce2cdc07a090e33bbe53b1b67081cce741 (diff)
downloadaerc-822bd3620a456fefcdb828f2768c0677e4442f05.tar.gz
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>
Diffstat (limited to 'worker/lib/foldermap_test.go')
-rw-r--r--worker/lib/foldermap_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/worker/lib/foldermap_test.go b/worker/lib/foldermap_test.go
new file mode 100644
index 00000000..ec8b6d52
--- /dev/null
+++ b/worker/lib/foldermap_test.go
@@ -0,0 +1,54 @@
+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)
+ }
+ }
+}