Updated SpanSubspanQuery for empty length.
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestSubSpanIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestSubSpanIndex.java
index 58f88f5..4aff0bf 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestSubSpanIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestSubSpanIndex.java
@@ -9,7 +9,6 @@
 import org.junit.Test;
 
 import de.ids_mannheim.korap.KorapIndex;
-import de.ids_mannheim.korap.KorapMatch;
 import de.ids_mannheim.korap.KorapResult;
 import de.ids_mannheim.korap.query.DistanceConstraint;
 import de.ids_mannheim.korap.query.SpanDistanceQuery;
@@ -20,7 +19,7 @@
     KorapResult kr;
     KorapIndex ki;
 
-    public TestSubSpanIndex() throws IOException {
+    public TestSubSpanIndex () throws IOException {
         ki = new KorapIndex();
         ki.addDocFile(getClass().getResource("/wiki/00001.json.gz").getFile(),
                 true);
@@ -29,10 +28,10 @@
 
     @Test
     public void testCase1() throws IOException {
-        SpanDistanceQuery sdq = new SpanDistanceQuery(
-                new SpanTermQuery(new Term("tokens", "tt/p:NN")), 
-                new SpanTermQuery(new Term("tokens", "tt/p:VAFIN")), 
-                new DistanceConstraint(5, 5, true,false), true);
+        SpanDistanceQuery sdq = new SpanDistanceQuery(new SpanTermQuery(
+                new Term("tokens", "tt/p:NN")), new SpanTermQuery(new Term(
+                "tokens", "tt/p:VAFIN")), new DistanceConstraint(5, 5, true,
+                false), true);
 
         SpanSubspanQuery ssq = new SpanSubspanQuery(sdq, 0, 2, true);
         kr = ki.search(ssq, (short) 10);
@@ -60,11 +59,12 @@
 
     @Test
     public void testCase2() {
-        SpanDistanceQuery sdq = new SpanDistanceQuery(
-                new SpanTermQuery(new Term("tokens", "tt/p:NN")), 
-                new SpanTermQuery(new Term("tokens", "tt/p:VAFIN")), 
-                new DistanceConstraint(5, 5, true,false), true);
-        
+        SpanDistanceQuery sdq = new SpanDistanceQuery(new SpanTermQuery(
+                new Term("tokens", "tt/p:NN")), new SpanTermQuery(new Term(
+                "tokens", "tt/p:VAFIN")), new DistanceConstraint(5, 5, true,
+                false), true);
+
+        // the subspan length is longer than the span length
         SpanSubspanQuery ssq = new SpanSubspanQuery(sdq, 0, 7, true);
         kr = ki.search(ssq, (short) 10);
 
@@ -72,20 +72,47 @@
         assertEquals(41, kr.getMatch(0).getEndPos());
         assertEquals(179, kr.getMatch(1).getStartPos());
         assertEquals(185, kr.getMatch(1).getEndPos());
-        
+
+        // the subspan start is before the span start
         ssq = new SpanSubspanQuery(sdq, -7, 4, true);
         kr = ki.search(ssq, (short) 10);
-        
+
         assertEquals((long) 8, kr.getTotalResults());
         assertEquals(35, kr.getMatch(0).getStartPos());
         assertEquals(39, kr.getMatch(0).getEndPos());
         assertEquals(179, kr.getMatch(1).getStartPos());
         assertEquals(183, kr.getMatch(1).getEndPos());
-        
-        /* for (KorapMatch km : kr.getMatches()){
-         System.out.println(km.getStartPos() +","+km.getEndPos()
-         +km.getSnippetBrackets()); }*/
-         
+
+    }
+
+    // Length 0
+    @Test
+    public void testCase3() {
+        SpanDistanceQuery sdq = new SpanDistanceQuery(new SpanTermQuery(
+                new Term("tokens", "tt/p:NN")), new SpanTermQuery(new Term(
+                "tokens", "tt/p:VAFIN")), new DistanceConstraint(5, 5, true,
+                false), true);
+
+        SpanSubspanQuery ssq = new SpanSubspanQuery(sdq, 3, 0, true);
+        kr = ki.search(ssq, (short) 10);
+
+        assertEquals(38, kr.getMatch(0).getStartPos());
+        assertEquals(41, kr.getMatch(0).getEndPos());
+        assertEquals(182, kr.getMatch(1).getStartPos());
+        assertEquals(185, kr.getMatch(1).getEndPos());
+
+        ssq = new SpanSubspanQuery(sdq, -2, 0, true);
+        kr = ki.search(ssq, (short) 10);
+
+        assertEquals(39, kr.getMatch(0).getStartPos());
+        assertEquals(41, kr.getMatch(0).getEndPos());
+        assertEquals(183, kr.getMatch(1).getStartPos());
+        assertEquals(185, kr.getMatch(1).getEndPos());
+
+        // for (KorapMatch km : kr.getMatches()) {
+        // System.out.println(km.getStartPos() + "," + km.getEndPos()
+        // + km.getSnippetBrackets());
+        // }
     }
 
 }
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestSpanSubspanQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestSpanSubspanQueryJSON.java
index e1e473d..c9f6d56 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestSpanSubspanQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestSpanSubspanQueryJSON.java
@@ -21,6 +21,26 @@
                 .getFile();
         SpanQueryWrapper sqwi = getJSONQuery(filepath);
         SpanQuery sq = sqwi.toQuery();
+        assertEquals(sq.toString(),
+                "subspan(spanContain(<tokens:s />, tokens:tt/l:Haus),1,4)");
+    }
+
+    @Test
+    public void testCase2() throws QueryException {
+        String filepath = getClass().getResource("/queries/submatch2.jsonld")
+                .getFile();
+        SpanQueryWrapper sqwi = getJSONQuery(filepath);
+        SpanQuery sq = sqwi.toQuery();
         assertEquals(sq.toString(), "subspan(<tokens:s />,1,4)");
     }
+
+    public void testCase3() throws QueryException {
+        String filepath = getClass().getResource("/queries/submatch3.jsonld")
+                .getFile();
+        SpanQueryWrapper sqwi = getJSONQuery(filepath);
+        SpanQuery sq = sqwi.toQuery();
+        assertEquals(sq.toString(), "subspan(<tokens:s />,1,0)");
+
+    }
+
 }
