JAL-3518 separation of ChimeraXManager, pull up of closeViewer etc
[jalview.git] / test / jalview / structure / AtomSpecTest.java
index ea53131..9881baf 100644 (file)
@@ -71,4 +71,68 @@ public class AtomSpecTest
       // ok
     }
   }
+
+  @Test
+  public void testFromChimeraXAtomSpec()
+  {
+    AtomSpec as = AtomSpec.fromChimeraXAtomspec("#1/B:12");
+    assertEquals(as.getModelNumber(), 1);
+    assertEquals(as.getPdbResNum(), 12);
+    assertEquals(as.getChain(), "B");
+    assertNull(as.getPdbFile());
+  
+    // no model - default to zero
+    as = AtomSpec.fromChimeraXAtomspec("/C:13");
+    assertEquals(as.getModelNumber(), 0);
+    assertEquals(as.getPdbResNum(), 13);
+    assertEquals(as.getChain(), "C");
+    assertNull(as.getPdbFile());
+  
+    // model.submodel
+    as = AtomSpec.fromChimeraXAtomspec("#3.2/:15");
+    assertEquals(as.getModelNumber(), 3);
+    assertEquals(as.getPdbResNum(), 15);
+    assertEquals(as.getChain(), "");
+    assertNull(as.getPdbFile());
+  
+    String spec = "3:12.B";
+    try
+    {
+      as = AtomSpec.fromChimeraXAtomspec(spec);
+      fail("Expected exception for " + spec);
+    } catch (IllegalArgumentException e)
+    {
+      // ok
+    }
+  
+    spec = "#3:12-14.B";
+    try
+    {
+      as = AtomSpec.fromChimeraXAtomspec(spec);
+      fail("Expected exception for " + spec);
+    } catch (IllegalArgumentException e)
+    {
+      // ok
+    }
+  
+    spec = "";
+    try
+    {
+      as = AtomSpec.fromChimeraXAtomspec(spec);
+      fail("Expected exception for " + spec);
+    } catch (IllegalArgumentException e)
+    {
+      // ok
+    }
+  
+    spec = null;
+    try
+    {
+      as = AtomSpec.fromChimeraXAtomspec(spec);
+      fail("Expected exception for " + spec);
+    } catch (NullPointerException e)
+    {
+      // ok
+    }
+  }
 }