forked from emersion/go-vcard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoder_test.go
53 lines (45 loc) · 1.3 KB
/
encoder_test.go
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
package vcard
import (
"bytes"
"reflect"
"testing"
)
func TestEncoder(t *testing.T) {
var b bytes.Buffer
if err := NewEncoder(&b).Encode(testCard); err != nil {
t.Fatal("Expected no error when formatting card, got:", err)
}
card, err := NewDecoder(&b).Decode()
if err != nil {
t.Fatal("Expected no error when parsing formatted card, got:", err)
}
if !reflect.DeepEqual(card, testCard) {
t.Errorf("Invalid parsed card: expected \n%+v\n but got \n%+v", testCard, card)
}
}
func TestFormatLine_withGroup(t *testing.T) {
l := formatLine("FN", &Field{
Value: "Akiyama Mio",
Group: "item1",
})
expected := "item1.FN:Akiyama Mio"
if l != expected {
t.Errorf("Excpected formatted line with group to be %q, but got %q", expected, l)
}
}
var testValue = []struct {
v string
formatted string
}{
{"Hello World!", "Hello World!"},
{"this is a single value, with a comma encoded", "this is a single value\\, with a comma encoded"},
{"Mythical Manager\nHyjinx Software Division", "Mythical Manager\\nHyjinx Software Division"},
{"aa\\\nbb", "aa\\\\\\nbb"},
}
func TestFormatValue(t *testing.T) {
for _, test := range testValue {
if formatted := formatValue(test.v); formatted != test.formatted {
t.Errorf("formatValue(%q): expected %q, got %q", test.v, test.formatted, formatted)
}
}
}