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
This commit is contained in:
Josh Johnson 2018-01-30 17:25:49 -05:00
parent 09fe37f04b
commit 27433b47ce
8 changed files with 34 additions and 15 deletions

View File

@ -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 += ">";
}

View File

@ -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");
});
});
});

View File

@ -0,0 +1,3 @@
<Node>
<Node name="testChild"/>
</Node>

View File

@ -0,0 +1 @@
<Node><Node name="testChild"/></Node>

View File

@ -0,0 +1,6 @@
<Tag>
<Tag2>
Text1
Text2
</Tag2>
</Tag>

View File

@ -0,0 +1,6 @@
<Tag>
<Tag2>
Text1
Text2
</Tag2>
</Tag>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<Имя>
<element>text</element>
</Имя>

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Имя><element>text</element></Имя>