diff --git a/src/test/resources/queries/submatch.jsonld b/src/test/resources/queries/submatch.jsonld
index 36153eb..4baa073 100644
--- a/src/test/resources/queries/submatch.jsonld
+++ b/src/test/resources/queries/submatch.jsonld
@@ -11,15 +11,35 @@
    ],
    "collection":null,
    "query":{
-      "@type":"korap:reference",
-      "operation":"operation:focus",
-      "operands":[
+      "@type" : "korap:reference",
+      "operands" : [
          {
-            "@type":"korap:span",
-            "key":"s"
+            "@type" : "korap:group",
+            "frame" : "frame:contains",
+            "frames" : [
+               "frames:contains"
+            ],
+            "operands" : [
+               {
+                  "@type" : "korap:span",
+                  "key" : "s"
+               },
+               {
+                  "@type" : "korap:token",
+                  "wrap" : {
+                     "@type" : "korap:term",
+                     "foundry" : "tt",
+                     "key" : "Haus",
+                     "layer" : "lemma",
+                     "match" : "match:eq"
+                  }
+               }
+            ],
+            "operation" : "operation:position"
          }
       ],
-      "spanRef":[
+      "operation" : "operation:focus",
+      "spanRef" : [
          1,
          4
       ]
diff --git a/src/test/resources/queries/submatch2.jsonld b/src/test/resources/queries/submatch2.jsonld
new file mode 100644
index 0000000..45a3155
--- /dev/null
+++ b/src/test/resources/queries/submatch2.jsonld
@@ -0,0 +1,30 @@
+{
+   "@context":"http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld",
+   "errors":[
+
+   ],
+   "warnings":[
+
+   ],
+   "messages":[
+
+   ],
+   "collection":null,
+   "query":{
+      "@type" : "korap:reference",
+      "operands" : [
+         {
+            "@type" : "korap:span",
+            "key" : "s"
+         }
+      ],
+      "operation" : "operation:focus",
+      "spanRef" : [
+         1,
+         4
+      ]
+   },
+   "meta":{
+
+   }
+}
diff --git a/src/test/resources/queries/submatch3.jsonld b/src/test/resources/queries/submatch3.jsonld
new file mode 100644
index 0000000..6363de6
--- /dev/null
+++ b/src/test/resources/queries/submatch3.jsonld
@@ -0,0 +1,29 @@
+{
+   "@context":"http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld",
+   "errors":[
+
+   ],
+   "warnings":[
+
+   ],
+   "messages":[
+
+   ],
+   "collection":null,
+   "query":{
+      "@type" : "korap:reference",
+      "operands" : [
+         {
+            "@type" : "korap:span",
+            "key" : "s"
+         }
+      ],
+      "operation" : "operation:focus",
+      "spanRef" : [
+         1
+      ]
+   },
+   "meta":{
+
+   }
+}