From 27433b47cea84fcbff36311185e04bb98bad421b Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Tue, 30 Jan 2018 17:25:49 -0500 Subject: [PATCH] Add Tests for Fixed Issues This commit also changes the "fix" for text-only lines. We should be adjusting the text content as little as possible. In this case, we are still adding spaces (or tabs) after the last line break, but that is necessary to indent the closing element. I'll continue to adjust this as needed based on feedback and possibly add a setting to gate this behavior. #137 --- src/formatting/formatters/v2-xml-formatter.ts | 15 --------------- src/test/extension.test.ts | 12 ++++++++++++ src/test/test-data/self-closing.formatted.xml | 3 +++ src/test/test-data/self-closing.unformatted.xml | 1 + src/test/test-data/text-only-line.formatted.xml | 6 ++++++ src/test/test-data/text-only-line.unformatted.xml | 6 ++++++ src/test/test-data/unicode.formatted.xml | 4 ++++ src/test/test-data/unicode.unformatted.xml | 2 ++ 8 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 src/test/test-data/self-closing.formatted.xml create mode 100644 src/test/test-data/self-closing.unformatted.xml create mode 100644 src/test/test-data/text-only-line.formatted.xml create mode 100644 src/test/test-data/text-only-line.unformatted.xml create mode 100644 src/test/test-data/unicode.formatted.xml create mode 100644 src/test/test-data/unicode.unformatted.xml diff --git a/src/formatting/formatters/v2-xml-formatter.ts b/src/formatting/formatters/v2-xml-formatter.ts index 19b1dd1..3f85734 100644 --- a/src/formatting/formatters/v2-xml-formatter.ts +++ b/src/formatting/formatters/v2-xml-formatter.ts @@ -121,21 +121,6 @@ export class V2XmlFormatter implements XmlFormatter { output += `>${options.newLine}`; } - // if this is an open tag followed by a line break, add an indent before the text (after the line break) - // TODO: there could be multiple lines of text here, so we'll need a less naive implementation at some point - else if (nc === "\r" || nc === "\n") { - output += `>${options.newLine}${this._getIndent(options, indentLevel)}`; - - // fast-forward based on what type of line break was used - if (nc === "\r") { - i += 2; - } - - else { - i++; - } - } - else { output += ">"; } diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index e5de0ab..7f51b01 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -28,6 +28,18 @@ describe("V2XmlFormatter", () => { 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"); + }); + }); }); diff --git a/src/test/test-data/self-closing.formatted.xml b/src/test/test-data/self-closing.formatted.xml new file mode 100644 index 0000000..e37f362 --- /dev/null +++ b/src/test/test-data/self-closing.formatted.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/test/test-data/self-closing.unformatted.xml b/src/test/test-data/self-closing.unformatted.xml new file mode 100644 index 0000000..c24f1dd --- /dev/null +++ b/src/test/test-data/self-closing.unformatted.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/test/test-data/text-only-line.formatted.xml b/src/test/test-data/text-only-line.formatted.xml new file mode 100644 index 0000000..8c8717d --- /dev/null +++ b/src/test/test-data/text-only-line.formatted.xml @@ -0,0 +1,6 @@ + + +Text1 +Text2 + + \ No newline at end of file diff --git a/src/test/test-data/text-only-line.unformatted.xml b/src/test/test-data/text-only-line.unformatted.xml new file mode 100644 index 0000000..43436ac --- /dev/null +++ b/src/test/test-data/text-only-line.unformatted.xml @@ -0,0 +1,6 @@ + + +Text1 +Text2 + + \ No newline at end of file diff --git a/src/test/test-data/unicode.formatted.xml b/src/test/test-data/unicode.formatted.xml new file mode 100644 index 0000000..a19a993 --- /dev/null +++ b/src/test/test-data/unicode.formatted.xml @@ -0,0 +1,4 @@ + +<Имя> + text + \ No newline at end of file diff --git a/src/test/test-data/unicode.unformatted.xml b/src/test/test-data/unicode.unformatted.xml new file mode 100644 index 0000000..098f43f --- /dev/null +++ b/src/test/test-data/unicode.unformatted.xml @@ -0,0 +1,2 @@ + +<Имя>text \ No newline at end of file