use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectReaderTest method parameter_value_escape_sequences_in_other_places.
/**
* Escape sequences for parameter values should not be applied to groups,
* property names, or parameter names.
*/
@Test
public void parameter_value_escape_sequences_in_other_places() throws Exception {
// @formatter:off
String string = "one\\\\two^^three.four\\\\five^^six;seven\\\\eight^^nine=ten:";
for (SyntaxStyle style : SyntaxStyle.values()) {
for (boolean caretDecodingEnabled : new boolean[] { false, true }) {
VObjectReader reader = reader(string, style);
reader.setCaretDecodingEnabled(caretDecodingEnabled);
VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
reader.parse(listener);
InOrder inorder = inOrder(listener);
inorder.verify(listener).onProperty(eq(property().group("one\\\\two^^three").name("four\\\\five^^six").param("seven\\\\eight^^nine", "ten").value("").build()), any(Context.class));
// @formatter:off
String[] lines = string.split("\r\n");
int line = 0;
assertContexts(listener, context(lines[line], ++line));
// @formatter:on
}
}
}
use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectWriterTest method property_name_starts_with_whitespace.
@Test
public void property_name_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(null, c + "", new VObjectParameters(), "");
fail("IllegalArgumentException expected when property name starts with character " + ch(c) + " and style is " + style.name());
} catch (IllegalArgumentException e) {
// expected
}
writer.writeProperty(null, "PROP" + c, new VObjectParameters(), "");
}
String actual = sw.toString();
// @formatter:off
String expected = "PROP :\r\n" + "PROP :\r\n";
// @formatter:on
assertEquals(expected, actual);
}
}
use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectWriterTest method writeBeginComponent.
@Test
public void writeBeginComponent() throws Exception {
for (SyntaxStyle style : SyntaxStyle.values()) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
writer.writeBeginComponent("COMP");
writer.writeBeginComponent(" ");
try {
writer.writeBeginComponent("");
fail();
} catch (IllegalArgumentException e) {
// expected
}
try {
writer.writeBeginComponent(null);
fail();
} catch (IllegalArgumentException e) {
// expected
}
String actual = sw.toString();
// @formatter:off
String expected = "BEGIN:COMP\r\n" + "BEGIN: \r\n";
// @formatter:on
assertEquals(expected, actual);
}
}
use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectWriterTest method parameters_invalid_characters_in_name.
@Test
public void parameters_invalid_characters_in_name() throws Exception {
for (SyntaxStyle style : SyntaxStyle.values()) {
for (boolean caretEncoding : new boolean[] { false, true }) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
writer.setCaretEncodingEnabled(caretEncoding);
for (char c : ";:=\n\r".toCharArray()) {
VObjectParameters parameters = new VObjectParameters();
parameters.put(c + "", "");
try {
writer.writeProperty(null, "PROP", parameters, "");
fail("IllegalArgumentException expected when parameter name contains 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);
}
}
}
}
use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectWriterTest method property_name_invalid_characters.
@Test
public void property_name_invalid_characters() throws Exception {
for (SyntaxStyle style : SyntaxStyle.values()) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
for (char c : ".;:\n\r".toCharArray()) {
try {
writer.writeProperty(null, c + "", new VObjectParameters(), "");
fail("IllegalArgumentException expected when property name contains 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