diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMAttributeFormatter.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMAttributeFormatter.java index 66107467d..705ddad05 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMAttributeFormatter.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMAttributeFormatter.java @@ -15,6 +15,8 @@ import org.eclipse.lemminx.dom.DOMAttr; import org.eclipse.lsp4j.TextEdit; +import org.eclipse.lemminx.settings.EnforceQuoteStyle; +import org.eclipse.lemminx.utils.StringUtils; /** * DOM attribute formatter. @@ -77,6 +79,24 @@ public void formatAttribute(DOMAttr attr, int prevOffset, boolean singleAttribut removeLeftSpaces(delimiterOffset, attrValueStart, edits); } } + + // replace current quote with preferred quote in case of attribute value + // ex: if preferred quote is single quote (') + // + // --> + String originalValue = attr.getOriginalValue(); + if (getEnforceQuoteStyle() == EnforceQuoteStyle.preferred && originalValue != null) { + if (originalValue.charAt(0) != getQuotationAsChar() + && StringUtils.isQuote(originalValue.charAt(0))) { + formatterDocument.replaceQuoteWithPreferred(attr.getNodeAttrValue().getStart(), + attr.getNodeAttrValue().getStart() + 1, getQuotationAsString(), edits); + } + if (originalValue.charAt(originalValue.length() - 1) != getQuotationAsChar() + && StringUtils.isQuote(originalValue.charAt(originalValue.length() - 1))) { + formatterDocument.replaceQuoteWithPreferred(attr.getNodeAttrValue().getEnd() - 1, + attr.getNodeAttrValue().getEnd(), getQuotationAsString(), edits); + } + } } private void replaceLeftSpacesWithOneSpace(int from, int to, List edits) { @@ -108,4 +128,15 @@ private boolean hasLineBreak(int prevOffset, int start) { return formatterDocument.hasLineBreak(prevOffset, start); } + private char getQuotationAsChar() { + return formatterDocument.getSharedSettings().getPreferences().getQuotationAsChar(); + } + + private String getQuotationAsString() { + return formatterDocument.getSharedSettings().getPreferences().getQuotationAsString(); + } + + private EnforceQuoteStyle getEnforceQuoteStyle() { + return formatterDocument.getSharedSettings().getFormattingSettings().getEnforceQuoteStyle(); + } } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMDocTypeFormatter.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMDocTypeFormatter.java index 2035d6072..10f746f90 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMDocTypeFormatter.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/DOMDocTypeFormatter.java @@ -20,6 +20,8 @@ import org.eclipse.lemminx.dom.DTDDeclParameter; import org.eclipse.lsp4j.TextEdit; import org.w3c.dom.Node; +import org.eclipse.lemminx.settings.EnforceQuoteStyle; +import org.eclipse.lemminx.utils.StringUtils; /** * DOM docType formatter. @@ -52,21 +54,38 @@ public void formatDocType(DOMDocumentType docType, XMLFormattingConstraints pare constraints.setIndentLevel(constraints.getIndentLevel() + 1); formatDTD(docType, constraints, start, end, edits); } - } - } - DTDDeclParameter internalSubset = docType.getInternalSubsetNode(); - if (internalSubset == null) { - if (docType.isClosed()) { - int endDocType = docType.getEnd() - 1; - removeLeftSpaces(endDocType, edits); + if (getEnforceQuoteStyle() == EnforceQuoteStyle.preferred) { + int quoteStart = getDocTypeIdStart(docType); + int quoteEnd = getDocTypeIdEnd(docType); + + if (quoteStart != -1 && quoteEnd != -1) { + // replace current quote with preferred quote in the case: + // + formatterDocument.replaceQuoteWithPreferred(quoteStart, + quoteStart + 1, getQuotationAsString(), edits); + formatterDocument.replaceQuoteWithPreferred(quoteEnd - 1, + quoteEnd, getQuotationAsString(), edits); + } } - } else { - int endDocType = internalSubset.getEnd() - 1; - String lineDelimiter = formatterDocument.getLineDelimiter(); - replaceLeftSpacesWith(endDocType, lineDelimiter, edits); } } + DTDDeclParameter internalSubset = docType.getInternalSubsetNode(); + if (internalSubset == null) { + if (docType.isClosed()) { + // Remove space between content and end bracket in case of no internal subset + // Example: + int endDocType = docType.getEnd() - 1; + removeLeftSpaces(endDocType, edits); + } + } else { + // Add new line at end of internal subset + // |]> + int endDocType = internalSubset.getEnd() - 1; + String lineDelimiter = formatterDocument.getLineDelimiter(); + replaceLeftSpacesWith(endDocType, lineDelimiter, edits); + } } private void formatDTD(DOMDocumentType docType, XMLFormattingConstraints parentConstraints, int start, int end, @@ -75,20 +94,22 @@ private void formatDTD(DOMDocumentType docType, XMLFormattingConstraints parentC for (DOMNode child : docType.getChildren()) { switch (child.getNodeType()) { - case DOMNode.DTD_ELEMENT_DECL_NODE: - case DOMNode.DTD_ATT_LIST_NODE: - case Node.ENTITY_NODE: - case DOMNode.DTD_NOTATION_DECL: - DTDDeclNode nodeDecl = (DTDDeclNode) child; - formatDTDNodeDecl(nodeDecl, parentConstraints, addLineSeparator, edits); - addLineSeparator = true; - break; - - default: - // unknown, so just leave alone for now but make sure to update - // available line width - int width = updateLineWidthWithLastLine(child, parentConstraints.getAvailableLineWidth()); - parentConstraints.setAvailableLineWidth(width); + case DOMNode.DTD_ELEMENT_DECL_NODE: + case DOMNode.DTD_ATT_LIST_NODE: + case Node.ENTITY_NODE: + case DOMNode.DTD_NOTATION_DECL: + // Format DTD node declaration, for example: + // + DTDDeclNode nodeDecl = (DTDDeclNode) child; + formatDTDNodeDecl(nodeDecl, parentConstraints, addLineSeparator, edits); + addLineSeparator = true; + break; + + default: + // unknown, so just leave alone for now but make sure to update + // available line width + int width = updateLineWidthWithLastLine(child, parentConstraints.getAvailableLineWidth()); + parentConstraints.setAvailableLineWidth(width); } } } @@ -114,7 +135,13 @@ private void formatDTDNodeDecl(DTDDeclNode nodeDecl, XMLFormattingConstraints pa List internalDecls = attlist.getInternalChildren(); if (internalDecls == null) { for (DTDDeclParameter parameter : attlist.getParameters()) { + // Normalize space at the start of parameter to a single space for ATTLIST, for + // example: + // replaceLeftSpacesWithOneSpace(parameter.getStart(), edits); + // replace current quote with preferred quote in the case: + // + replaceQuoteWithPreferred(nodeDecl, parameter, edits); } } else { boolean multipleInternalAttlistDecls = false; @@ -152,7 +179,13 @@ private void formatDTDNodeDecl(DTDDeclNode nodeDecl, XMLFormattingConstraints pa List parameters = nodeDecl.getParameters(); if (!parameters.isEmpty()) { for (DTDDeclParameter parameter : parameters) { + // Normalize space at the start of parameter to a single space for non-ATTLIST, + // for example: + // replaceLeftSpacesWithOneSpace(parameter.getStart(), edits); + // replace current quote with preferred quote in the case: + // + replaceQuoteWithPreferred(nodeDecl, parameter, edits); } } } @@ -175,4 +208,44 @@ private void removeLeftSpaces(int to, List edits) { formatterDocument.removeLeftSpaces(to, edits); } + private String getQuotationAsString() { + return formatterDocument.getSharedSettings().getPreferences().getQuotationAsString(); + } + + private EnforceQuoteStyle getEnforceQuoteStyle() { + return formatterDocument.getSharedSettings().getFormattingSettings().getEnforceQuoteStyle(); + } + + private static int getDocTypeIdStart(DOMDocumentType docType) { + if (docType.getPublicIdNode() != null) { + return docType.getPublicIdNode().getStart(); + } else if (docType.getSystemIdNode() != null) { + return docType.getSystemIdNode().getStart(); + } else + return -1; + } + + private static int getDocTypeIdEnd(DOMDocumentType docType) { + if (docType.getPublicIdNode() != null) { + return docType.getPublicIdNode().getEnd(); + } else if (docType.getSystemIdNode() != null) { + return docType.getSystemIdNode().getEnd(); + } else + return -1; + } + + private void replaceQuoteWithPreferred(DTDDeclNode nodeDecl, DTDDeclParameter parameter, List edits) { + int paramStart = parameter.getStart(); + int paramEnd = parameter.getEnd(); + if (StringUtils.isQuote(nodeDecl.getOwnerDocument().getText().charAt(paramStart)) && + StringUtils.isQuote(nodeDecl.getOwnerDocument().getText().charAt(paramEnd - 1))) { + if (getEnforceQuoteStyle() == EnforceQuoteStyle.preferred) { + formatterDocument.replaceQuoteWithPreferred(paramStart, + paramStart + 1, getQuotationAsString(), edits); + formatterDocument.replaceQuoteWithPreferred(paramEnd - 1, + paramEnd, getQuotationAsString(), edits); + + } + } + } } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/TextEditUtils.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/TextEditUtils.java index e8295f187..60cd278b0 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/TextEditUtils.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/TextEditUtils.java @@ -20,6 +20,7 @@ import org.eclipse.lemminx.commons.BadLocationException; import org.eclipse.lemminx.commons.TextDocument; +import org.eclipse.lemminx.utils.StringUtils; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextEdit; @@ -92,6 +93,12 @@ public static TextEdit createTextEditIfNeeded(int from, int to, String expectedC matchExpectedContent = to - from == expectedContent.length(); } + // Set parameters to handle case when replacing single quote with double quote and vice versa + if (from == to && !expectedContent.isEmpty() && StringUtils.isQuote(expectedContent.toCharArray()[0])) { + from--; + matchExpectedContent = false; + } + if (!matchExpectedContent) { try { Position endPos = textDocument.positionAt(to); diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/XMLFormatterDocumentNew.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/XMLFormatterDocumentNew.java index bf12a4937..bd9efdac5 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/XMLFormatterDocumentNew.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/format/XMLFormatterDocumentNew.java @@ -329,6 +329,10 @@ void replaceLeftSpacesWith(int leftLimit, int to, String replacement, List edits){ + createTextEditIfNeeded(from, to, replacement, edits); + } + private int getLeftWhitespacesOffset(int leftLimit, int to) { String text = textDocument.getText(); int from = leftLimit != -1 ? leftLimit : to - 1; diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/TextEditUtilsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/TextEditUtilsTest.java index 3d5930ab3..db5dd3654 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/TextEditUtilsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/TextEditUtilsTest.java @@ -50,4 +50,13 @@ public void textEdit2() { assertNotNull(edit); assertEquals(te(0, 2, 0, 4, " "), edit); } + + @Test + public void textEditQuote() { + TextDocument document = new TextDocument(" ", "test.xml"); + TextEdit edit = TextEditUtils.createTextEditIfNeeded(8, 9, "\"", document); + assertNotNull(edit); + assertEquals(te(0, 8, 0, 9, "\""), edit); + } + } diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/experimental/XMLFormatterQuoteStyleTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/experimental/XMLFormatterQuoteStyleTest.java index 8fe3afe75..356a5d251 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/experimental/XMLFormatterQuoteStyleTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/format/experimental/XMLFormatterQuoteStyleTest.java @@ -19,7 +19,6 @@ import org.eclipse.lemminx.settings.QuoteStyle; import org.eclipse.lemminx.settings.SharedSettings; import org.eclipse.lsp4j.TextEdit; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ */ public class XMLFormatterQuoteStyleTest { - @Disabled @Test public void testUseDoubleQuotesFromDoubleQuotes() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -36,22 +34,22 @@ public void testUseDoubleQuotesFromDoubleQuotes() throws BadLocationException { settings.getPreferences().setQuoteStyle(QuoteStyle.doubleQuotes); String content = " "; - String expected = ""; + String expected = " "; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testUseSingleQuotesFromSingleQuotes() throws BadLocationException { SharedSettings settings = new SharedSettings(); settings.getPreferences().setQuoteStyle(QuoteStyle.singleQuotes); settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); String content = " "; - String expected = ""; + String expected = " "; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testUseSingleQuotesFromDoubleQuotes() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -59,43 +57,83 @@ public void testUseSingleQuotesFromDoubleQuotes() throws BadLocationException { settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); String content = " "; - String expected = ""; + String expected = " "; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testUseDoubleQuotesFromSingleQuotes() throws BadLocationException { SharedSettings settings = new SharedSettings(); settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); String content = " "; - String expected = ""; + String expected = " "; + assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); + } + + @Test + public void testUseDoubleQuotesFromSingleQuotesUnclosedEnd() throws BadLocationException { + SharedSettings settings = new SharedSettings(); + settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); + String content = " "; + String expected = " "; + assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); + } + + @Test + public void testUseDoubleQuotesFromSingleQuotesUnclosedStart() throws BadLocationException { + SharedSettings settings = new SharedSettings(); + settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); + String content = " "; + String expected = " "; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); + } + + @Test + public void testUseDoubleQuotesFromSingleQuotesMisMatchStart() throws BadLocationException { + SharedSettings settings = new SharedSettings(); + settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); + String content = " "; + String expected = " "; + assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); + } + + @Test + public void testUseDoubleQuotesFromSingleQuotesMisMatchEnd() throws BadLocationException { + SharedSettings settings = new SharedSettings(); + settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); + String content = " "; + String expected = " "; + assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testUseSingleQuotesNoQuotes() throws BadLocationException { SharedSettings settings = new SharedSettings(); settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); settings.getPreferences().setQuoteStyle(QuoteStyle.singleQuotes); String content = " "; - String expected = ""; + String expected = " "; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testUseSingleQuotesNoQuotesSplit() throws BadLocationException { SharedSettings settings = new SharedSettings(); settings.getPreferences().setQuoteStyle(QuoteStyle.singleQuotes); settings.getFormattingSettings().setSplitAttributes(true); String content = " "; - String expected = ""; + String expected = " "; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testAttValueOnlyStartQuote() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -103,30 +141,30 @@ public void testAttValueOnlyStartQuote() throws BadLocationException { String content = " "; String expected = " "; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testUseDoubleQuotesMultipleAttributes() throws BadLocationException { SharedSettings settings = new SharedSettings(); settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); String content = " "; - String expected = ""; + String expected = " "; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testUseSingleQuotesMultipleAttributes() throws BadLocationException { SharedSettings settings = new SharedSettings(); settings.getPreferences().setQuoteStyle(QuoteStyle.singleQuotes); settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); String content = " "; - String expected = ""; + String expected = " "; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testUseDoubleQuotesMultipleAttributesSplit() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -135,11 +173,11 @@ public void testUseDoubleQuotesMultipleAttributesSplit() throws BadLocationExcep String content = " \n"; String expected = ""; + " name3=\" value3 \"> "; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testUseSingleQuotesMultipleAttributesSplit() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -148,11 +186,11 @@ public void testUseSingleQuotesMultipleAttributesSplit() throws BadLocationExcep settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); String content = " \n"; String expected = ""; + " name3=\' value3 \'> "; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testUseSingleQuotesLocalDTD() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -161,9 +199,31 @@ public void testUseSingleQuotesLocalDTD() throws BadLocationException { String content = ""; String expected = ""; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); + } + + @Test + public void testUseSingleQuotesLocalDTDUnclosedStart() throws BadLocationException { + SharedSettings settings = new SharedSettings(); + settings.getPreferences().setQuoteStyle(QuoteStyle.singleQuotes); + settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); + String content = ""; + String expected = ""; + assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); + } + + @Test + public void testUseSingleQuotesLocalDTDUnclosedEnd() throws BadLocationException { + SharedSettings settings = new SharedSettings(); + settings.getPreferences().setQuoteStyle(QuoteStyle.singleQuotes); + settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); + String content = ""; + String expected = ""; + assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testUseSingleQuotesLocalDTDWithSubset() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -188,9 +248,36 @@ public void testUseSingleQuotesLocalDTDWithSubset() throws BadLocationException "\n" + // ""; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); + } + + @Test + public void testUseSingleQuotesLocalDTDWithSubsetUnclosed() throws BadLocationException { + SharedSettings settings = new SharedSettings(); + settings.getPreferences().setQuoteStyle(QuoteStyle.singleQuotes); + settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); + String content = "\n" + // + " \n" + // + " \n" + // + " \n" + // + " \n" + // + "]>\n" + // + "\n" + // + ""; + String expected = "\n" + // + " \n" + // + " \n" + // + " \n" + // + " \n" + // + "]>\n" + // + "\n" + // + ""; + assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testUseSingleQuotesDTDFile() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -207,6 +294,7 @@ public void testUseSingleQuotesDTDFile() throws BadLocationException { "\n" + // ""; assertFormat(content, expected, settings, "test.dtd"); + assertFormat(expected, expected, settings); } @Test @@ -218,9 +306,9 @@ public void testDontFormatQuotesByDefault() throws BadLocationException { assertFormat(content, expected, settings); settings.getPreferences().setQuoteStyle(QuoteStyle.doubleQuotes); assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void testAttributeNameTouchingPreviousValue() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -238,9 +326,9 @@ public void testAttributeNameTouchingPreviousValue() throws BadLocationException " aa>\r\n" + // ""; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void enforceSingleQuoteStyle() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -253,7 +341,6 @@ public void enforceSingleQuoteStyle() throws BadLocationException { assertFormat(expected, expected, settings); } - @Disabled @Test public void enforceDoubleQuoteStyle() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -266,7 +353,6 @@ public void enforceDoubleQuoteStyle() throws BadLocationException { assertFormat(expected, expected, settings); } - @Disabled @Test public void enforceSingleQuoteStyleProlog() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -279,7 +365,6 @@ public void enforceSingleQuoteStyleProlog() throws BadLocationException { assertFormat(expected, expected, settings); } - @Disabled @Test public void enforceDoubleQuoteStyleProlog() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -292,7 +377,18 @@ public void enforceDoubleQuoteStyleProlog() throws BadLocationException { assertFormat(expected, expected, settings); } - @Disabled + @Test + public void enforceDoubleQuoteStyleProlo() throws BadLocationException { + SharedSettings settings = new SharedSettings(); + settings.getPreferences().setQuoteStyle(QuoteStyle.doubleQuotes); + settings.getFormattingSettings().setEnforceQuoteStyle(EnforceQuoteStyle.preferred); + + String content = ""; + String expected = ""; + assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); + } + @Test public void dontEnforceSingleQuoteStyle() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -302,6 +398,7 @@ public void dontEnforceSingleQuoteStyle() throws BadLocationException { String content = ""; String expected = ""; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } @Test @@ -313,6 +410,7 @@ public void dontEnforceSingleQuoteStyleProlog() throws BadLocationException { String content = ""; String expected = content; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } @Test @@ -324,9 +422,9 @@ public void dontEnforceDoubleQuoteStyleProlog() throws BadLocationException { String content = ""; String expected = content; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - @Disabled @Test public void dontEnforceDoubleQuoteStyle() throws BadLocationException { SharedSettings settings = new SharedSettings(); @@ -336,16 +434,17 @@ public void dontEnforceDoubleQuoteStyle() throws BadLocationException { String content = ""; String expected = ""; assertFormat(content, expected, settings); + assertFormat(expected, expected, settings); } - private static void assertFormat(String unformatted, String expected, SharedSettings sharedSettings, - TextEdit... expectedEdits) throws BadLocationException { - assertFormat(unformatted, expected, sharedSettings, "test://test.html", expectedEdits); + private static void assertFormat(String unformatted, String expected, SharedSettings sharedSettings) + throws BadLocationException { + assertFormat(unformatted, expected, sharedSettings, "test://test.html"); } - private static void assertFormat(String unformatted, String expected, SharedSettings sharedSettings, String uri, - TextEdit... expectedEdits) throws BadLocationException { - assertFormat(unformatted, expected, sharedSettings, uri, true, expectedEdits); + private static void assertFormat(String unformatted, String expected, SharedSettings sharedSettings, String uri) + throws BadLocationException { + assertFormat(unformatted, expected, sharedSettings, uri, true, (TextEdit[]) null); } private static void assertFormat(String unformatted, String expected, SharedSettings sharedSettings, String uri,