Xml.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. var Xml_ts_1 = require("../../../src/Common/FileIO/Xml.ts");
  3. // Test XML simple document
  4. var xmlTestData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
  5. <!DOCTYPE score-partwise PUBLIC \"-//Recordare//DTD MusicXML 2.0 Partwise//EN\" \"http://www.musicxml.org/dtds/partwise.dtd\">\
  6. <score-partwise> <identification> <encoding> <software>Example Software name</software> \
  7. <encoding-date>2016-04-04</encoding-date> </encoding> </identification> <credit page=\"1\"> \
  8. <credit-words justify=\"center\" valign=\"top\">Example Credit Words</credit-words> </credit> </score-partwise>";
  9. describe("XML interface", function () {
  10. var parser = new DOMParser();
  11. var doc = parser.parseFromString(xmlTestData, "text/xml");
  12. var documentElement = new Xml_ts_1.IXmlElement(doc.documentElement);
  13. it("test IXmlElement", function (done) {
  14. // Test name attribute
  15. chai.expect(documentElement.name).to.equal("score-partwise");
  16. // Test element method
  17. chai.should().exist(documentElement.element("identification"));
  18. // Test value attribute
  19. chai.expect(documentElement
  20. .element("identification")
  21. .element("encoding")
  22. .element("software").value).to.equal("Example Software name");
  23. done();
  24. });
  25. it("test IXmlAttribute", function (done) {
  26. // Test attributes method
  27. chai.expect(documentElement.element("credit").attributes()[0].name).to.equal("page");
  28. var creditWords = documentElement.element("credit").element("credit-words");
  29. // Test attributes method
  30. chai.expect(creditWords.attributes().length).to.equal(2);
  31. // Test value attribute
  32. chai.expect(creditWords.attribute("justify").value).to.equal("center");
  33. done();
  34. });
  35. });