package io.virtdata.libraryimpl.composers;

import io.virtdata.api.ValueType;
import org.testng.annotations.Test;

import static org.assertj.core.api.Assertions.assertThat;

@Test
public class MultiSpecDataTest {

    @Test
    public void testBasicMultiSpec() {
        MultiSpecData msd = MultiSpecData.forSpec("foobarbaz ", "foobarbaz func1(arg1,arg2) ; func2(arg1,arg2)");
        assertThat(msd.getResultType()).isEmpty();
        assertThat(msd.getSpecs().size()).isEqualTo(2);
    }

    @Test
    public void testAllowedSpaceBetweenArgs() {
        MultiSpecData msd = MultiSpecData.forSpec("foobarbaz ", "foobarbaz func1(arg1, arg2) ; func2(arg1, arg2)");
        assertThat(msd.getResultType()).isEmpty();
        assertThat(msd.getSpecs().size()).isEqualTo(2);
        assertThat(msd.getSpecs().get(0).getArgs()[0]).isEqualTo("arg1");
        assertThat(msd.getSpecs().get(0).getArgs()[1]).isEqualTo("arg2");
    }

    @Test
    public void testInlineConstraintMultiSpec() {
        MultiSpecData msd = MultiSpecData.forSpec("woot:", "woot:func1(arg1,arg2) -> long ; func2(arg1,arg2)");
        assertThat(msd.getResultType()).isEmpty();
        assertThat(msd.getSpecs().size()).isEqualTo(2);
        assertThat(msd.getSpecs().get(0).getResultType()).contains(ValueType.LONG);
    }

    @Test
    public void testResultConstraintMultiSpec() {
        MultiSpecData msd = MultiSpecData.forSpec("frogteeth ","frogteeth func1(arg1,arg2); func2(arg1,arg2) -> long");
        assertThat(msd.getResultType()).isPresent();
        assertThat(msd.getResultType()).contains(ValueType.LONG);
        assertThat(msd.getSpecs().size()).isEqualTo(2);
        assertThat(msd.getSpecs().get(0).getResultType()).isEmpty();
        assertThat(msd.getSpecs().get(1).getResultType()).contains(ValueType.LONG);
    }

    @Test
    public void TestStrangeChars() {
        MultiSpecData msd = MultiSpecData.forSpec("compose ", "compose Mod(3) ; Suffix('0000000000') -> String");
        assertThat(msd.getResultType()).isPresent();
        assertThat(msd.getResultType()).contains(ValueType.STRING);
    }
}
@@ -912,32 +912,499 @@
 %22arg2%22);%0A    %7D%0A%0A
+    @Test%0A    public void testReportedError() %7B%0A        MultiSpecData msd = MultiSpecData.forSpec(%22compose %22, %22compose RandomToByteBuffer(1048576) ; ToString()%22);%0A        assertThat(msd.getResultType()).isEmpty();%0A        assertThat(msd.getSpecs().get(0).getFuncName()).isEqualTo(%22RandomToByteBuffer%22);%0A        assertThat(msd.getSpecs().get(0).getArgs()%5B0%5D).isEqualTo(%221048576%22);%0A        assertThat(msd.getSpecs().get(1).getFuncName()).isEqualTo(%22ToString%22);%0A%0A    %7D%0A%0A
     @Test%0A    pu
@@ -2560,9 +2560,11 @@
 ;%0A    %7D%0A
+%0A%0A
 %7D

add sanity check to spec test