use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectWriterTest method property_value_with_newlines.
/**
* When the property value contains newlines, it should encode in
* quoted-printable in old style, and escape newlines in new style.
*/
@Test
public void property_value_with_newlines() throws Exception {
SyntaxStyle style = SyntaxStyle.OLD;
{
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
writer.getFoldedLineWriter().setLineLength(null);
VObjectParameters parameters = new VObjectParameters();
VObjectParameters expectedParams = new VObjectParameters(parameters);
writer.writeProperty(null, "PROP", parameters, "one\r\ntwo");
// nothing should be added to the parameters object that was passed into the method
assertEquals(expectedParams, parameters);
parameters = new VObjectParameters();
expectedParams = new VObjectParameters(parameters);
writer.writeProperty(null, "PROP", parameters, "one\rtwo");
assertEquals(expectedParams, parameters);
parameters = new VObjectParameters();
expectedParams = new VObjectParameters(parameters);
writer.writeProperty(null, "PROP", parameters, "one\ntwo");
assertEquals(expectedParams, parameters);
parameters = new VObjectParameters();
parameters.put(null, "QUOTED-PRINTABLE");
expectedParams = new VObjectParameters(parameters);
writer.writeProperty(null, "PROP", parameters, "one\r\ntwo");
assertEquals(expectedParams, parameters);
parameters = new VObjectParameters();
parameters.put("ENCODING", "QUOTED-PRINTABLE");
expectedParams = new VObjectParameters(parameters);
writer.writeProperty(null, "PROP", parameters, "one\r\ntwo");
assertEquals(expectedParams, parameters);
parameters = new VObjectParameters();
parameters.put("CHARSET", "UTF-16");
expectedParams = new VObjectParameters(parameters);
writer.writeProperty(null, "PROP", parameters, "one\r\ntwo");
assertEquals(expectedParams, parameters);
String actual = sw.toString();
// @formatter:off
String expected = "PROP;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:one=0D=0Atwo\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:one=0Dtwo\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:one=0Atwo\r\n" + "PROP;QUOTED-PRINTABLE;CHARSET=UTF-8:one=0D=0Atwo\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:one=0D=0Atwo\r\n" + "PROP;CHARSET=UTF-16;ENCODING=QUOTED-PRINTABLE:=FE=FF=00o=00n=00e=00=0D=00=0A=00t=00w=00o\r\n";
// @formatter:on
assertEquals(expected, actual);
}
style = SyntaxStyle.NEW;
{
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
writer.writeProperty(null, "PROP", new VObjectParameters(), "one\r\ntwo");
writer.writeProperty(null, "PROP", new VObjectParameters(), "one\rtwo");
writer.writeProperty(null, "PROP", new VObjectParameters(), "one\ntwo");
String actual = sw.toString();
// @formatter:off
String expected = "PROP:one\\ntwo\r\n" + "PROP:one\\ntwo\r\n" + "PROP:one\\ntwo\r\n";
// @formatter:on
assertEquals(expected, actual);
}
}
use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectWriterTest method property_value_null.
/**
* When the property value is null, it should treat the value as an empty
* string.
*/
@Test
public void property_value_null() throws Exception {
for (SyntaxStyle style : SyntaxStyle.values()) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
writer.writeProperty(null, "PROP", new VObjectParameters(), null);
String actual = sw.toString();
// @formatter:off
String expected = "PROP:\r\n";
// @formatter:on
assertEquals(expected, actual);
}
}
use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectWriterTest method parameters_nameless.
@Test
public void parameters_nameless() throws Exception {
List<VObjectParameters> list = new ArrayList<VObjectParameters>();
VObjectParameters parameters = new VObjectParameters();
parameters.put(null, "one");
list.add(parameters);
parameters = new VObjectParameters();
parameters.put(null, "one");
parameters.put(null, "two");
list.add(parameters);
SyntaxStyle style = SyntaxStyle.OLD;
{
for (boolean caretEncoding : new boolean[] { false, true }) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
writer.setCaretEncodingEnabled(caretEncoding);
for (VObjectParameters p : list) {
writer.writeProperty(null, "PROP", p, "");
}
String actual = sw.toString();
// @formatter:off
String expected = "PROP;one:\r\n" + "PROP;one;two:\r\n";
// @formatter:on
assertEquals(expected, actual);
}
}
style = SyntaxStyle.NEW;
{
for (boolean caretEncoding : new boolean[] { false, true }) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
writer.setCaretEncodingEnabled(caretEncoding);
for (VObjectParameters p : list) {
try {
writer.writeProperty(null, "PROP", p, "");
fail("IllegalArgumentException expected when property name contains nameless parameter and style is " + style.name());
} catch (IllegalArgumentException e) {
// expected
}
}
String actual = sw.toString();
// @formatter:off
String expected = "";
// @formatter:on
assertEquals(expected, actual);
}
}
}
use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectWriterTest method write_VObjectProperty.
@Test
public void write_VObjectProperty() throws Exception {
for (SyntaxStyle style : SyntaxStyle.values()) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
VObjectProperty property = new VObjectProperty();
property.setGroup("group");
property.setName("PROP");
property.getParameters().put("PARAM", "pvalue");
property.setValue("value");
writer.writeProperty(property);
String actual = sw.toString();
// @formatter:off
String expected = "group.PROP;PARAM=pvalue:value\r\n";
// @formatter:on
assertEquals(expected, actual);
}
}
use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectWriterTest method writeEndComponent.
@Test
public void writeEndComponent() throws Exception {
for (SyntaxStyle style : SyntaxStyle.values()) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
writer.writeEndComponent("COMP");
writer.writeEndComponent(" ");
try {
writer.writeEndComponent("");
fail();
} catch (IllegalArgumentException e) {
// expected
}
try {
writer.writeEndComponent(null);
fail();
} catch (IllegalArgumentException e) {
// expected
}
String actual = sw.toString();
// @formatter:off
String expected = "END:COMP\r\n" + "END: \r\n";
// @formatter:on
assertEquals(expected, actual);
}
}
Aggregations