Search in sources :

Example 36 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method case_insensitivity.

/**
 * Asserts the case-sensitivity of the parts of a vobject.
 */
@Test
public void case_insensitivity() throws Exception {
    // @formatter:off
    String string = "BEGIN:COMP1\r\n" + "group.prop;param=param_value:prop_value\r\n" + "end:comp1\r\n" + "BEGIN:comp2\r\n" + "end:COMP2";
    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().group("group").name("prop").param("PARAM", "param_value").value("prop_value").build()), any(Context.class));
        inorder.verify(listener).onComponentEnd(eq("COMP1"), any(Context.class));
        inorder.verify(listener).onComponentBegin(eq("COMP2"), any(Context.class));
        inorder.verify(listener).onComponentEnd(eq("COMP2"), 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(lines[line], ++line), context(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 37 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method pause_parsing.

@Test
public void pause_parsing() throws Exception {
    // @formatter:off
    String string = "BEGIN:COMP1\r\n" + "PROP:value\r\n" + "END:COMP1\r\n" + "BEGIN:COMP2\r\n" + "PROP:value\r\n" + "END:COMP2\r\n" + "PROP2:value\r\n" + "PROP:value";
    for (SyntaxStyle style : SyntaxStyle.values()) {
        VObjectReader reader = reader(string, style);
        VObjectDataListenerMock listener = spy(new VObjectDataListenerMock() {

            @Override
            public void onComponentBegin(String name, Context context) {
                super.onComponentBegin(name, context);
                if (name.equals("COMP1")) {
                    context.stop();
                }
            }

            @Override
            public void onComponentEnd(String name, Context context) {
                super.onComponentEnd(name, context);
                if (name.equals("COMP2")) {
                    context.stop();
                }
            }

            @Override
            public void onProperty(VObjectProperty property, Context context) {
                super.onProperty(property, context);
                if (property.getName().equals("PROP2")) {
                    context.stop();
                }
            }
        });
        InOrder inorder = inOrder(listener);
        reader.parse(listener);
        inorder.verify(listener).onComponentBegin(eq("COMP1"), any(Context.class));
        inorder.verifyNoMoreInteractions();
        reader.parse(listener);
        inorder.verify(listener).onProperty(eq(property().name("PROP").value("value").build()), any(Context.class));
        inorder.verify(listener).onComponentEnd(eq("COMP1"), any(Context.class));
        inorder.verify(listener).onComponentBegin(eq("COMP2"), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").value("value").build()), any(Context.class));
        inorder.verify(listener).onComponentEnd(eq("COMP2"), any(Context.class));
        inorder.verifyNoMoreInteractions();
        reader.parse(listener);
        inorder.verify(listener).onProperty(eq(property().name("PROP2").value("value").build()), any(Context.class));
        inorder.verifyNoMoreInteractions();
        reader.parse(listener);
        inorder.verify(listener).onProperty(eq(property().name("PROP").value("value").build()), any(Context.class));
        inorder.verifyNoMoreInteractions();
        // @formatter:off
        String[] lines = string.split("\r\n");
        int line = 0;
        assertContexts(listener, context(lines[line], ++line), context(asList("COMP1"), lines[line], ++line), context(lines[line], ++line), context(lines[line], ++line), context(asList("COMP2"), lines[line], ++line), context(lines[line], ++line), context(lines[line], ++line), context(lines[line], ++line));
    // @formatter:on
    }
}
Also used : VObjectProperty(com.github.mangstadt.vinnie.VObjectProperty) InOrder(org.mockito.InOrder) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) Test(org.junit.Test)

Example 38 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method property_cut_off.

/**
 * When the input stream ends before the property value is reached.
 */
@Test
public void property_cut_off() throws Exception {
    // @formatter:off
    String string = "PROP;PARAM=one;PARA";
    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));
        // @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) 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 39 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method folded_lines.

/**
 * Asserts that it can unfold folded lines.
 */
@Test
public void folded_lines() throws Exception {
    // @formatter:off
    String string = "PROP:fo\r\n" + " lded\r\n" + "PROP:fo\r\n" + "\tlded\r\n" + "PROP:fo\r\n" + // empty folded line
    " \r\n" + " lded\r\n" + "PROP:fo\r\n" + " \tlded\r\n" + "PROP:fo\r\n" + "\t lded\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE:fo=\r\n" + " lded\r\n" + "PROP;QUOTED-PRINTABLE:fo=\r\n" + " lded\r\n" + "PROP;ENCODING=QUOTED-PRINTABLE:fo=\r\n" + "lded\r\n" + "PROP;P\r\n" + " ARAM=value:\r\n" + "PROP:last";
    // @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, times(5)).onProperty(eq(property().name("PROP").value("folded").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").value("folded").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").param(null, "QUOTED-PRINTABLE").value("folded").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").value("folded").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").param("PARAM", "value").value("").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").value("last").build()), any(Context.class));
        // @formatter:off
        assertContexts(listener, context("PROP:folded", 1), context("PROP:folded", 3), context("PROP:folded", 5), context("PROP:folded", 8), context("PROP:folded", 10), context("PROP;ENCODING=QUOTED-PRINTABLE:folded", 12), context("PROP;QUOTED-PRINTABLE:folded", 14), context("PROP;ENCODING=QUOTED-PRINTABLE:folded", 16), context("PROP;PARAM=value:", 18), context("PROP:last", 20));
    // @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, times(3)).onProperty(eq(property().name("PROP").value("folded").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").value("fo\tlded").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").value("fo lded").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").value("folded").value("folded").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").param(null, "QUOTED-PRINTABLE").value("folded").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").param("ENCODING", "QUOTED-PRINTABLE").value("folded").value("folded").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").param("PARAM", "value").value("").build()), any(Context.class));
        inorder.verify(listener).onProperty(eq(property().name("PROP").value("last").build()), any(Context.class));
        // @formatter:off
        assertContexts(listener, context("PROP:folded", 1), context("PROP:folded", 3), context("PROP:folded", 5), context("PROP:fo\tlded", 8), context("PROP:fo lded", 10), context("PROP;ENCODING=QUOTED-PRINTABLE:folded", 12), context("PROP;QUOTED-PRINTABLE:folded", 14), context("PROP;ENCODING=QUOTED-PRINTABLE:folded", 16), context("PROP;PARAM=value:", 18), context("PROP:last", 20));
    // @formatter:on
    }
}
Also used : InOrder(org.mockito.InOrder) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) Test(org.junit.Test)

Example 40 with SyntaxStyle

use of com.github.mangstadt.vinnie.SyntaxStyle in project vinnie by mangstadt.

the class VObjectReaderTest method multi_valued_parameters.

/**
 * New style syntax has special syntax for defining multi-valued parameters.
 */
@Test
public void multi_valued_parameters() throws Exception {
    // @formatter:off
    String string = "PROP;PARAM=value1,value2: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", "value1,value2").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", "value1", "value2").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)

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