X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fio%2Fgff%2FGffHelperBaseTest.java;h=5bd60a80c2749da1203a2f08b55b87bc757d96a1;hb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;hp=de4e8205ea358c65db965b3a1e42aa931d100176;hpb=9135cbb74bbff06ea60485540194515ebcc018b0;p=jalview.git diff --git a/test/jalview/io/gff/GffHelperBaseTest.java b/test/jalview/io/gff/GffHelperBaseTest.java index de4e820..5bd60a8 100644 --- a/test/jalview/io/gff/GffHelperBaseTest.java +++ b/test/jalview/io/gff/GffHelperBaseTest.java @@ -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> map = GffHelperBase.parseNameValuePairs( - "hello world", ";", ' ', ", "); + Map> 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 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 {