use of com.github.mangstadt.vinnie.VObjectParameters 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.VObjectParameters 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.VObjectParameters 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.VObjectParameters in project vinnie by mangstadt.
the class VObjectWriterTest method parameters_multivalued.
@Test
public void parameters_multivalued() throws Exception {
List<VObjectParameters> list = new ArrayList<VObjectParameters>();
VObjectParameters parameters = new VObjectParameters();
parameters.put("SINGLE", "one");
list.add(parameters);
parameters = new VObjectParameters();
parameters.put("MULTIPLE", "one");
parameters.put("MULTIPLE", "two");
list.add(parameters);
parameters = new VObjectParameters();
parameters.put("SINGLE", "one");
parameters.put("MULTIPLE", "one");
parameters.put("MULTIPLE", "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;SINGLE=one:\r\n" + "PROP;MULTIPLE=one;MULTIPLE=two:\r\n" + "PROP;SINGLE=one;MULTIPLE=one;MULTIPLE=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) {
writer.writeProperty(null, "PROP", p, "");
}
String actual = sw.toString();
// @formatter:off
String expected = "PROP;SINGLE=one:\r\n" + "PROP;MULTIPLE=one,two:\r\n" + "PROP;SINGLE=one;MULTIPLE=one,two:\r\n";
// @formatter:on
assertEquals(expected, actual);
}
}
}
use of com.github.mangstadt.vinnie.VObjectParameters in project vinnie by mangstadt.
the class VObjectWriterTest method group_starts_with_whitespace.
@Test
public void group_starts_with_whitespace() throws Exception {
for (SyntaxStyle style : SyntaxStyle.values()) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
for (char c : " \t".toCharArray()) {
try {
writer.writeProperty(c + "", "PROP", new VObjectParameters(), "");
fail("IllegalArgumentException expected when group name starts with character " + ch(c) + " and style is " + style.name());
} catch (IllegalArgumentException e) {
// expected
}
String actual = sw.toString();
// @formatter:off
String expected = "";
// @formatter:on
assertEquals(expected, actual);
}
}
}
Aggregations