From f156845afbb02f7973ec8a1deba711130a65a141 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Wed, 1 Jul 2020 23:12:48 -0400 Subject: [PATCH] Add Failing Test --- src/test/extension.test.ts | 29 +++++++++++++++++++++ src/test/test-data/issue-262.minified.xml | 13 +++++++++ src/test/test-data/issue-262.unminified.xml | 18 +++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 src/test/test-data/issue-262.minified.xml create mode 100644 src/test/test-data/issue-262.unminified.xml diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index a4368e9..77ef70e 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -101,6 +101,26 @@ describe("V2XmlFormatter", () => { }); }); + describe("#minifyXml(xml, options)", () => { + + const options = { + editorOptions: { + insertSpaces: true, + tabSize: 4 + }, + enforcePrettySelfClosingTagOnFormat: false, + newLine: "\r\n", + removeCommentsOnMinify: false, + splitAttributesOnFormat: false, + splitXmlnsOnFormat: true + }; + + it("should preserve whitespace on minify if xml:space is set to 'preserve-whitespace'", () => { + testMinifier(xmlFormatter, options, "issue-262"); + }); + + }); + }); function testFormatter(xmlFormatter: XmlFormatter, options: XmlFormattingOptions, fileLabel: string): void { @@ -111,3 +131,12 @@ function testFormatter(xmlFormatter: XmlFormatter, options: XmlFormattingOptions assert.equal(actualFormattedXml, expectedFormattedXml, "Actual formatted XML does not match expected formatted XML."); } + +function testMinifier(xmlFormatter: XmlFormatter, options: XmlFormattingOptions, fileLabel: string): void { + const expectedMinifiedXml = TestDataLoader.load(`${fileLabel}.minified.xml`); + const unminifiedXml = TestDataLoader.load(`${fileLabel}.unminified.xml`); + + const actualMinifiedXml = xmlFormatter.minifyXml(unminifiedXml, options); + + assert.equal(actualMinifiedXml, expectedMinifiedXml, "Actual minified XML does not match expected minified XML."); +} diff --git a/src/test/test-data/issue-262.minified.xml b/src/test/test-data/issue-262.minified.xml new file mode 100644 index 0000000..beed2a0 --- /dev/null +++ b/src/test/test-data/issue-262.minified.xml @@ -0,0 +1,13 @@ +1. +2. +3. +4.1. +2. +3. +4.1. + 2. + 3. + 4.1. + 2. + 3. + 4. \ No newline at end of file diff --git a/src/test/test-data/issue-262.unminified.xml b/src/test/test-data/issue-262.unminified.xml new file mode 100644 index 0000000..023f4e0 --- /dev/null +++ b/src/test/test-data/issue-262.unminified.xml @@ -0,0 +1,18 @@ + +1. +2. +3. +4. +1. +2. +3. +4. +1. + 2. + 3. + 4. +1. + 2. + 3. + 4. + \ No newline at end of file