forked from external/vscode-xml
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:
parent
09fe37f04b
commit
27433b47ce
@ -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 += ">";
|
||||
}
|
||||
|
@ -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");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
3
src/test/test-data/self-closing.formatted.xml
Normal file
3
src/test/test-data/self-closing.formatted.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<Node>
|
||||
<Node name="testChild"/>
|
||||
</Node>
|
1
src/test/test-data/self-closing.unformatted.xml
Normal file
1
src/test/test-data/self-closing.unformatted.xml
Normal file
@ -0,0 +1 @@
|
||||
<Node><Node name="testChild"/></Node>
|
6
src/test/test-data/text-only-line.formatted.xml
Normal file
6
src/test/test-data/text-only-line.formatted.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<Tag>
|
||||
<Tag2>
|
||||
Text1
|
||||
Text2
|
||||
</Tag2>
|
||||
</Tag>
|
6
src/test/test-data/text-only-line.unformatted.xml
Normal file
6
src/test/test-data/text-only-line.unformatted.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<Tag>
|
||||
<Tag2>
|
||||
Text1
|
||||
Text2
|
||||
</Tag2>
|
||||
</Tag>
|
4
src/test/test-data/unicode.formatted.xml
Normal file
4
src/test/test-data/unicode.formatted.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Имя>
|
||||
<element>text</element>
|
||||
</Имя>
|
2
src/test/test-data/unicode.unformatted.xml
Normal file
2
src/test/test-data/unicode.unformatted.xml
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Имя><element>text</element></Имя>
|
Loading…
Reference in New Issue
Block a user