use of ezvcard.VCardVersion in project ez-vcard by mangstadt.
the class VCardReaderTest method label_parameters.
/**
* Escaped newlines should ONLY be unescaped in LABEL parameters of ADR
* properties.
*/
@Test
public void label_parameters() throws Exception {
for (VCardVersion version : VCardVersion.values()) {
// @formatter:off
VCardAsserter asserter = read("BEGIN:VCARD\r\n" + "VERSION:" + version.getVersion() + "\r\n" + "ADR;LABEL=one\\ntwo;PARAM=one\\ntwo:\r\n" + "PROP;LABEL=one\\ntwo;PARAM=one\\ntwo:\r\n" + "END:VCARD\r\n");
asserter.next(version);
asserter.address().label("one" + NEWLINE + "two").param("PARAM", "one\\ntwo").noMore();
asserter.rawProperty("PROP").param("LABEL", "one\\ntwo").param("PARAM", "one\\ntwo").value("").noMore();
asserter.done();
// @formatter:on
}
}
use of ezvcard.VCardVersion in project ez-vcard by mangstadt.
the class VCardReaderTest method extended_properties.
@Test
public void extended_properties() throws Exception {
for (VCardVersion version : VCardVersion.values()) {
// @formatter:off
String str = "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "X-LUCKY-NUM:24\r\n" + "X-GENDER:ma\\,le\r\n" + "X-LUCKY-NUM:22\r\n" + "END:VCARD\r\n";
// @formatter:on
VCardReader reader = new VCardReader(str);
reader.registerScribe(new LuckyNumScribe());
VCard vcard = reader.readNext();
assertVersion(version, vcard);
assertPropertyCount(3, vcard);
// read a type that has a type class
List<LuckyNumProperty> luckyNumTypes = vcard.getProperties(LuckyNumProperty.class);
assertEquals(2, luckyNumTypes.size());
assertEquals(24, luckyNumTypes.get(0).luckyNum);
assertEquals(22, luckyNumTypes.get(1).luckyNum);
assertTrue(vcard.getExtendedProperties("X-LUCKY-NUM").isEmpty());
// read a type without a type class
List<RawProperty> genderTypes = vcard.getExtendedProperties("X-GENDER");
assertEquals(1, genderTypes.size());
// raw type values are not unescaped
assertEquals("ma\\,le", genderTypes.get(0).getValue());
assertParseWarnings(reader);
assertNoMoreVCards(reader);
}
}
use of ezvcard.VCardVersion in project ez-vcard by mangstadt.
the class VCardReaderTest method cannotParseException.
@Test
public void cannotParseException() throws Exception {
for (VCardVersion version : VCardVersion.values()) {
// @formatter:off
String str = "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "group.CANNOTPARSE;PARAM=value;VALUE=text:value\r\n" + "X-FOO:value\r\n" + "END:VCARD\r\n";
VCardReader reader = new VCardReader(str);
reader.registerScribe(new CannotParseScribe());
VCardAsserter asserter = new VCardAsserter(reader);
asserter.next(version);
asserter.rawProperty("X-FOO").value("value").noMore();
asserter.rawProperty("CANNOTPARSE").group("group").param("PARAM", "value").dataType(VCardDataType.TEXT).value("value").noMore();
asserter.warnings(25);
asserter.done();
// @formatter:on
}
}
use of ezvcard.VCardVersion in project ez-vcard by mangstadt.
the class VCardReaderTest method type_parameter_enclosed_in_double_quotes.
/**
* Account for an error in the 4.0 specification, which places multi-valued
* TYPE parameters in double quotes.
*/
@Test
public void type_parameter_enclosed_in_double_quotes() throws Exception {
VCardVersion version = V2_1;
{
// @formatter:off
VCardAsserter asserter = read("BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "PROP;TYPE=\"one,two,,three\";FOO=\"four,five,,six\":\r\n" + "END:VCARD\r\n");
asserter.next(version);
asserter.rawProperty("PROP").param("TYPE", "\"one,two,,three\"").param("FOO", "\"four,five,,six\"").value("").noMore();
asserter.done();
// @formatter:on
}
for (VCardVersion v : each(V3_0, V4_0)) {
// @formatter:off
VCardAsserter asserter = read("BEGIN:VCARD\r\n" + "VERSION:" + v + "\r\n" + "PROP;TYPE=\"one,two,,three\";FOO=\"four,five,,six\":\r\n" + "END:VCARD\r\n");
asserter.next(v);
asserter.rawProperty("PROP").param("TYPE", "one", "two", "", "three").param("FOO", "four,five,,six").value("").noMore();
asserter.done();
// @formatter:on
}
}
use of ezvcard.VCardVersion in project ez-vcard by mangstadt.
the class VCardReaderTest method property_warning.
@Test
public void property_warning() throws Exception {
for (VCardVersion version : VCardVersion.values()) {
// @formatter:off
String str = "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "WARNINGS:foo\r\n" + "END:VCARD\r\n";
// @formatter:on
VCardReader reader = new VCardReader(str);
reader.registerScribe(new WarningsScribe());
VCard vcard = reader.readNext();
assertVersion(version, vcard);
assertPropertyCount(1, vcard);
assertParseWarnings(reader, (Integer) null);
assertNoMoreVCards(reader);
}
}
Aggregations