Added failing test for distances including a sequence with optionality

Change-Id: I39c3411d382e1d87f1fcd2e2f4da47f3fd8cbfb3
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryJSON.java
index a38aec2..e5030f8 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestSpanSequenceQueryJSON.java
@@ -351,6 +351,27 @@
                 sqwi.toQuery().toString());
     };
 
+    @Test
+    public void queryJSONkoralOptionalityInDistanceBug () throws QueryException {
+		// Sonne [] Mond?
+        SpanQueryWrapper sqwi = jsonQueryFile("distance-with-optionality.jsonld");
+        assertEquals(
+			"focus(254: spanContain(<tokens:base/s:t />, {254: spanOr([spanExpansion(tokens:s:Sonne, []{1, 1}, right), spanNext(spanExpansion(tokens:s:Sonne, []{1, 1}, right), tokens:s:Mond)])}))",
+			sqwi.toQuery().toString());
+		// Could also be a distance at the end ... that's a query planner thing.
+    };
+
+	@Test
+    public void queryJSONkoralOptionalityAfterEmptyBug () throws QueryException {
+		// Sonne [] Mond?
+        SpanQueryWrapper sqwi = jsonQueryFile("empty-followed-by-optionality.jsonld");
+        assertEquals(
+			"focus(254: spanContain(<tokens:base/s:t />, {254: spanOr([spanExpansion(tokens:s:Sonne, []{1, 1}, right), spanNext(spanExpansion(tokens:s:Sonne, []{1, 1}, right), tokens:s:Mond)])}))",
+			sqwi.toQuery().toString());
+		// Could also be a distance at the end ... that's a query planner thing.
+    };
+
+	
 
     // get query wrapper based on json file
     public SpanQueryWrapper jsonQueryFile (String filename) {
diff --git a/src/test/resources/queries/sequence/distance-with-optionality.jsonld b/src/test/resources/queries/sequence/distance-with-optionality.jsonld
new file mode 100644
index 0000000..c1ec846
--- /dev/null
+++ b/src/test/resources/queries/sequence/distance-with-optionality.jsonld
@@ -0,0 +1,52 @@
+{
+  "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
+  "query": {
+    "@type": "koral:group",
+    "distances": [
+      {
+        "@type": "koral:distance",
+        "boundary": {
+          "@type": "koral:boundary",
+          "max": 1,
+          "min": 1
+        },
+        "key": "w",
+        "max": 1,
+        "min": 1
+      }
+    ],
+    "inOrder": true,
+    "operands": [
+      {
+        "@type": "koral:token",
+        "wrap": {
+          "@type": "koral:term",
+          "key": "Sonne",
+          "layer": "orth",
+          "match": "match:eq"
+        }
+      },
+      {
+        "@type": "koral:group",
+        "boundary": {
+          "@type": "koral:boundary",
+          "max": 1,
+          "min": 0
+        },
+        "operands": [
+          {
+            "@type": "koral:token",
+            "wrap": {
+              "@type": "koral:term",
+              "key": "Mond",
+              "layer": "orth",
+              "match": "match:eq"
+            }
+          }
+        ],
+        "operation": "operation:repetition"
+      }
+    ],
+    "operation": "operation:sequence"
+  }
+}
diff --git a/src/test/resources/queries/sequence/empty-followed-by-optionality.jsonld b/src/test/resources/queries/sequence/empty-followed-by-optionality.jsonld
new file mode 100644
index 0000000..0d60cd1
--- /dev/null
+++ b/src/test/resources/queries/sequence/empty-followed-by-optionality.jsonld
@@ -0,0 +1,42 @@
+{
+  "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
+  "query": {
+    "@type": "koral:group",
+    "inOrder": true,
+    "operation": "operation:sequence",
+    "operands": [
+      {
+        "@type": "koral:token",
+        "wrap": {
+          "@type": "koral:term",
+          "key": "Sonne",
+          "layer": "orth",
+          "match": "match:eq"
+        }
+      },
+      {
+        "@type": "koral:token"
+      },
+      {
+        "@type": "koral:group",
+        "boundary": {
+          "@type": "koral:boundary",
+          "max": 1,
+          "min": 0
+        },
+        "operands": [
+          {
+            "@type": "koral:token",
+            "wrap": {
+              "@type": "koral:term",
+              "key": "Mond",
+              "layer": "orth",
+              "match": "match:eq"
+            }
+          }
+        ],
+        "operation": "operation:repetition"
+      }
+    ]
+  }
+}