package org.javarosa.form.api.test;

import org.javarosa.core.model.FormIndex;
import org.javarosa.form.api.FormEntryAction;
import org.javarosa.form.api.FormEntrySession;
import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;
import java.util.Vector;

/**
 * @author Phillip Mates (pmates@dimagi.com).
 */
public class FormEntrySessionTest {
    @Test
    public void testSplitByParens() {
        String input = "(a) (b c) (d)";
        Vector<String> expectedOutput = new Vector<>(Arrays.asList("(a)", "(b c)", "(d)"));
        Assert.assertEquals(expectedOutput, FormEntrySession.splitTopParens(input));

        input = "(a) ((b) (c)) ((d))";
        expectedOutput = new Vector<>(Arrays.asList("(a)", "((b) (c))", "((d))"));
        Assert.assertEquals(expectedOutput, FormEntrySession.splitTopParens(input));

        input = "(a) (\\(b c\\)) (\\(d\\))";
        expectedOutput = new Vector<>(Arrays.asList("(a)", "(\\(b c\\))", "(\\(d\\))"));
        Assert.assertEquals(expectedOutput, FormEntrySession.splitTopParens(input));
    }

    /*@Test
    public void testFormEntrySessionStringSerialization() {
        FormEntrySession formEntrySession = new FormEntrySession();
        formEntrySession.addValueSet(FormIndex.createBeginningOfFormIndex(), "foo");
        formEntrySession.addNewRepeat(FormIndex.createBeginningOfFormIndex());
        formEntrySession.addValueSet(FormIndex.createEndOfFormIndex(), "bar");
        String sessionAsString = formEntrySession.toString();
        Assert.assertEquals(sessionAsString, FormEntrySession.fromString(sessionAsString).toString());
    }

    @Test
    public void testAddingDuplicate() {
        FormEntrySession formEntrySession = new FormEntrySession();
        formEntrySession.addValueSet(FormIndex.createBeginningOfFormIndex(), "foo");
        formEntrySession.addValueSet(FormIndex.createBeginningOfFormIndex(), "foo");
        Assert.assertEquals(1, formEntrySession.size());

        FormIndex randomIndex = new FormIndex(FormIndex.createBeginningOfFormIndex(), 52, 2, null);
        formEntrySession.addValueSet(randomIndex, "bar");
        FormEntryAction secondAction = formEntrySession.peekAction();

        formEntrySession.addValueSet(FormIndex.createBeginningOfFormIndex(), "foo");

        Assert.assertEquals(2, formEntrySession.size());
        Assert.assertEquals(secondAction, formEntrySession.peekAction());
    }*/
}

@@ -1057,1363 +1057,7 @@
    %7D
-%0A%0A    /*@Test%0A    public void testFormEntrySessionStringSerialization() %7B%0A        FormEntrySession formEntrySession = new FormEntrySession();%0A        formEntrySession.addValueSet(FormIndex.createBeginningOfFormIndex(), %22foo%22);%0A        formEntrySession.addNewRepeat(FormIndex.createBeginningOfFormIndex());%0A        formEntrySession.addValueSet(FormIndex.createEndOfFormIndex(), %22bar%22);%0A        String sessionAsString = formEntrySession.toString();%0A        Assert.assertEquals(sessionAsString, FormEntrySession.fromString(sessionAsString).toString());%0A    %7D%0A%0A    @Test%0A    public void testAddingDuplicate() %7B%0A        FormEntrySession formEntrySession = new FormEntrySession();%0A        formEntrySession.addValueSet(FormIndex.createBeginningOfFormIndex(), %22foo%22);%0A        formEntrySession.addValueSet(FormIndex.createBeginningOfFormIndex(), %22foo%22);%0A        Assert.assertEquals(1, formEntrySession.size());%0A%0A        FormIndex randomIndex = new FormIndex(FormIndex.createBeginningOfFormIndex(), 52, 2, null);%0A        formEntrySession.addValueSet(randomIndex, %22bar%22);%0A        FormEntryAction secondAction = formEntrySession.peekAction();%0A%0A        formEntrySession.addValueSet(FormIndex.createBeginningOfFormIndex(), %22foo%22);%0A%0A        Assert.assertEquals(2, formEntrySession.size());%0A        Assert.assertEquals(secondAction, formEntrySession.peekAction());%0A    %7D*/
 %0A%7D%0A

Remove commented out tests