package de.ids_mannheim.korap.query;

import java.util.*;
import de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper;
import de.ids_mannheim.korap.query.SpanWithinQuery;

import de.ids_mannheim.korap.util.QueryException;

import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class TestSpanWithinQuery {
    @Test
    public void spanSegmentWithinQuery () throws QueryException {

        SpanSequenceQueryWrapper ssquery = new SpanSequenceQueryWrapper(
                "field", "a", "b", "c");
        SpanWithinQuery ssequery = new SpanWithinQuery("s", ssquery.toQuery());

        assertEquals(
                "spanContain(<field:s />, spanNext(spanNext(field:a, field:b), field:c))",
                ssequery.toString());

        ssquery = new SpanSequenceQueryWrapper("field", "a", "b");
        ssequery = new SpanWithinQuery("p", ssquery.toQuery());
        assertEquals("spanContain(<field:p />, spanNext(field:a, field:b))",
                ssequery.toString());

    };

};

@@ -164,24 +164,77 @@
 WithinQuery;
+%0Aimport de.ids_mannheim.korap.query.SpanElementQuery;
 %0A%0Aimport de.
@@ -1160,11 +1160,790 @@
     %7D;%0A%0A
+    @Test%0A    public void spanSegmentStartsWithQuery () throws QueryException %7B%0A%0A        SpanSequenceQueryWrapper ssquery = new SpanSequenceQueryWrapper(%0A                %22field%22, %22a%22, %22b%22, %22c%22);%0A        SpanWithinQuery ssequery = new SpanWithinQuery(%0A                                                       new SpanElementQuery(%22field%22, %22s%22),%0A                                                       ssquery.toQuery(),%0A                                                       SpanWithinQuery.STARTSWITH,%0A                                                       true%0A                                                       );%0A%0A        assertEquals(%0A                %22spanStartsWith(%3Cfield:s /%3E, spanNext(spanNext(field:a, field:b), field:c))%22,%0A                ssequery.toString());%0A    %7D;%0A
 %7D;%0A

Test with different query type