use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectReaderTest method blank_parameter_name.
/**
* When a parameter name is empty.
*/
@Test
public void blank_parameter_name() throws Exception {
// @formatter:off
String string = "PROP;=value:value";
for (SyntaxStyle style : SyntaxStyle.values()) {
VObjectReader reader = reader(string, style);
VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
reader.parse(listener);
InOrder inorder = inOrder(listener);
inorder.verify(listener).onProperty(eq(property().name("PROP").param("", "value").value("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 VObjectReaderTest method no_parameter_name.
/**
* When a parameter value doesn't have a name.
*/
@Test
public void no_parameter_name() throws Exception {
// @formatter:off
String string = "PROP;HOME;WORK:value";
for (SyntaxStyle style : SyntaxStyle.values()) {
VObjectReader reader = reader(string, style);
VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
reader.parse(listener);
InOrder inorder = inOrder(listener);
inorder.verify(listener).onProperty(eq(property().name("PROP").param(null, "HOME", "WORK").value("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 VObjectReaderTest method whitespace_around_component_names.
/**
* When checking for BEGIN and END properties, the property name and value
* should be trimmed so that any whitespace around the colon ignored.
* Whitespace around the colon is allowed by old style syntax, though it
* never happens in practice.
*/
@Test
public void whitespace_around_component_names() throws Exception {
// @formatter:off
String string = "BEGIN:COMP1\r\n" + "BEGIN:COMP2\r\n" + "END : COMP2 \r\n" + "END\t:\tCOMP1\t";
for (SyntaxStyle style : SyntaxStyle.values()) {
VObjectReader reader = reader(string, style);
VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
reader.parse(listener);
InOrder inorder = inOrder(listener);
inorder.verify(listener).onComponentBegin(eq("COMP1"), any(Context.class));
inorder.verify(listener).onComponentBegin(eq("COMP2"), any(Context.class));
inorder.verify(listener).onComponentEnd(eq("COMP2"), any(Context.class));
inorder.verify(listener).onComponentEnd(eq("COMP1"), any(Context.class));
// @formatter:off
String[] lines = string.split("\r\n");
int line = 0;
assertContexts(listener, context(lines[line], ++line), context(asList("COMP1"), lines[line], ++line), context(asList("COMP1"), lines[line], ++line), context(lines[line], ++line));
// @formatter:on
}
}
use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectWriterTest method parameters_multivalued_empty_values.
/**
* When the parameters multimap has a key with an empty list, the parameter
* should not be written. This should never happen if the user sticks to the
* API of the VObjectParameters class and does not modify the backing map
* manually.
*/
@Test
public void parameters_multivalued_empty_values() 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);
VObjectParameters parameters = new VObjectParameters();
parameters.getMap().put("PARAM", new ArrayList<String>());
writer.writeProperty(null, "PROP", parameters, "");
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 property_name.
@Test
public void property_name() throws Exception {
for (SyntaxStyle style : SyntaxStyle.values()) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
writer.writeProperty(null, "PROP", new VObjectParameters(), "");
try {
writer.writeProperty(null, "", new VObjectParameters(), "");
fail("IllegalArgumentException expected when property name is empty and style is " + style.name());
} catch (IllegalArgumentException e) {
// expected
}
try {
writer.writeProperty(null, null, new VObjectParameters(), "");
fail("NullPointerException expected when property name is null and style is " + style.name());
} catch (NullPointerException e) {
// expected
}
String actual = sw.toString();
// @formatter:off
String expected = "PROP:\r\n";
// @formatter:on
assertEquals(expected, actual);
}
}
Aggregations