Skip to content

Commit

Permalink
Support spaceBeforeEmptyCloseTag setting with experimental formatter
Browse files Browse the repository at this point in the history
Signed-off-by: Jessica He <[email protected]>
  • Loading branch information
JessicaJHee authored and angelozerr committed Aug 24, 2022
1 parent c053f67 commit 5bfe06a
Showing 1 changed file with 75 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,82 @@
import org.eclipse.lemminx.commons.BadLocationException;
import org.eclipse.lemminx.settings.SharedSettings;
import org.eclipse.lsp4j.TextEdit;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

/**
* XML experimental formatter services tests with setSpaceBeforeEmptyCloseTag setting.
* XML experimental formatter services tests with setSpaceBeforeEmptyCloseTag
* setting.
*
*/
public class XMLFormatterSetSpaceBeforeEmptyCloseTagTest {

@Disabled
@Test
public void testSelfCloseTagSpaceSingleElement() throws BadLocationException {
SharedSettings settings = new SharedSettings();
settings.getFormattingSettings().setSpaceBeforeEmptyCloseTag(true);

String content = "<a/>";
String expected = "<a />";
assertFormat(content, expected, settings,
te(0, 2, 0, 2, " "));
assertFormat(expected, expected, settings);
}

@Test
public void testSelfCloseTagSpaceSingleElementMultipleSpaces() throws BadLocationException {
SharedSettings settings = new SharedSettings();
settings.getFormattingSettings().setSpaceBeforeEmptyCloseTag(true);

String content = "<a />";
String expected = "<a />";
assertFormat(content, expected, settings,
te(0, 2, 0, 11, " "));
assertFormat(expected, expected, settings);
}

@Test
public void testSelfCloseTagSpaceSingleElementNewLine() throws BadLocationException {
SharedSettings settings = new SharedSettings();
settings.getFormattingSettings().setSpaceBeforeEmptyCloseTag(true);

String content = "<a\r\n" + //
" />";
String expected = "<a />";
assertFormat(content, expected, settings,
te(0, 2, 1, 2, " "));
assertFormat(expected, expected, settings);
}

@Test
public void testSelfCloseTagSpace() throws BadLocationException {
SharedSettings settings = new SharedSettings();
settings.getFormattingSettings().setSpaceBeforeEmptyCloseTag(true);

String content = "<a>\r" + //
" <b/>\r" + //
String content = "<a>\r\n" + //
" <b/>\r\n" + //
"</a>";
String expected = "<a>\r" + //
" <b />\r" + //
String expected = "<a>\r\n" + //
" <b />\r\n" + //
"</a>";
assertFormat(content, expected, settings);
assertFormat(content, expected, settings,
te(0, 3, 1, 1, "\r\n "),
te(1, 3, 1, 3, " "));
assertFormat(expected, expected, settings);
}

@Test
public void testSelfCloseTagAlreadyHasSpace() throws BadLocationException {
SharedSettings settings = new SharedSettings();
settings.getFormattingSettings().setSpaceBeforeEmptyCloseTag(true);

String content = "<a>\r" + //
" <b />\r" + //
String content = "<a>\r\n" + //
" <b />\r\n" + //
"</a>";
String expected = "<a>\r" + //
" <b />\r" + //
String expected = "<a>\r\n" + //
" <b />\r\n" + //
"</a>";
assertFormat(content, expected, settings, //
te(0, 3, 1, 1, "\r "));
te(0, 3, 1, 1, "\r\n "));
assertFormat(expected, expected, settings);
}

Expand All @@ -62,45 +101,47 @@ public void testSelfCloseTagSpaceFalse() throws BadLocationException {
SharedSettings settings = new SharedSettings();
settings.getFormattingSettings().setSpaceBeforeEmptyCloseTag(false);

String content = "<a>\r" + //
" <b/>\r" + //
String content = "<a>\r\n" + //
" <b/>\r\n" + //
"</a>";
String expected = "<a>\r" + //
" <b/>\r" + //
String expected = "<a>\r\n" + //
" <b/>\r\n" + //
"</a>";
assertFormat(content, expected, settings, //
te(0, 3, 1, 1, "\r "));
te(0, 3, 1, 1, "\r\n "));
assertFormat(expected, expected, settings);
}

@Disabled
@Test
public void testSelfCloseTagSpaceFalseAlreadyHasSpace() throws BadLocationException {
SharedSettings settings = new SharedSettings();
settings.getFormattingSettings().setSpaceBeforeEmptyCloseTag(false);

String content = "<a>\r" + //
" <b />\r" + //
String content = "<a>\r\n" + //
" <b />\r\n" + //
"</a>";
String expected = "<a>\r" + //
" <b/>\r" + //
String expected = "<a>\r\n" + //
" <b/>\r\n" + //
"</a>";
assertFormat(content, expected, settings);
assertFormat(content, expected, settings,
te(0, 3, 1, 1, "\r\n "),
te(1, 3, 1, 4, ""));
assertFormat(expected, expected, settings);
}

@Test
public void testDontAddClosingBracket() throws BadLocationException {
SharedSettings settings = new SharedSettings();
settings.getFormattingSettings().setSpaceBeforeEmptyCloseTag(false);

String content = "<a>\r" + //
" <b\r" + //
String content = "<a>\r\n" + //
" <b\r\n" + //
"</a>";
String expected = "<a>\r" + //
" <b\r" + //
String expected = "<a>\r\n" + //
" <b\r\n" + //
"</a>";
assertFormat(content, expected, settings, //
te(0, 3, 1, 1, "\r "));
te(0, 3, 1, 1, "\r\n "));
assertFormat(expected, expected, settings);

}
Expand All @@ -110,14 +151,14 @@ public void testEndTagMissingCloseBracket() throws BadLocationException {
SharedSettings settings = new SharedSettings();
settings.getFormattingSettings().setSpaceBeforeEmptyCloseTag(false);

String content = "<a>\r" + //
" <b> Value </b\r" + //
String content = "<a>\r\n" + //
" <b> Value </b\r\n" + //
"</a>";
String expected = "<a>\r" + //
" <b> Value </b\r" + //
String expected = "<a>\r\n" + //
" <b> Value </b\r\n" + //
"</a>";
assertFormat(content, expected, settings, //
te(0, 3, 1, 1, "\r "));
te(0, 3, 1, 1, "\r\n "));
assertFormat(expected, expected, settings);
}

Expand Down

0 comments on commit 5bfe06a

Please sign in to comment.