diff --git a/platform/platform-tests/testData/newGeneralFormatter/1.xml b/platform/platform-tests/testData/newGeneralFormatter/1.xml
deleted file mode 100644
index 4b579a73c734..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/1.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/2.xml b/platform/platform-tests/testData/newGeneralFormatter/2.xml
deleted file mode 100644
index d0d3124daaa7..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/2.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/3.xml b/platform/platform-tests/testData/newGeneralFormatter/3.xml
deleted file mode 100644
index 1d24df16f159..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/3.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/4.xml b/platform/platform-tests/testData/newGeneralFormatter/4.xml
deleted file mode 100644
index c079be024ae2..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/4.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/5.xml b/platform/platform-tests/testData/newGeneralFormatter/5.xml
deleted file mode 100644
index 616ba529f5fc..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/5.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/6.xml b/platform/platform-tests/testData/newGeneralFormatter/6.xml
deleted file mode 100644
index 8f9d25dcf27d..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/6.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/chopDownIfLong.xml b/platform/platform-tests/testData/newGeneralFormatter/chopDownIfLong.xml
deleted file mode 100644
index 849352ffa562..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/chopDownIfLong.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/continuationIndent.xml b/platform/platform-tests/testData/newGeneralFormatter/continuationIndent.xml
deleted file mode 100644
index a2e5397d3bca..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/continuationIndent.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/defaultContinuationIndent.xml b/platform/platform-tests/testData/newGeneralFormatter/defaultContinuationIndent.xml
deleted file mode 100644
index 74e6903fc03d..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/defaultContinuationIndent.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/differentWraps.xml b/platform/platform-tests/testData/newGeneralFormatter/differentWraps.xml
deleted file mode 100644
index 04aa38125820..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/differentWraps.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/multipleWrap.xml b/platform/platform-tests/testData/newGeneralFormatter/multipleWrap.xml
deleted file mode 100644
index f762d8718ce3..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/multipleWrap.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/nestedCalls.xml b/platform/platform-tests/testData/newGeneralFormatter/nestedCalls.xml
deleted file mode 100644
index 13c637ba89ea..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/nestedCalls.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/nestedIndents.xml b/platform/platform-tests/testData/newGeneralFormatter/nestedIndents.xml
deleted file mode 100644
index eb1e09b7f815..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/nestedIndents.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/removeAllSpaces.xml b/platform/platform-tests/testData/newGeneralFormatter/removeAllSpaces.xml
deleted file mode 100644
index 22d37e2408bc..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/removeAllSpaces.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/wrapAlways.xml b/platform/platform-tests/testData/newGeneralFormatter/wrapAlways.xml
deleted file mode 100644
index eaa0a36a76d0..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/wrapAlways.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/wrapAsNeeded.xml b/platform/platform-tests/testData/newGeneralFormatter/wrapAsNeeded.xml
deleted file mode 100644
index 6762d13a9f8e..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/wrapAsNeeded.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testData/newGeneralFormatter/wrapAtMiddle.xml b/platform/platform-tests/testData/newGeneralFormatter/wrapAtMiddle.xml
deleted file mode 100644
index 09e37d1f54e5..000000000000
--- a/platform/platform-tests/testData/newGeneralFormatter/wrapAtMiddle.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/platform/platform-tests/testSrc/com/intellij/formatting/GeneralCodeFormatterTest.java b/platform/platform-tests/testSrc/com/intellij/formatting/GeneralCodeFormatterTest.java
index 162338d82a5d..2fd210ae7625 100644
--- a/platform/platform-tests/testSrc/com/intellij/formatting/GeneralCodeFormatterTest.java
+++ b/platform/platform-tests/testSrc/com/intellij/formatting/GeneralCodeFormatterTest.java
@@ -5,64 +5,10 @@ import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.util.IncorrectOperationException;
-import org.jdom.JDOMException;
import org.jetbrains.annotations.NonNls;
-import java.io.IOException;
-
@NonNls
public class GeneralCodeFormatterTest extends LightPlatformTestCase {
- private int myRightMargin = 120;
-
- public void testDefaultContinuationIndent() throws Exception {
- doTest("defaultContinuationIndent", "aaa bbb ccc\nddd eee fff", "aaa bbb ccc\n" +
- " ddd eee fff");
- }
-
- public void testContinuationIndent() throws Exception {
- doTest("4", "a\nb\nc", "a\n" +
- " b\n" +
- " c");
- }
-
- public void testContinuationIndent2() throws Exception{
- doTest("5", "a\nb\nc", "a\n" +
- " b\n" +
- " c");
- }
-
- public void testParentContinuationIndent() throws Exception {
- doTest("continuationIndent", "a\nb\nc\nd\ne\nf",
- "a\n" +
- " b\n" +
- " c\n" +
- " d\n" +
- " e\n" +
- " f");
- }
-
- public void test1() throws Exception {
- doTest("1", "aaa bbb\nccc ddd\neee\nfff",
- "aaa bbb\n" +
- " ccc ddd\n" +
- " eee\n" +
- " fff");
- }
-
- public void test2() throws Exception {
- doTest("2", "aaa bbb\nccc ddd\neee\nfff", "aaa bbb\n" +
- " ccc ddd\n" +
- " eee\n" +
- " fff");
- }
-
- public void testNestedIndents() throws IOException, JDOMException {
- String before = "xxx\n" +
- "yyy";
- String after = "xxx\n" +
- " yyy";
- doTest("nestedIndents", before, after);
- }
public void testLastLineIndent() throws Exception{
final String initialText = "a\n";
@@ -74,7 +20,7 @@ public class GeneralCodeFormatterTest extends LightPlatformTestCase {
indentOptions.INDENT_SIZE = 4;
indentOptions.LABEL_INDENT_SIZE = 1;
final CodeStyleSettings settings = new CodeStyleSettings(false);
- settings.setDefaultRightMargin(myRightMargin);
+ settings.setDefaultRightMargin(120);
try {
FormatterEx.getInstanceEx().adjustLineIndent(model, settings, indentOptions, initialText.length() - 1, new TextRange(0, initialText.length()));
}
@@ -86,95 +32,4 @@ public class GeneralCodeFormatterTest extends LightPlatformTestCase {
}
- public void test22() throws Exception {
- doTest("2", "aaa bbb ccc ddd eee\nfff", "aaa bbb ccc ddd eee\n" +
- " fff");
-
- }
-
- public void testSpaceProperties() throws Exception {
- doTest("3",
- "aaa bbb ccc\n" +
- "ddd eee fff",
- "aaa bbb ccc\n" +
- " ddd eee\n" +
- "\n" +
- " fff"
- );
- }
-
- public void testSimpleWrapping() throws Exception {
- doTest("wrapAlways", "aaa bbb ccc ddd eee fff", "aaa\n" +
- "bbb\n" +
- " ccc\n" +
- " ddd\n" +
- " eee\n" +
- " fff");
- myRightMargin = 16;
- doTest("wrapAsNeeded", "aaa bbb ccc ddd eee fff", "aaa bbb ccc\n" +
- " ddd eee fff");
- }
-
- public void testWrapping() throws Exception {
- myRightMargin = 10;
- doTest("chopDownIfLong", "aaa bbb ccc ddd eee fff", "aaa\n" +
- " bbb\n" +
- " ccc\n" +
- " ddd\n" +
- " eee\n" +
- " fff");
- myRightMargin = 20;
- doTest("wrapAtMiddle", "aaa bbb ccc ddd eee fff", "aaa bbb ccc\n" +
- " ddd eee fff");
-
- }
-
- public void testMultipleWrap() throws Exception {
- myRightMargin = 2;
- doTest("multipleWrap", "abc", "ab\n c");
- }
-
- public void testDifferentWraps() throws Exception {
- myRightMargin = 10;
- doTest("differentWraps", "(ab)(cd)(ef)", "(ab)(cd)\n" +
- "(ef)");
-
- }
-
- public void testNestedCalls2() throws Exception{
- doTest("nestedCalls",
- "1 a2 b3\nc",
- "1 a2 b3\n" +
- " c");
-
- }
- public void testRemoveAllSpaces() throws Exception{
- doTest("removeAllSpaces",
- "0 1\n2\n3\t4 5\n6 7 8\t9 ",
- "0123456789 ");
- }
-
- private void doTest(final String formattingModelName,
- final String initial,
- final String expected) throws IOException, JDOMException {
- final TestFormattingModel model = new TestFormattingModel(initial);
-
- model.setRootBlock(new FormattingModelXmlReader(model).readTestBlock(formattingModelName));
- final CommonCodeStyleSettings.IndentOptions indentOptions = new CommonCodeStyleSettings.IndentOptions();
- indentOptions.CONTINUATION_INDENT_SIZE = 8;
- indentOptions.INDENT_SIZE = 4;
- indentOptions.LABEL_INDENT_SIZE = 1;
- final CodeStyleSettings settings = new CodeStyleSettings(false);
- settings.setDefaultRightMargin(myRightMargin);
- try {
- FormatterEx.getInstanceEx().format(model, settings, indentOptions, indentOptions, null);
- }
- catch (IncorrectOperationException e) {
- fail();
- }
-
- assertEquals(expected, FormatterImpl.getText(model));
- }
-
-
}
diff --git a/platform/platform-tests/testSrc/com/intellij/formatting/TestModelBuilder.kt b/platform/platform-tests/testSrc/com/intellij/formatting/TestModelBuilder.kt
index 5ad23f223877..c10e082d7243 100644
--- a/platform/platform-tests/testSrc/com/intellij/formatting/TestModelBuilder.kt
+++ b/platform/platform-tests/testSrc/com/intellij/formatting/TestModelBuilder.kt
@@ -15,7 +15,6 @@
*/
package com.intellij.formatting
-import com.intellij.formatting.*
import com.intellij.formatting.engine.testModel.TestBlock
import com.intellij.openapi.util.TextRange
@@ -24,11 +23,29 @@ class BlockAttributes(val alignment: Alignment? = null, val wrap: Wrap? = null,
class CompositeTestBlock(startOffset: Int,
attributes: BlockAttributes,
- private val children: List) : TestBlockBase(startOffset, attributes)
-{
+ private val children: List) : TestBlockBase(startOffset, attributes) {
override fun getSubBlocks() = children
override fun isLeaf() = false
override val endOffset = children.last().endOffset
+
+ override fun getSpacing(child1: Block?, child2: Block): Spacing? {
+ val right: TestBlockBase = child2 as TestBlockBase
+ if (right.getSpacing() != null) {
+ return right.getSpacing()
+ }
+
+ val offset = child2.startOffset
+ var firstBlock = child2.firstChild() as? TestBlockBase
+ while (firstBlock != null && offset == firstBlock.startOffset) {
+ val spacing = firstBlock.getSpacing()
+ if (spacing != null) {
+ return spacing
+ }
+ firstBlock = firstBlock.firstChild() as? TestBlockBase
+ }
+
+ return null
+ }
}
class LeafTestBlock(startOffset: Int, attributes: BlockAttributes, val text: String) : TestBlockBase(startOffset, attributes) {
@@ -38,7 +55,7 @@ class LeafTestBlock(startOffset: Int, attributes: BlockAttributes, val text: Str
}
abstract class TestBlockBase(val startOffset: Int,
- private val attributes: BlockAttributes) : Block {
+ val attributes: BlockAttributes) : Block {
override fun getAlignment() = attributes.alignment
override fun getTextRange() = TextRange(startOffset, endOffset)
@@ -46,32 +63,92 @@ abstract class TestBlockBase(val startOffset: Int,
override fun getIndent() = attributes.indent
override fun getSpacing(child1: Block?, child2: Block) = attributes.spacing
+ fun getSpacing() = attributes.spacing
+ fun firstChild() = subBlocks.firstOrNull()
+
override fun getChildAttributes(newChildIndex: Int): ChildAttributes = ChildAttributes.DELEGATE_TO_NEXT_CHILD
override fun isIncomplete() = false
abstract val endOffset: Int
-
+
}
class AttributesProvider {
-
+
private val alignments = hashMapOf()
-
+ private val wraps = hashMapOf()
+
fun extract(text: String): BlockAttributes {
- val attributes: List = text.split(",").map(String::trim)
+ val attributes: List = text.split(" ").map(String::trim)
+
val alignment = getAlignment(attributes)
- return BlockAttributes(alignment = alignment)
+ val indent = getIndent(attributes)
+ val spacing = getSpacing(attributes)
+ val wrap = getWrap(attributes)
+
+ return BlockAttributes(alignment, wrap, indent, spacing)
+ }
+
+ private fun getWrap(attributes: List): Wrap? {
+ val wrap = attributes.find { it.startsWith("w_") }?.substring(2) ?: return null
+ val matcher = "([a-z]*)([0-9]*)".toPattern().matcher(wrap)
+ if (!matcher.matches()) return null
+
+ val type = matcher.group(1)
+ val id = matcher.group(2)
+
+ return when (type) {
+ "normal" -> Wrap.createWrap(WrapType.NORMAL, true)
+ "always" -> Wrap.createWrap(WrapType.ALWAYS, true)
+ "chop" -> getChopWrapById(id)
+ else -> null
+ }
+ }
+
+ private fun getChopWrapById(id: String): Wrap {
+ val wrap = wraps[id]
+ if (wrap != null) {
+ return wrap
+ }
+ wraps[id] = Wrap.createWrap(WrapType.CHOP_DOWN_IF_LONG, true)
+ return getChopWrapById(id)
+ }
+
+ private fun getSpacing(attributes: List): Spacing? {
+ val spaceProperties = attributes.find { it.startsWith("s_") }?.substring(2)?.split("_") ?: return null
+
+ val minSpaces = spaceProperties.getPropertyValue("min") ?: 1
+ val maxSpaces = spaceProperties.getPropertyValue("max") ?: 100
+ val minLfs = spaceProperties.getPropertyValue("minlf") ?: 0
+ val keepLineBreaks = if (spaceProperties.getPropertyValue("keepLb") == 0) false else true
+
+ return Spacing.createSpacing(minSpaces, maxSpaces, minLfs, keepLineBreaks, 100)
+ }
+
+ private fun List.getPropertyValue(name: String): Int? {
+ return find { it.startsWith(name) }?.substring(name.length)?.toInt()
+ }
+
+ private fun getIndent(attributes: List): Indent? {
+ val type = attributes.find { it.startsWith("i_") }?.substring(2)
+ return when (type) {
+ "cont" -> Indent.getContinuationIndent()
+ "none" -> Indent.getNoneIndent()
+ "norm" -> Indent.getNormalIndent()
+ "label" -> Indent.getLabelIndent()
+ else -> null
+ }
}
private fun getAlignment(attributes: List): Alignment? {
val index = attributes.find { it.startsWith("a") }?.substring(1)?.toInt()
if (index == null || index < 0) return null
-
+
var alignment = alignments[index]
if (alignment != null) {
return alignment
}
-
+
alignment = AlignmentImpl(true, Alignment.Anchor.LEFT)
alignments[index] = alignment
return alignment
@@ -79,15 +156,15 @@ class AttributesProvider {
}
-fun TestBlock.Composite.toFormattingBlock(startOffset: Int): CompositeTestBlock {
+fun TestBlock.Composite.toFormattingBlock(startOffset: Int,
+ attributesProvider: AttributesProvider = AttributesProvider()): CompositeTestBlock {
val childBlocks = mutableListOf()
- val attributesProvider = AttributesProvider()
var previousStartOffset = startOffset
-
+
children.forEach {
val block = when (it) {
is TestBlock.Composite -> {
- val composite = it.toFormattingBlock(previousStartOffset)
+ val composite = it.toFormattingBlock(previousStartOffset, attributesProvider)
previousStartOffset = composite.endOffset
composite
}
diff --git a/platform/platform-tests/testSrc/com/intellij/formatting/engine/FormatterEngineTests.kt b/platform/platform-tests/testSrc/com/intellij/formatting/engine/FormatterEngineTests.kt
index 33b0479ea06c..8b1447ebf0dd 100644
--- a/platform/platform-tests/testSrc/com/intellij/formatting/engine/FormatterEngineTests.kt
+++ b/platform/platform-tests/testSrc/com/intellij/formatting/engine/FormatterEngineTests.kt
@@ -15,13 +15,11 @@
*/
package com.intellij.formatting.engine
-import com.intellij.formatting.FormatTextRanges
-import com.intellij.formatting.FormatterImpl
+import com.intellij.formatting.FormatterEx
import com.intellij.formatting.engine.testModel.TestFormattingModel
import com.intellij.formatting.engine.testModel.getRoot
import com.intellij.formatting.toFormattingBlock
import com.intellij.openapi.editor.EditorFactory
-import com.intellij.openapi.util.TextRange
import com.intellij.psi.codeStyle.CodeStyleSettings
import com.intellij.testFramework.LightPlatformTestCase
import junit.framework.TestCase
@@ -58,19 +56,23 @@ go boo
}
-fun doTest(before: String, expectedText: String) {
- val root = getRoot(before.trimStart())
+fun doTest(before: String, expectedText: String, settings: CodeStyleSettings = CodeStyleSettings()) {
+ var root = getRoot(before.trimStart())
+ var beforeText = root.text
+
+ val rightMargin = beforeText.indexOf('|')
+ if (rightMargin > 0) {
+ settings.setRightMargin(null, rightMargin)
+ root = getRoot(before.trimStart().replace("|", ""))
+ beforeText = root.text
+ }
+
val rootFormattingBlock = root.toFormattingBlock(0)
- val beforeText = root.text
val document = EditorFactory.getInstance().createDocument(beforeText)
val model = TestFormattingModel(rootFormattingBlock, document)
- val settings = CodeStyleSettings()
- val textRanges = FormatTextRanges(TextRange(0, document.textLength - 1), true)
+ FormatterEx.getInstanceEx().format(model, settings, settings.indentOptions, null)
- val formatter = FormatterImpl()
- formatter.format(model, settings, settings.indentOptions, textRanges)
-
- TestCase.assertEquals(document.text, expectedText.trimStart())
+ TestCase.assertEquals(expectedText.trimStart(), document.text)
}
\ No newline at end of file
diff --git a/platform/platform-tests/testSrc/com/intellij/formatting/engine/GeneralCodeFormatterTest.kt b/platform/platform-tests/testSrc/com/intellij/formatting/engine/GeneralCodeFormatterTest.kt
new file mode 100644
index 000000000000..da5d7f4f9b50
--- /dev/null
+++ b/platform/platform-tests/testSrc/com/intellij/formatting/engine/GeneralCodeFormatterTest.kt
@@ -0,0 +1,318 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.formatting.engine
+
+import com.intellij.psi.codeStyle.CodeStyleSettings
+import com.intellij.testFramework.LightPlatformTestCase
+import org.junit.Test
+
+/**
+ * Just a GeneralCodeFormatterTest.java migration to simplified formatting model specification
+ */
+class GeneralCodeFormatterTest : LightPlatformTestCase() {
+
+ @Test
+ fun `test null indent is treated as continuation indent`() {
+ doTest(
+ """
+[]aaa []bbb []ccc
+[]ddd []eee []fff
+""",
+ """
+aaa bbb ccc
+ ddd eee fff
+"""
+ )
+ }
+
+ @Test
+ fun `test continuation indent`() {
+ doTest(
+ """
+[i_none]a
+[i_none]([i_cont]b
+[i_cont]c)
+""",
+ """
+a
+ b
+ c
+"""
+ )
+ }
+
+ @Test
+ fun `test normal indent`() {
+ doTest(
+ """
+[i_none]a
+[i_none]([i_norm]b
+[i_norm]c)
+""",
+ """
+a
+ b
+ c
+"""
+ )
+ }
+
+ @Test
+ fun `test many nested blocks and continuation indent`() {
+ doTest(
+ """
+[]([]([]([]a
+[]b
+[]([]([]c
+[]d
+[]([]e
+[]f))))))
+""",
+ """
+a
+ b
+ c
+ d
+ e
+ f
+"""
+ )
+ }
+
+ @Test
+ fun `test indents composition`() {
+ val settings = CodeStyleSettings()
+ settings.indentOptions!!.LABEL_INDENT_SIZE = 1
+ doTest("""
+[i_none]aaa [i_none]bbb
+[i_none]([i_norm]ccc [i_norm]ddd
+[i_norm]([i_label]eee
+[i_label]fff))
+""",
+ """
+aaa bbb
+ ccc ddd
+ eee
+ fff
+""", settings)
+ }
+
+ @Test
+ fun `test alignments on different block levels`() {
+ doTest(
+ """
+[]aaa [a1]bbb
+[a1]([i_label]ccc [i_label]ddd
+[i_label a1]([]eee
+[a1]fff))
+""",
+ """
+aaa bbb
+ ccc ddd
+ eee
+ fff
+"""
+ )
+ }
+
+ @Test
+ fun `test nested indents`() {
+ doTest(
+ """
+[]xxx
+[i_cont]([i_cont]([i_cont]yyy))
+""",
+ """
+xxx
+ yyy
+"""
+ )
+ }
+
+ @Test
+ fun `test one more alignment test`() {
+ doTest(
+ """
+[]aaa [a1]bbb [a1]([i_label]ccc [i_label]ddd [i_label a1]([]eee
+[a1]fff))
+""",
+ """
+aaa bbb ccc ddd eee
+ fff
+"""
+ )
+ }
+
+ @Test
+ fun `test trivial spaces`() {
+ doTest(
+ """
+[]foo [s_min3]goo
+""",
+ """
+foo goo
+"""
+ )
+ }
+
+ @Test
+ fun `test space properties`() {
+ val settings = CodeStyleSettings()
+ settings.indentOptions!!.LABEL_INDENT_SIZE = 1
+ doTest(
+ """
+[]aaa [s_min2_max2]bbb [s_min2_max2]([i_norm]ccc
+[i_norm s_min2_max2]ddd [i_norm s_min2_max2]([i_label]eee [i_label s_min2_max2_minlf2]fff))
+""",
+ """
+aaa bbb ccc
+ ddd eee
+
+ fff
+""", settings)
+ }
+
+ @Test
+ fun `test remove all spaces`() {
+ doTest(
+ """
+[s_min0_max0_keepLb0]0 [s_min0_max0_keepLb0]1
+[s_min0_max0_keepLb0]2
+[s_min0_max0_keepLb0]3 [s_min0_max0_keepLb0]4 [s_min0_max0_keepLb0]5
+[s_min0_max0_keepLb0]6 [s_min0_max0_keepLb0]7 [s_min0_max0_keepLb0]8 [s_min0_max0_keepLb0]9 """,
+ "0123456789 ")
+ }
+
+ @Test
+ fun `test no wrap object no text wrap`() {
+ doTest("[]aaa []bbb []ccc []ddd []eee []f|ff", "aaa bbb ccc ddd eee fff")
+ }
+
+ @Test
+ fun `test simple wrap`() {
+ doTest(
+ """
+[]aaa [w_normal i_cont]b|bb
+""",
+ """
+aaa
+ bbb
+""")
+ }
+
+ @Test
+ fun `test wrap`() {
+ val settings = CodeStyleSettings()
+ settings.indentOptions!!.LABEL_INDENT_SIZE = 1
+
+ doTest(
+"[i_none w_always]aaa " +
+"[i_none s_min2_max2 w_always]bbb " +
+"[i_none s_min2_max2]" +
+ "([i_label w_always]ccc " +
+ "[i_label s_min2_max2 w_always]ddd " +
+ "[i_label s_min2_max2]([w_always]eee " +
+ "[s_min2_max2 w_always]fff))",
+
+"""
+aaa
+bbb
+ ccc
+ ddd
+ eee
+ fff""", settings)
+ }
+
+ @Test
+ fun `test wrap one more time`() {
+ val settings = CodeStyleSettings()
+ settings.indentOptions!!.LABEL_INDENT_SIZE = 1
+
+ doTest(
+"[w_normal]aaa " +
+"[s_min2_max2 w_normal]bbb " +
+"[s_min2_max2 w_normal]" +
+ "([i_label]ccc " +
+ "[i_label s_min2_max2 w_normal]ddd |" +
+ "[i_label s_min2_max2 w_normal]" +
+ "([]eee [s_min2_max2 w_normal]fff))",
+"""aaa bbb ccc
+ ddd eee fff""", settings)
+ }
+
+ @Test
+ fun `test chop down`() {
+ val settings = CodeStyleSettings()
+ settings.indentOptions!!.LABEL_INDENT_SIZE = 1
+
+ doTest(
+ "[w_chop1]aaa [s_min2_max2 w_chop1]bbb " +
+ "[]([i_label s_min2_max2 w_chop1]cc|c " +
+ "[i_label s_min2_max2 w_chop1]ddd " +
+ "[i_label]([s_min2_max2 w_chop1]eee [s_min2_max2 w_chop1]fff))",
+"""
+aaa
+ bbb
+ ccc
+ ddd
+ eee
+ fff""",
+ settings)
+ }
+
+ @Test
+ fun `test wrap in the middle`() {
+ val settings = CodeStyleSettings()
+ settings.indentOptions!!.LABEL_INDENT_SIZE = 1
+ doTest(
+ "[]aaa [s_min2_max2]bbb " +
+ "[]" +
+ "([i_label s_min2_max2]ccc " +
+ "[i_label s_min2_max2 w_normal]ddd " +
+ "[i_label]" +
+ "([s_min2_max2]eee [s_min2_max2]|fff))",
+"""
+aaa bbb ccc
+ ddd eee fff""", settings)
+ }
+
+
+ @Test
+ fun `test multiple wrap`() {
+ doTest("[w_normal]a[w_normal]b|[w_normal]([w_normal]c)",
+ "ab\n" +
+ " c")
+
+ }
+
+ @Test
+ fun `test nested calls`() {
+ doTest("[i_none]1 [i_none]([i_cont]a[i_none]([i_cont]2 [i_none]([i_cont]b[i_none]([i_cont]3\n[i_none]([i_cont]c)))))",
+"""
+1 a2 b3
+ c""")
+ }
+
+ @Test
+ fun `test different wraps`() {
+ doTest(
+ "[i_none w_normal]([w_normal]x[w_normal]a[w_normal]b[w_normal]x)" +
+ "[i_none w_normal]([w_normal]x[w_normal]c[w_normal]d[w_normal]x)" +
+ "[i_none w_normal]([w_normal]x[w_normal]e[w_normal]|f[w_normal]x)",
+ "xabxxcdx\nxefx")
+ }
+
+}
\ No newline at end of file