Search in sources :

Example 1 with SyntaxStyle

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
    }
}
Also used : InOrder(org.mockito.InOrder) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) Test(org.junit.Test)

Example 2 with SyntaxStyle

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
    }
}
Also used : InOrder(org.mockito.InOrder) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) Test(org.junit.Test)

Example 3 with SyntaxStyle

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
    }
}
Also used : InOrder(org.mockito.InOrder) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) Test(org.junit.Test)

Example 4 with SyntaxStyle

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
    }
}
Also used : InOrder(org.mockito.InOrder) VObjectProperty(com.github.mangstadt.vinnie.VObjectProperty) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) DecoderException(com.github.mangstadt.vinnie.codec.DecoderException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) Test(org.junit.Test)

Example 5 with SyntaxStyle

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
    }
}
Also used : InOrder(org.mockito.InOrder) VObjectProperty(com.github.mangstadt.vinnie.VObjectProperty) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) DecoderException(com.github.mangstadt.vinnie.codec.DecoderException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) Test(org.junit.Test)

Aggregations

SyntaxStyle (com.github.mangstadt.vinnie.SyntaxStyle)50 Test (org.junit.Test)45 InOrder (org.mockito.InOrder)24 StringWriter (java.io.StringWriter)21 VObjectParameters (com.github.mangstadt.vinnie.VObjectParameters)15 VObjectProperty (com.github.mangstadt.vinnie.VObjectProperty)12 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)7 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)7 DecoderException (com.github.mangstadt.vinnie.codec.DecoderException)6 ArrayList (java.util.ArrayList)4 AllowedCharacters (com.github.mangstadt.vinnie.validate.AllowedCharacters)3 ValidationWarning (ezvcard.ValidationWarning)3 HashMap (java.util.HashMap)3 Map (java.util.Map)2 VCardDataType (ezvcard.VCardDataType)1 VCardVersion (ezvcard.VCardVersion)1 ClientPidMap (ezvcard.property.ClientPidMap)1 SortString (ezvcard.property.SortString)1 AbstractList (java.util.AbstractList)1 EnumSet (java.util.EnumSet)1