X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FDnaUtilsTest.java;h=fbc95ad6e0f61169f0866205fc0832c399691503;hb=a28768a635abf715690fe991326dc7e650f37049;hp=af76885ba19d017a8b8deb4bd94a5f4e2357a49d;hpb=a4507b66add69be7e5097dcc8fbd9bd08b0626cb;p=jalview.git diff --git a/test/jalview/util/DnaUtilsTest.java b/test/jalview/util/DnaUtilsTest.java index af76885..fbc95ad 100644 --- a/test/jalview/util/DnaUtilsTest.java +++ b/test/jalview/util/DnaUtilsTest.java @@ -4,6 +4,7 @@ import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNull; import static org.testng.AssertJUnit.fail; +import java.text.ParseException; import java.util.List; import org.testng.annotations.Test; @@ -13,15 +14,25 @@ public class DnaUtilsTest /** * Tests for parsing an ENA/GenBank location specifier * + * @throws ParseException + * * @see http://www.insdc.org/files/feature_table.html#3.4 */ @Test(groups = { "Functional" }) - public void testParseLocation() + public void testParseLocation() throws ParseException { /* + * single locus + */ + List ranges = DnaUtils.parseLocation("467"); + assertEquals(1, ranges.size()); + assertEquals(467, ranges.get(0)[0]); + assertEquals(467, ranges.get(0)[1]); + + /* * simple range */ - List ranges = DnaUtils.parseLocation("12..78"); + ranges = DnaUtils.parseLocation("12..78"); assertEquals(1, ranges.size()); assertEquals(12, ranges.get(0)[0]); assertEquals(78, ranges.get(0)[1]); @@ -83,17 +94,21 @@ public class DnaUtilsTest /* * valid things we don't yet handle */ - assertNull(DnaUtils.parseLocation("<34..126")); - assertNull(DnaUtils.parseLocation("34..>126")); - assertNull(DnaUtils.parseLocation("34.126")); - assertNull(DnaUtils.parseLocation("34^126")); + checkForParseException("<34..126"); + checkForParseException("35..>126"); + checkForParseException("34.126"); + checkForParseException("34^126"); + checkForParseException("order(34..126,130..180)"); /* * invalid things */ - assertNull(DnaUtils.parseLocation("")); - assertNull(DnaUtils.parseLocation("JOIN(1..2)")); - assertNull(DnaUtils.parseLocation("join(1..2")); + checkForParseException(""); + checkForParseException("JOIN(1..2)"); + checkForParseException("join(1..2"); + checkForParseException("join(1..2("); + checkForParseException("complement(1..2"); + checkForParseException("complement(1..2("); try { assertNull(DnaUtils.parseLocation(null)); @@ -102,6 +117,34 @@ public class DnaUtilsTest { // expected } + + /* + * nested joins are not allowed; just as well since this fails to parse + * (splitting tokens by comma fragments the inner join expression) + */ + checkForParseException("join(1..2,join(4..5,10..12),18..22)"); + /* + * complement may not enclose multiple ranges + * parsing fails for the same reason + */ + checkForParseException("join(complement(36618..36700,4000..4200),86988..87064)"); + } + + /** + * Verifies that a ParseException is thrown when the given location is parsed + * + * @param location + */ + void checkForParseException(String location) + { + try + { + DnaUtils.parseLocation(location); + fail("Expected exception"); + } catch (ParseException e) + { + // expected; + } } }