public void TestEndsWith_String_String_String() { CMLStack stack = new CMLStack(); stack.Push("first"); stack.Push("second"); stack.Push("third"); Assert.IsTrue(stack.EndsWith("first", "second", "third")); }
public void TestSize() { CMLStack stack = new CMLStack(); Assert.AreEqual(0, stack.Count); stack.Push("first"); Assert.AreEqual(1, stack.Count); stack.Push("second"); Assert.AreEqual(2, stack.Count); stack.Push("third"); Assert.AreEqual(3, stack.Count); }
public void TestCurrent() { CMLStack stack = new CMLStack(); stack.Push("first"); Assert.AreEqual("first", stack.Peek()); stack.Push("second"); Assert.AreEqual("second", stack.Peek()); stack.Push("third"); Assert.AreEqual("third", stack.Peek()); stack.Pop(); Assert.AreEqual("second", stack.Peek()); stack.Pop(); Assert.AreEqual("first", stack.Peek()); }
public void TestPush_String() { // the class has a hardcoded default length. Test going beyond this. CMLStack stack = new CMLStack(); for (int i = 0; i < 100; i++) { stack.Push("element"); } }
public void TestPop() { CMLStack stack = new CMLStack(); stack.Push("first"); stack.Push("second"); stack.Push("third"); Assert.AreEqual("third", stack.Pop()); Assert.AreEqual("second", stack.Pop()); Assert.AreEqual("first", stack.Pop()); try { Assert.AreEqual("doesNotExist", stack.Pop()); Assert.Fail("Should have received an ArrayIndexOutOfBoundsException"); } catch (Exception) { // OK, should happen } }
public override void StartDocument() { conv.StartDocument(); conventionStack.Push("CML"); moduleStack.Push(conv); }
public override void StartElement(XElement element) { var uri = element.Name.NamespaceName; var local = element.Name.LocalName; xpath.Push(element.Name.LocalName); Debug.WriteLine($"<{element.Value}> -> {xpath}"); // Detect CML modules, like CRML and CCML if (local.StartsWith("reaction", StringComparison.Ordinal)) { // e.g. reactionList, reaction -> CRML module Trace.TraceInformation("Detected CRML module"); if (!string.Equals(conventionStack.Peek(), "CMLR", StringComparison.Ordinal)) { conv = new CMLReactionModule(conv); } conventionStack.Push("CMLR"); } else if (string.IsNullOrEmpty(uri) || uri.StartsWith("http://www.xml-cml.org/", StringComparison.Ordinal)) { // assume CML Core // Detect conventions string convName = ""; if (element.Attribute(Attribute_convention) != null) { convName = element.Attribute(Attribute_convention).Value; } if (convName.Length == 0) { // no convention set/reset: take convention of parent conventionStack.Push(conventionStack.Peek()); } else if (convName.Length > 0) { if (convName.Equals(conventionStack.Peek(), StringComparison.Ordinal)) { Debug.WriteLine("Same convention as parent"); } else { Trace.TraceInformation($"New Convention: {convName}"); switch (convName) { case "CML": // Don't reset the convention handler to CMLCore, // becuase all handlers should extend this handler, and // use it for any content other then specifically put // into the specific convention break; case "PDB": conv = new PDBConvention(conv); break; case "PMP": conv = new PMPConvention(conv); break; case "MDLMol": Debug.WriteLine("MDLMolConvention instantiated..."); conv = new MDLMolConvention(conv); break; case "JMOL-ANIMATION": conv = new JMOLANIMATIONConvention(conv); break; default: if (userConventions.ContainsKey(convName)) { //unknown convention. userConvention? var newconv = userConventions[convName]; newconv.Inherit(conv); conv = newconv; } else { Trace.TraceWarning($"Detected unknown convention: {convName}"); } break; } } conventionStack.Push(convName); } else { // no convention set/reset: take convention of parent conventionStack.Push(conventionStack.Peek()); } } else { conv = new OtherNamespace(); conventionStack.Push("Other"); } moduleStack.Push(conv); Debug.WriteLine($"ConventionStack: {conventionStack}"); conv.StartElement(xpath, element); }