Search in sources :

Example 41 with SyntaxStyle

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

the class VObjectReaderTest method parameter_value_escape_sequences_in_other_places.

/**
 * Escape sequences for parameter values should not be applied to groups,
 * property names, or parameter names.
 */
@Test
public void parameter_value_escape_sequences_in_other_places() throws Exception {
    // @formatter:off
    String string = "one\\\\two^^three.four\\\\five^^six;seven\\\\eight^^nine=ten:";
    for (SyntaxStyle style : SyntaxStyle.values()) {
        for (boolean caretDecodingEnabled : new boolean[] { false, true }) {
            VObjectReader reader = reader(string, style);
            reader.setCaretDecodingEnabled(caretDecodingEnabled);
            VObjectDataListenerMock listener = spy(new VObjectDataListenerMock());
            reader.parse(listener);
            InOrder inorder = inOrder(listener);
            inorder.verify(listener).onProperty(eq(property().group("one\\\\two^^three").name("four\\\\five^^six").param("seven\\\\eight^^nine", "ten").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 42 with SyntaxStyle

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

the class VObjectWriterTest method property_name_starts_with_whitespace.

@Test
public void property_name_starts_with_whitespace() throws Exception {
    for (SyntaxStyle style : SyntaxStyle.values()) {
        StringWriter sw = new StringWriter();
        VObjectWriter writer = new VObjectWriter(sw, style);
        for (char c : " \t".toCharArray()) {
            try {
                writer.writeProperty(null, c + "", new VObjectParameters(), "");
                fail("IllegalArgumentException expected when property name starts with character " + ch(c) + " and style is " + style.name());
            } catch (IllegalArgumentException e) {
            // expected
            }
            writer.writeProperty(null, "PROP" + c, new VObjectParameters(), "");
        }
        String actual = sw.toString();
        // @formatter:off
        String expected = "PROP :\r\n" + "PROP	:\r\n";
        // @formatter:on
        assertEquals(expected, actual);
    }
}
Also used : StringWriter(java.io.StringWriter) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) VObjectParameters(com.github.mangstadt.vinnie.VObjectParameters) Test(org.junit.Test)

Example 43 with SyntaxStyle

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

the class VObjectWriterTest method writeBeginComponent.

@Test
public void writeBeginComponent() throws Exception {
    for (SyntaxStyle style : SyntaxStyle.values()) {
        StringWriter sw = new StringWriter();
        VObjectWriter writer = new VObjectWriter(sw, style);
        writer.writeBeginComponent("COMP");
        writer.writeBeginComponent(" ");
        try {
            writer.writeBeginComponent("");
            fail();
        } catch (IllegalArgumentException e) {
        // expected
        }
        try {
            writer.writeBeginComponent(null);
            fail();
        } catch (IllegalArgumentException e) {
        // expected
        }
        String actual = sw.toString();
        // @formatter:off
        String expected = "BEGIN:COMP\r\n" + "BEGIN: \r\n";
        // @formatter:on
        assertEquals(expected, actual);
    }
}
Also used : StringWriter(java.io.StringWriter) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) Test(org.junit.Test)

Example 44 with SyntaxStyle

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

the class VObjectWriterTest method parameters_invalid_characters_in_name.

@Test
public void parameters_invalid_characters_in_name() 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);
            for (char c : ";:=\n\r".toCharArray()) {
                VObjectParameters parameters = new VObjectParameters();
                parameters.put(c + "", "");
                try {
                    writer.writeProperty(null, "PROP", parameters, "");
                    fail("IllegalArgumentException expected when parameter name contains character " + ch(c) + " and style is " + style.name());
                } catch (IllegalArgumentException e) {
                // expected
                }
                String actual = sw.toString();
                // @formatter:off
                String expected = "";
                // @formatter:on
                assertEquals(expected, actual);
            }
        }
    }
}
Also used : StringWriter(java.io.StringWriter) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) VObjectParameters(com.github.mangstadt.vinnie.VObjectParameters) Test(org.junit.Test)

Example 45 with SyntaxStyle

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

the class VObjectWriterTest method property_name_invalid_characters.

@Test
public void property_name_invalid_characters() throws Exception {
    for (SyntaxStyle style : SyntaxStyle.values()) {
        StringWriter sw = new StringWriter();
        VObjectWriter writer = new VObjectWriter(sw, style);
        for (char c : ".;:\n\r".toCharArray()) {
            try {
                writer.writeProperty(null, c + "", new VObjectParameters(), "");
                fail("IllegalArgumentException expected when property name contains character " + ch(c) + " and style is " + style.name());
            } catch (IllegalArgumentException e) {
            // expected
            }
            String actual = sw.toString();
            // @formatter:off
            String expected = "";
            // @formatter:on
            assertEquals(expected, actual);
        }
    }
}
Also used : StringWriter(java.io.StringWriter) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) VObjectParameters(com.github.mangstadt.vinnie.VObjectParameters) 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