const xmlMatcher = require("../xml-matcher.js");
const { expect } = require("./utils");
const xmlprettify = require("./xml-prettify");
describe("XmlMatcher", function () {
it("should work with simple tag", function () {
const 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 () {
const 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 () {
const matcher = xmlMatcher(' ', [
"w:spacing",
]);
expect(matcher.matches.length).to.be.equal(1);
expect(matcher.matches[0].array[0]).to.be.equal(
''
);
});
it("should work with no tag, with w:t", function () {
const matcher = xmlMatcher("Text1Text2", ["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(0);
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(11);
});
it("should work with no tag, no w:t", function () {
const matcher = xmlMatcher("Text1", ["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(0);
});
it("should not match with no starter", function () {
const 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 () {
const matcher = xmlMatcher("Text1TAG", ["w:t"]);
expect(matcher.matches.length).to.be.equal(1);
});
});
describe("XML prettify", function () {
it("should sort attributes", function () {
const str =
'';
const prettified = xmlprettify(str);
expect(prettified).to
.equal(`
`);
});
it("should remove space inside tags", function () {
const str = `
Property
0 $
`;
const prettified = xmlprettify(str);
expect(prettified).to
.equal(`
Property
0 $
`);
});
});