Xml.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { XmlElement } from "../../../src/Common/FileIO/Xml.ts";
  2. let xml_test_data: string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE score-partwise PUBLIC \"-//Recordare//DTD MusicXML 2.0 Partwise//EN\" \"http://www.musicxml.org/dtds/partwise.dtd\"><score-partwise> <identification> <encoding> <software>Example Software Name</software> <encoding-date>2016-04-04</encoding-date> </encoding> </identification> <credit page=\"1\"> <credit-words justify=\"center\" valign=\"top\">Example Credit Words</credit-words> </credit> </score-partwise>";
  3. describe("XML Unit Tests", () => {
  4. let parser: DOMParser = new DOMParser();
  5. let doc: Document = parser.parseFromString(xml_test_data, "text/xml");
  6. let documentElement: XmlElement = new XmlElement(doc.documentElement);
  7. it("XmlElement Tests", (done: MochaDone) => {
  8. // Test Name attribute
  9. chai.expect(documentElement.Name).to.equal("score-partwise");
  10. // Test Element method
  11. chai.should().exist(documentElement.Element("identification"));
  12. // Test Value attribute
  13. chai.expect(documentElement
  14. .Element("identification")
  15. .Element("encoding")
  16. .Element("software").Value).to.equal("Example Software Name");
  17. done();
  18. });
  19. it("XmlAttribute Tests", (done: MochaDone) => {
  20. // Test Attributes method
  21. chai.expect(
  22. documentElement.Element("credit").Attributes()[0].Name
  23. ).to.equal("page");
  24. let creditWords: XmlElement =
  25. documentElement.Element("credit").Element("credit-words");
  26. // Test Attributes method
  27. chai.expect(creditWords.Attributes().length).to.equal(2);
  28. // Test Value attribute
  29. chai.expect(creditWords.Attribute("justify").Value).to.equal("center");
  30. done();
  31. });
  32. });