use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectReaderTest method structure.
/**
* Asserts that the component hierarchy is correctly parsed.
*/
@Test
public void structure() throws Exception {
// @formatter:off
String string = "PROP1:value1\r\n" + "BEGIN:COMP1\r\n" + "PROP2:value2\r\n" + "BEGIN:COMP2\r\n" + "PROP3:value3\r\n" + "END:COMP2\r\n" + "PROP4:value4\r\n" + "END:COMP1";
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("PROP1").value("value1").build()), any(Context.class));
inorder.verify(listener).onComponentBegin(eq("COMP1"), any(Context.class));
inorder.verify(listener).onProperty(eq(property().name("PROP2").value("value2").build()), any(Context.class));
inorder.verify(listener).onComponentBegin(eq("COMP2"), any(Context.class));
inorder.verify(listener).onProperty(eq(property().name("PROP3").value("value3").build()), any(Context.class));
inorder.verify(listener).onComponentEnd(eq("COMP2"), any(Context.class));
inorder.verify(listener).onProperty(eq(property().name("PROP4").value("value4").build()), 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(lines[line], ++line), context(asList("COMP1"), lines[line], ++line), context(asList("COMP1"), lines[line], ++line), context(asList("COMP1", "COMP2"), 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 VObjectReaderTest method structure_missing_end.
/**
* When the stream ends, but the components haven't ended.
*/
@Test
public void structure_missing_end() throws Exception {
// @formatter:off
String string = "BEGIN:COMP1\r\n" + "PROP1:value1\r\n" + "BEGIN:COMP2\r\n" + "PROP2:value2\r\n";
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).onProperty(eq(property().name("PROP1").value("value1").build()), any(Context.class));
inorder.verify(listener).onComponentBegin(eq("COMP2"), any(Context.class));
inorder.verify(listener).onProperty(eq(property().name("PROP2").value("value2").build()), 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(asList("COMP1", "COMP2"), lines[line], ++line));
// @formatter:on
}
}
use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectReaderTest method parameters_space_around_equals.
/**
* If there is any whitespace surrounding the equals character in a
* parameter declaration, it is handled differently depending on the
* version.
*/
@Test
public void parameters_space_around_equals() throws Exception {
// @formatter:off
String string = "PROP;PARAM = value:value";
// @formatter:on
SyntaxStyle style = SyntaxStyle.OLD;
{
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("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
}
style = SyntaxStyle.NEW;
{
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("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 structure_no_component_name.
/**
* When a BEGIN or END property value is empty.
*/
@Test
public void structure_no_component_name() throws Exception {
// @formatter:off
String string = "BEGIN:\r\n" + "BEGIN: \r\n" + "PROP:value\r\n" + "END:\r\n" + "END: \r\n";
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, times(2)).onWarning(eq(Warning.EMPTY_BEGIN), isNull(VObjectProperty.class), isNull(Exception.class), any(Context.class));
inorder.verify(listener).onProperty(eq(property().name("PROP").value("value").build()), any(Context.class));
inorder.verify(listener, times(2)).onWarning(eq(Warning.EMPTY_END), isNull(VObjectProperty.class), isNull(Exception.class), any(Context.class));
// @formatter:off
String[] lines = string.split("\r\n");
int line = 0;
assertContexts(listener, context(lines[line], ++line), context(lines[line], ++line), context(lines[line], ++line), context(lines[line], ++line), context(lines[line], ++line));
// @formatter:on
}
}
use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectReaderTest method badly_folded_line.
/**
* Tests what happens when the producer did not add whitespace to the
* beginning of a folded line.
*/
@Test
public void badly_folded_line() throws Exception {
// @formatter:off
String string = "PROP;PARAM=one;PARA\r\n" + "M=two: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).onWarning(eq(Warning.MALFORMED_LINE), isNull(VObjectProperty.class), isNull(Exception.class), any(Context.class));
inorder.verify(listener).onProperty(eq(property().name("M=two").value("value").build()), any(Context.class));
// @formatter:off
String[] lines = string.split("\r\n");
int line = 0;
assertContexts(listener, context(lines[line], ++line), context(lines[line], ++line));
// @formatter:on
}
}
Aggregations