aboutsummaryrefslogtreecommitdiffstats
path: root/worker/lib/foldermap_test.go
blob: ec8b6d5237e412090461fc6d8fd7ad4498dbd64c (plain) (blame)
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
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)
		}
	}
}