"use strict";
var xmlMatcher = require("../../xml-matcher.js");
var _require = require("../utils.js"),
expect = _require.expect;
var xmlprettify = require("../xml-prettify.js");
describe("XmlMatcher", function () {
it("should work with simple tag", function () {
var matcher = xmlMatcher("Text", ["w:t"]);
expect(matcher.matches[0].array[0]).to.be.equal("Text");
expect(matcher.matches[0].array[1]).to.be.equal("");
expect(matcher.matches[0].array[2]).to.be.equal("Text");
expect(matcher.matches[0].offset).to.be.equal(0);
});
it("should work with multiple tags", function () {
var matcher = xmlMatcher("Text TAG Text2", ["w:t"]);
expect(matcher.matches[1].array[0]).to.be.equal("Text2");
expect(matcher.matches[1].array[1]).to.be.equal("");
expect(matcher.matches[1].array[2]).to.be.equal("Text2");
expect(matcher.matches[1].offset).to.be.equal(20);
});
it("should work with selfclosing tag", function () {
var matcher = xmlMatcher(' ', ["w:spacing"]);
expect(matcher.matches.length).to.be.equal(1);
expect(matcher.matches[0].array[0]).to.be.equal('');
});
it("should not match with no starter", function () {
var matcher = xmlMatcher("TAGText1", ["w:t"]);
expect(matcher.matches[0].array[0]).to.be.equal("Text1");
expect(matcher.matches[0].array[1]).to.be.equal("");
expect(matcher.matches[0].array[2]).to.be.equal("Text1");
expect(matcher.matches[0].offset).to.be.equal(3);
});
it("should not match with no ender", function () {
var matcher = xmlMatcher("Text1TAG", ["w:t"]);
expect(matcher.matches.length).to.be.equal(1);
});
});
describe("XML prettify", function () {
it("should work with > inside attribute", function () {
var str = xmlprettify("\n \"/>");
expect(str).to.equal("\n\"/>\n");
});
it("should deduplicate xmlns:w", function () {
var str = '';
str = xmlprettify(str);
expect(str).to.equal("\n \n\n");
});
it("should normalize d", function () {
var str = '';
str = xmlprettify(str);
expect(str).to.equal("\n");
});
it("should sort attributes", function () {
var str = '';
var prettified = xmlprettify(str);
expect(prettified).to.equal("\n\n\n\n");
});
it("should remove space inside tags", function () {
var str = "\n\t\n\t\t\n\t\t\tProperty\n\t\t\n\t\t\n\t\t\t0 $\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t";
var prettified = xmlprettify(str);
expect(prettified).to.equal("\n\n \n Property\n \n \n 0 $\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n");
});
it("should work with processing instruction : ", function () {
var str = xmlprettify("\n\n\n DocumentLibraryForm\n DocumentLibraryForm\n DocumentLibraryForm\n");
expect(str).to.equal("\n\n\n DocumentLibraryForm\n DocumentLibraryForm\n DocumentLibraryForm\n\n");
});
});