vscode-xml/src/test/extension.test.ts

66 lines
2.1 KiB
TypeScript
Raw Normal View History

2018-01-27 18:01:04 -05:00
import * as assert from "assert";
2018-01-30 16:45:10 -05:00
import { FormattingOptions } from "vscode";
import { TestDataLoader } from "./test-utils/test-data-loader";
2018-05-03 22:01:29 -04:00
import { XmlFormatter, XmlFormattingOptions } from "../formatting";
import { V2XmlFormatter } from "../formatting/formatters";
2018-01-30 16:45:10 -05:00
describe("V2XmlFormatter", () => {
const xmlFormatter = new V2XmlFormatter();
describe("#formatXml(xml, options)", () => {
2018-01-27 17:50:50 -05:00
2018-01-30 16:45:10 -05:00
const options = {
editorOptions: {
insertSpaces: true,
tabSize: 4
},
newLine: "\r\n",
removeCommentsOnMinify: false,
splitAttributesOnFormat: false,
splitXmlnsOnFormat: true
};
it("should handle basic XML", () => {
testFormatter(xmlFormatter, options, "basic");
});
it("should handle unicode element names", () => {
testFormatter(xmlFormatter, options, "unicode");
});
it("should handle self-closing elements", () => {
testFormatter(xmlFormatter, options, "self-closing");
});
it("should handle text-only lines", () => {
testFormatter(xmlFormatter, options, "text-only-line");
});
it("should handle preformatted xml", () => {
testFormatter(xmlFormatter, options, "preformatted");
});
it ("should preserve line breaks between elements", () => {
testFormatter(xmlFormatter, options, "preserve-breaks");
});
2018-02-13 22:52:19 -05:00
it("should maintain comment formatting", () => {
testFormatter(xmlFormatter, options, "maintain-comment-formatting");
});
2018-01-30 16:45:10 -05:00
});
2018-01-27 17:50:50 -05:00
2018-01-27 18:01:04 -05:00
});
2018-01-30 16:45:10 -05:00
function testFormatter(xmlFormatter: XmlFormatter, options: XmlFormattingOptions, fileLabel: string): void {
const expectedFormattedXml = TestDataLoader.load(`${fileLabel}.formatted.xml`);
const unformattedXml = TestDataLoader.load(`${fileLabel}.unformatted.xml`);
const actualFormattedXml = xmlFormatter.formatXml(unformattedXml, options);
assert.equal(actualFormattedXml, expectedFormattedXml, "Actual formatted XML does not match expected formatted XML.");
}