use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectReaderTest method structured_extra_end.
/**
* Asserts that a warning should be thrown when an unmatched END property is
* found.
*/
@Test
public void structured_extra_end() throws Exception {
// @formatter:off
String string = "BEGIN:COMP1\r\n" + "PROP:value\r\n" + "END:COMP2\r\n" + "END:COMP1\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("PROP").value("value").build()), any(Context.class));
inorder.verify(listener).onWarning(eq(Warning.UNMATCHED_END), isNull(VObjectProperty.class), isNull(Exception.class), 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 VObjectReaderTest method special_chars_in_parameter_name.
/**
* When a parameter name has special characters.
*/
@Test
public void special_chars_in_parameter_name() throws Exception {
// @formatter:off
String string = "PROP;P,.\"ARAM=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("P,.\"ARAM", "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_components_out_of_order.
/**
* Asserts what happens when BEGIN/END components are not nested correctly.
*/
@Test
public void structure_components_out_of_order() throws Exception {
// @formatter:off
String string = "BEGIN:COMP1\r\n" + "PROP1:value1\r\n" + "BEGIN:COMP2\r\n" + "PROP2:value2\r\n" + // this also ends COMP2
"END:COMP1\r\n" + "PROP3:value3\r\n" + "END:COMP2\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));
/*
* COMP2 is ended even though its END property wasn't reached
* because COMP1 ended and COMP2 is nested inside of COMP1.
*/
inorder.verify(listener).onComponentEnd(eq("COMP2"), any(Context.class));
inorder.verify(listener).onComponentEnd(eq("COMP1"), any(Context.class));
inorder.verify(listener).onProperty(eq(property().name("PROP3").value("value3").build()), any(Context.class));
inorder.verify(listener).onWarning(eq(Warning.UNMATCHED_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(asList("COMP1"), lines[line], ++line), context(asList("COMP1"), lines[line], ++line), context(asList("COMP1", "COMP2"), lines[line], ++line), context(asList("COMP1"), lines[line], line + 1), 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 quoted_printable.
/**
* Tests quoted-printable encoding.
*/
@Test
public void quoted_printable() throws Exception {
// @formatter:off
String string = "PROP;QUOTED-PRINTABLE:one=0D=0Atwo\r\n" + "PROP;quoted-printable:one=0D=0Atwo\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE:one=0D=0Atwo\r\n" + "PROP;ENCODING=quoted-printable:one=0D=0Atwo\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE:=XX\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:one=0D=0Atwo\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE;CHARSET=invalid:one=0D=0Atwo\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE;CHARSET=illegal name:one=0D=0Atwo";
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, "QUOTED-PRINTABLE").value("one\r\ntwo").build()), any(Context.class));
inorder.verify(listener).onProperty(eq(property().name("PROP").param(null, "quoted-printable").value("one\r\ntwo").build()), any(Context.class));
inorder.verify(listener).onProperty(eq(property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").value("one\r\ntwo").build()), any(Context.class));
inorder.verify(listener).onProperty(eq(property().name("PROP").param("ENCODING", "quoted-printable").value("one\r\ntwo").build()), any(Context.class));
VObjectProperty errorDecoding = property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").value("=XX").build();
inorder.verify(listener).onWarning(eq(Warning.QUOTED_PRINTABLE_ERROR), eq(errorDecoding), any(DecoderException.class), any(Context.class));
inorder.verify(listener).onProperty(eq(errorDecoding), any(Context.class));
inorder.verify(listener).onProperty(eq(property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").param("CHARSET", "UTF-8").value("one\r\ntwo").build()), any(Context.class));
VObjectProperty invalidCharset = property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").param("CHARSET", "invalid").value("one\r\ntwo").build();
inorder.verify(listener).onWarning(eq(Warning.UNKNOWN_CHARSET), eq(invalidCharset), any(UnsupportedCharsetException.class), any(Context.class));
inorder.verify(listener).onProperty(eq(invalidCharset), any(Context.class));
VObjectProperty illegalName = property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").param("CHARSET", "illegal name").value("one\r\ntwo").build();
inorder.verify(listener).onWarning(eq(Warning.UNKNOWN_CHARSET), eq(illegalName), any(IllegalCharsetNameException.class), any(Context.class));
inorder.verify(listener).onProperty(eq(illegalName), 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 + 1), context(lines[line], ++line), context(lines[line], ++line), context(lines[line], line + 1), context(lines[line], ++line), context(lines[line], line + 1), context(lines[line], ++line));
// @formatter:on
}
}
use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.
the class VObjectReaderTest method empty_group_and_property_names.
/**
* When the group and/or property names are empty.
*/
@Test
public void empty_group_and_property_names() throws Exception {
// @formatter:off
String string = ":value\r\n" + ".:value\r\n" + "group.:value\r\n" + ".PROP: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("").value("value").build()), any(Context.class));
inorder.verify(listener).onProperty(eq(property().group("").name("").value("value").build()), any(Context.class));
inorder.verify(listener).onProperty(eq(property().group("group").name("").value("value").build()), any(Context.class));
inorder.verify(listener).onProperty(eq(property().group("").name("PROP").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), context(lines[line], ++line), context(lines[line], ++line));
// @formatter:on
}
}
Aggregations