JAL-3438 spotless for 2.11.2.0
[jalview.git] / test / jalview / io / gff / GffHelperBaseTest.java
index de4e820..5bd60a8 100644 (file)
@@ -53,21 +53,20 @@ public class GffHelperBaseTest
   {
     assertTrue(GffHelperBase.parseNameValuePairs(null, ";", ' ', ",")
             .isEmpty());
-    assertTrue(GffHelperBase.parseNameValuePairs("", ";", ' ', ",")
-            .isEmpty());
-    assertTrue(GffHelperBase.parseNameValuePairs("hello=world", ";", ' ',
-            ",").isEmpty());
+    assertTrue(
+            GffHelperBase.parseNameValuePairs("", ";", ' ', ",").isEmpty());
+    assertTrue(GffHelperBase
+            .parseNameValuePairs("hello=world", ";", ' ', ",").isEmpty());
 
-    Map<String, List<String>> map = GffHelperBase.parseNameValuePairs(
-            "hello world", ";", ' ', ", ");
+    Map<String, List<String>> map = GffHelperBase
+            .parseNameValuePairs("hello world", ";", ' ', ", ");
     assertEquals(map.size(), 1);
     assertEquals(map.get("hello").size(), 1);
     assertEquals(map.get("hello").get(0), "world");
 
-    map = GffHelperBase
-            .parseNameValuePairs(
-                    "Method= manual curation ;nothing; Notes=F2 S ; Notes=Metal,Shiny%2Csmooth; Type=",
-                    ";", '=', ",");
+    map = GffHelperBase.parseNameValuePairs(
+            "Method= manual curation ;nothing; Notes=F2 S ; Notes=Metal,Shiny%2Csmooth; Type=",
+            ";", '=', ",");
 
     // Type is ignored as no value was supplied
     assertEquals(map.size(), 2);
@@ -213,8 +212,46 @@ public class GffHelperBaseTest
   public void testParseAttributeMap()
   {
     Map<String, String> map = GffHelperBase
-            .parseAttributeMap("A=B,C%2C%3D%3B%09%25D");
+            .parseAttributeMap("A=B,C%2C%3D%3B%09%25D,X=Y");
+    assertEquals(map.size(), 2);
+    // value of A is everything up to and excluding ,X=
     assertEquals(map.get("A"), "B,C,=;\t%D");
+    assertEquals(map.get("X"), "Y");
+
+    /*
+     * malformed cases should result in an empty map
+     */
+    map = GffHelperBase.parseAttributeMap("=B=Y");
+    assertTrue(map.isEmpty());
+    // first token should be an attribute name only, no commas
+    map = GffHelperBase.parseAttributeMap("A,B=C");
+    assertTrue(map.isEmpty());
+    // intermediate tokens need at least one comma (value,name=)
+    map = GffHelperBase.parseAttributeMap("A=B=C");
+    assertTrue(map.isEmpty());
+    // last token may have a comma or not
+    map = GffHelperBase.parseAttributeMap("A=B");
+    assertEquals(map.get("A"), "B");
+    map = GffHelperBase.parseAttributeMap("A=B,C");
+    assertEquals(map.get("A"), "B,C");
+    map = GffHelperBase.parseAttributeMap("A");
+    assertTrue(map.isEmpty());
+    map = GffHelperBase.parseAttributeMap("A=");
+    assertTrue(map.isEmpty());
+    map = GffHelperBase.parseAttributeMap("A==C");
+    assertTrue(map.isEmpty());
+    map = GffHelperBase.parseAttributeMap("=A");
+    assertTrue(map.isEmpty());
+    map = GffHelperBase.parseAttributeMap("=");
+    assertTrue(map.isEmpty());
+    map = GffHelperBase.parseAttributeMap(",");
+    assertTrue(map.isEmpty());
+    map = GffHelperBase.parseAttributeMap(" ");
+    assertTrue(map.isEmpty());
+    map = GffHelperBase.parseAttributeMap("");
+    assertTrue(map.isEmpty());
+    map = GffHelperBase.parseAttributeMap("A=B, =C");
+    assertTrue(map.isEmpty());
 
     try
     {