forked from emersion/go-vcard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
emersion#5 - adds support for properties with multiple values
- Loading branch information
1 parent
37831e9
commit a0e42ac
Showing
3 changed files
with
127 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,66 @@ var testCardGoogle = Card{ | |
}, | ||
} | ||
|
||
var testCardGoogleMultiEmail = Card{ | ||
"VERSION": []*Field{{Value: "3.0"}}, | ||
"N": []*Field{{Value: "Bloggs;Joe;;;"}}, | ||
"FN": []*Field{{Value: "Joe Bloggs"}}, | ||
"EMAIL": []*Field{{ | ||
Value: "[email protected]", | ||
Params: Params{"TYPE": {"INTERNET", "HOME"}}, | ||
},{ | ||
Value: "[email protected]", | ||
Params: Params{"TYPE": {"INTERNET", "HOME"}}, | ||
}}, | ||
"TEL": []*Field{{ | ||
Value: "+44 20 1234 5678", | ||
Params: Params{"TYPE": {"CELL"}}, | ||
}}, | ||
"ADR": []*Field{{ | ||
Value: ";;1 Trafalgar Square;London;;WC2N;United Kingdom", | ||
Params: Params{"TYPE": {"HOME"}}, | ||
}}, | ||
"URL": []*Field{ | ||
{Value: "http\\://joebloggs.com", Group: "item1"}, | ||
{Value: "http\\://twitter.com/test", Group: "item2"}, | ||
}, | ||
"X-SKYPE": []*Field{{Value: "joe.bloggs"}}, | ||
"X-ABLABEL": []*Field{ | ||
{Value: "_$!<HomePage>!$_", Group: "item1"}, | ||
{Value: "Twitter", Group: "item2"}, | ||
}, | ||
} | ||
|
||
var testCardGoogleMultiEmailComma = Card{ | ||
"VERSION": []*Field{{Value: "3.0"}}, | ||
"N": []*Field{{Value: "Bloggs;Joe;;;"}}, | ||
"FN": []*Field{{Value: "Joe Bloggs"}}, | ||
"EMAIL": []*Field{{ | ||
Value: "[email protected]", | ||
Params: Params{"TYPE": {"INTERNET", "HOME"}}, | ||
},{ | ||
Value: `joe@joebloggs,com`, | ||
Params: Params{"TYPE": {"INTERNET", "HOME"}}, | ||
}}, | ||
"TEL": []*Field{{ | ||
Value: "+44 20 1234 5678", | ||
Params: Params{"TYPE": {"CELL"}}, | ||
}}, | ||
"ADR": []*Field{{ | ||
Value: ";;1 Trafalgar Square;London;;WC2N;United Kingdom", | ||
Params: Params{"TYPE": {"HOME"}}, | ||
}}, | ||
"URL": []*Field{ | ||
{Value: "http\\://joebloggs.com", Group: "item1"}, | ||
{Value: "http\\://twitter.com/test", Group: "item2"}, | ||
}, | ||
"X-SKYPE": []*Field{{Value: "joe.bloggs"}}, | ||
"X-ABLABEL": []*Field{ | ||
{Value: "_$!<HomePage>!$_", Group: "item1"}, | ||
{Value: "Twitter", Group: "item2"}, | ||
}, | ||
} | ||
|
||
var testCardApple = Card{ | ||
"VERSION": []*Field{{Value: "3.0"}}, | ||
"N": []*Field{{Value: "Bloggs;Joe;;;"}}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,36 @@ item2.URL:http\://twitter.com/test | |
item2.X-ABLabel:Twitter | ||
END:VCARD` | ||
|
||
// Google Contacts (15 November 2012) | ||
var testCardGoogleMultiValueString = `BEGIN:VCARD | ||
VERSION:3.0 | ||
N:Bloggs;Joe;;; | ||
FN:Joe Bloggs | ||
EMAIL;TYPE=INTERNET;TYPE=HOME:[email protected], [email protected] | ||
TEL;TYPE=CELL:+44 20 1234 5678 | ||
ADR;TYPE=HOME:;;1 Trafalgar Square;London;;WC2N;United Kingdom | ||
item1.URL:http\://joebloggs.com | ||
item1.X-ABLabel:_$!<HomePage>!$_ | ||
X-SKYPE:joe.bloggs | ||
item2.URL:http\://twitter.com/test | ||
item2.X-ABLabel:Twitter | ||
END:VCARD` | ||
|
||
var testCardGoogleMultiValueWithCommaString = `BEGIN:VCARD | ||
VERSION:3.0 | ||
N:Bloggs;Joe;;; | ||
FN:Joe Bloggs | ||
EMAIL;TYPE=INTERNET;TYPE=HOME:[email protected], joe@joebloggs\,com | ||
TEL;TYPE=CELL:+44 20 1234 5678 | ||
ADR;TYPE=HOME:;;1 Trafalgar Square;London;;WC2N;United Kingdom | ||
item1.URL:http\://joebloggs.com | ||
item1.X-ABLabel:_$!<HomePage>!$_ | ||
X-SKYPE:joe.bloggs | ||
item2.URL:http\://twitter.com/test | ||
item2.X-ABLabel:Twitter | ||
END:VCARD` | ||
|
||
|
||
// Apple Contacts (version 7.1) | ||
var testCardAppleString = `BEGIN:VCARD | ||
VERSION:3.0 | ||
|
@@ -81,6 +111,8 @@ var decoderTests = []struct { | |
{testCardGoogleString, testCardGoogle}, | ||
{testCardAppleString, testCardApple}, | ||
{testCardLineFoldingString, testCardLineFolding}, | ||
{testCardGoogleMultiValueString, testCardGoogleMultiEmail}, | ||
{testCardGoogleMultiValueWithCommaString, testCardGoogleMultiEmailComma}, | ||
} | ||
|
||
func TestDecoder(t *testing.T) { | ||
|
@@ -134,9 +166,9 @@ func TestParseLine_escaped(t *testing.T) { | |
expectedKey := "NOTE" | ||
expectedValue := "Mythical Manager\nHyjinx Software Division\nBabsCo, Inc.\n" | ||
|
||
if key, field, err := parseLine(l); err != nil { | ||
if key, fields, err := parseLine(l); err != nil { | ||
t.Fatal("Expected no error while parsing line, got:", err) | ||
} else if key != expectedKey || field.Value != expectedValue { | ||
t.Errorf("parseLine(%q): expected (%q, %q), got (%q, %q)", l, expectedKey, expectedValue, key, field.Value) | ||
} else if key != expectedKey || fields[0].Value != expectedValue { | ||
t.Errorf("parseLine(%q): expected (%q, %q), got (%q, %q)", l, expectedKey, expectedValue, key, fields[0].Value) | ||
} | ||
} |