diff --git a/org.eclipse.xtext.xbase.tests/.classpath b/org.eclipse.xtext.xbase.tests/.classpath index c59580bb78..2c3019a9a7 100644 --- a/org.eclipse.xtext.xbase.tests/.classpath +++ b/org.eclipse.xtext.xbase.tests/.classpath @@ -7,13 +7,6 @@ - - - - - - - diff --git a/org.eclipse.xtext.xbase.tests/build.properties b/org.eclipse.xtext.xbase.tests/build.properties index 3d4be68bf1..c387a04a8f 100644 --- a/org.eclipse.xtext.xbase.tests/build.properties +++ b/org.eclipse.xtext.xbase.tests/build.properties @@ -1,5 +1,4 @@ source.. = src/,\ - xtend-gen/,\ longrunning/src/,\ suites/,\ smoke-suites/ diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.java new file mode 100644 index 0000000000..dbb69b0f1d --- /dev/null +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.java @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2012, 2021 itemis AG (http://www.itemis.eu) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.xtext.xbase.tests.formatting; + +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.XtextRunner; +import org.eclipse.xtext.testing.formatter.FormatterTestRequest; +import org.eclipse.xtext.util.Strings; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.google.inject.Inject; + +@RunWith(XtextRunner.class) +@InjectWith(XbaseFormatterTestInjectorProvider.class) +public class XbaseCommentFormatterTest { + @Inject + private XbaseFormatterTester xbaseFormatterTester; + + @Test + public void commentInIfExpression() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String model = + "if (true)\n" + + " println(\"foo\")\n" + + "else // if (true)\n" + + " println(\"bar\")\n" + + "println(\"end\")\n"; + it.setToBeFormatted(Strings.toPlatformLineSeparator(model)); + }); + } + + @Test + public void commentAfterForExpression1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String model = + "for (f : #[])\n" + + " if (1 < 2) {\n" + + " }\n" + + "\n" + + "// foo\n" + + "var lastOffset = \"\"\n"; + it.setToBeFormatted(Strings.toPlatformLineSeparator(model)); + }); + } + + @Test + public void commentAfterForExpression3() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String model = "val ll = #[].map(e|e.toString) // error here\n"; + it.setToBeFormatted(Strings.toPlatformLineSeparator(model)); + }); + } +} diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.xtend b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.xtend deleted file mode 100644 index ee3b6a183c..0000000000 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.xtend +++ /dev/null @@ -1,47 +0,0 @@ -package org.eclipse.xtext.xbase.tests.formatting - -import com.google.inject.Inject -import org.eclipse.xtext.testing.InjectWith -import org.eclipse.xtext.testing.XtextRunner -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(typeof(XtextRunner)) -@InjectWith(typeof(XbaseFormatterTestInjectorProvider)) -class XbaseCommentFormatterTest { - - @Inject extension XbaseFormatterTester - - @Test def commentInIfExpression() { - assertFormattedExpression [ - toBeFormatted = ''' - if (true) - println("foo") - else // if (true) - println("bar") - println("end") - ''' - ] - } - - @Test def commentAfterForExpression1() { - assertFormattedExpression [ - toBeFormatted = ''' - for (f : #[]) - if (1 < 2) { - } - - // foo - var lastOffset = "" - ''' - ] - } - - @Test def commentAfterForExpression3() { - assertFormattedExpression [ - toBeFormatted = ''' - val ll = #[].map(e|e.toString) // error here - ''' - ] - } -} diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterTest.java new file mode 100644 index 0000000000..89027479d5 --- /dev/null +++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterTest.java @@ -0,0 +1,1867 @@ +/** + * Copyright (c) 2012, 2021 itemis AG (http://www.itemis.eu) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.xtext.xbase.tests.formatting; + +import org.eclipse.xtext.preferences.MapBasedPreferenceValues; +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.XtextRunner; +import org.eclipse.xtext.testing.formatter.FormatterTestRequest; +import org.eclipse.xtext.util.Strings; +import org.eclipse.xtext.xbase.formatting2.XbaseFormatterPreferenceKeys; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.google.inject.Inject; + +@RunWith(XtextRunner.class) +@InjectWith(XbaseFormatterTestInjectorProvider.class) +public class XbaseFormatterTest { + @Inject + private XbaseFormatterTester xbaseFormatterTester; + + @Test + public void formatGenerics() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "val x = >newArrayList()\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatBlockExpression() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val x = newArrayList(\"A\", \"b\");\n" + + "val y = 'foo';\n" + + "x.join\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val x = newArrayList(\"A\", \"b\") ; val y = 'foo' ; x.join\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatBlockExpressionPreserveNewLines() { + xbaseFormatterTester.assertFormatted((FormatterTestRequest it) -> { + String string = "{\n" + + "\n" + + " val x = newArrayList(\"A\", \"b\");\n" + + "\n" + + " val y = 'foo'\n" + + "\n" + + " x.join\n" + + "\n" + + "}\n"; + String expectation = string.toString().trim(); + it.setExpectation(Strings.toPlatformLineSeparator(expectation)); + String toBeFormatted = + " { \n" + + "\n" + + "\n" + + "val x = newArrayList(\"A\", \"b\") ;\n" + + "\n" + + "\n" + + "val y = 'foo'\n" + + "\n" + + "\n" + + " x.join\n" + + "\n" + + "\n" + + " }\n"; + it.setToBeFormatted(Strings.toPlatformLineSeparator(toBeFormatted)); + }); + } + + @Test + public void formatClosures() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "val x = newArrayList(\"A\", \"b\")\n" + + "val y = x.filter[toUpperCase == it]\n" + + "y.join\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatClosuresParenthesis() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "val x = newArrayList(\"A\", \"b\")\n" + + "val y = x.filter(toUpperCase == it)\n" + + "y.join\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatClosuresParenthesis2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val x = newArrayList(\"A\", \"b\")\n" + + "val y = x.filter(foo|foo.toUpperCase == foo)\n" + + "y.join\n"; + it.setToBeFormatted(expectation); + }); + } + + @Test + public void formatClosuresSemicolon() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "newArrayList(\"A\", \"b\").filter[val b = it; b.toUpperCase == b]\n"; + it.setExpectation(expectation); + String toBeFormatted = + "newArrayList(\"A\", \"b\").filter[ val b = it ; b.toUpperCase == b ]\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatClosuresEmpty() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val x = newArrayList(\"A\", \"b\")\n" + + "val y = x.filter[]\n" + + "y.join\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val x = newArrayList(\"A\", \"b\") val y = x.filter[ ] y.join\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatClosuresParam() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "val x = newArrayList(\"A\", \"b\")\n" + + "val y = x.filter[z|z.toUpperCase == z]\n" + + "y.join\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatClosuresEmptyParam() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "val Iterable x = [|#[].iterator]\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatClosuresMultiLine() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val x = newArrayList(\"A\", \"b\")\n" + + "val y = x.filter [\n" + + " val z = it\n" + + " z.toUpperCase == z\n" + + "]\n" + + "y.join\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val x = newArrayList(\"A\", \"b\") val y = x.filter [\n" + + " val z = it z.toUpperCase == z \n" + + "] y.join\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatClosuresMultiLine_02() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val x = newArrayList(\"A\", \"b\")\n" + + "val y = x.filter [\n" + + " val z = it\n" + + " z.toUpperCase == z\n" + + "]\n" + + "y.join\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val x = newArrayList(\"A\", \"b\") val y = x.filter[\n" + + " val z = it z.toUpperCase == z \n" + + "] y.join\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatClosuresMultiLine03() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "new Thread [|\n" + + " println(\"foo\")\n" + + "]\n"; + it.setExpectation(expectation); + String toBeFormatted = + "new Thread[ | println(\"foo\")\n" + + "]\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatClosuresMultiLineSemicolon() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val x = newArrayList(\"A\", \"b\")\n" + + "val y = x.filter [\n" + + " val z = it;\n" + + " z.toUpperCase == z;\n" + + "]\n" + + "y.join\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val x = newArrayList(\"A\", \"b\") val y = x.filter [\n" + + " val z = it ; z.toUpperCase == z ; \n" + + "] y.join\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatClosuresWrapIfNeeded() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val x = newArrayList(\"A\", \"b\")\n" + + "val y = x.filter [\n" + + " val z = it\n" + + " z.toUpperCase == z\n" + + " z.toUpperCase == z\n" + + " z.toUpperCase == z\n" + + "]\n" + + "y.join\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val x = newArrayList(\"A\", \"b\") val y = x.filter [ val z = it z.toUpperCase == z z.toUpperCase == z z.toUpperCase == z ] y.join\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatClosuresParamMultiLine() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val x = newArrayList(\"A\", \"b\")\n" + + "val y = x.filter [ z |\n" + + " val w = z\n" + + " w.toUpperCase == w\n" + + "]\n" + + "y.join\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val x = newArrayList(\"A\", \"b\") val y = x.filter[ z |\n" + + " val w = z w.toUpperCase == w\n" + + "] y.join\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatClosuresWithOperator() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val x = new StringBuffer() => [\n" + + " append(\"x\")\n" + + " append(\"y\")\n" + + "]\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val x = new StringBuffer() => [\n" + + " append(\"x\")\n" + + " append(\"y\")\n" + + "]\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMultiLineClosureWithAssignment() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "x += foo.myBuilder [\n" + + " foo\n" + + " bar\n" + + "]\n"; + it.setExpectation(expectation); + String toBeFormatted = + "x += foo.myBuilder [\n" + + " foo bar\n" + + "]\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSynchronizedBlock_1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "synchronized (new Object) {\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "synchronized(new Object){}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSynchronizedBlock_2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "synchronized (new Object) {\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "synchronized ( new Object ) { }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIf1SL1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisSL, true); + }); + String toBeFormatted = + "if (true) println(\"foo\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIf1SL2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisSL, false); + }); + String toBeFormatted = + "if(true) println(\"foo\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIf1ML1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, true); + }); + String toBeFormatted = + "if (true)\n" + + " println(\"foo\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIf1ML2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, false); + }); + String toBeFormatted = + "if(true)\n" + + " println(\"foo\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIf1MLVar() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "var x = if (true)\n" + + " println(\"foo\")\n" + + " else\n" + + " println(\"bar\")\n"; + it.setExpectation(expectation); + String toBeFormatted = + "var x = if(true)\n" + + "println(\"foo\") else println(\"bar\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIf1MLSemicolon1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "if (true)\n" + + " println(\"foo\");\n"; + it.setExpectation(expectation); + String toBeFormatted = + "if(true)\n" + + "println(\"foo\");\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIf1MLSemicolon2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "if (true)\n" + + " println(\"foo\");\n" + + "println(\"bar\")\n"; + it.setExpectation(expectation); + String toBeFormatted = + "if(true)\n" + + "println(\"foo\");\n" + + "println(\"bar\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIf2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "if (true) {\n" + + " println(\"foo\")\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIfElse1SL() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "if(true) println(\"foo\") else println(\"bar\")\n"; + it.setExpectation(expectation); + String toBeFormatted = + "if(true)println(\"foo\")else println(\"bar\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIfElse1ML() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "if (true)\n" + + " println(\"foo\")\n" + + "else\n" + + " println(\"bar\")\n"; + it.setExpectation(expectation); + String toBeFormatted = + "if(true)\n" + + "println(\"foo\")\n" + + "else\n" + + "println(\"bar\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIfElse2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "if (true) {\n" + + " println(\"foo\")\n" + + "} else {\n" + + " println(\"bar\")\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIfElse3() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, true); + }); + String toBeFormatted = + "if (true)\n" + + "{\n" + + " println(\"foo\")\n" + + "}\n" + + "else\n" + + "{\n" + + " println(\"bar\")\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIfElseIf1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "if (true)\n" + + " println(\"foo\")\n" + + "else if (false)\n" + + " println(\"bar\")\n"; + it.setExpectation(expectation); + String toBeFormatted = + "if(true)\n" + + "println(\"foo\")\n" + + "else if(false)\n" + + "println(\"bar\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIfElseIf2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "if (true) {\n" + + " println(\"foo\")\n" + + "} else if (false) {\n" + + " println(\"bar\")\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "if(true) {\n" + + "println(\"foo\")\n" + + "} else if(false) {\n" + + "println(\"bar\")\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatIfElseIf3() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "if (true) {\n" + + " println(\"foo\")\n" + + "} else if (false)\n" + + " println(\"bar\")\n"; + it.setExpectation(expectation); + String toBeFormatted = + "if(true) {\n" + + "println(\"foo\")\n" + + "} else if(false)\n" + + "println(\"bar\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatFor1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "for (i : 1 .. 2)\n" + + " println(i)\n"; + it.setExpectation(expectation); + String toBeFormatted = + "for ( i : 1 .. 2 ) println(i)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatFor2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, false); + }); + String toBeFormatted = + "for (i : 1 .. 2) {\n" + + " println(i)\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatFor3() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, true); + }); + it.setToBeFormatted("for (i : 1 .. 2)\n" + + "{\n" + + " println(i)\n" + + "}\n"); + }); + } + + @Test + public void formatBasicFor() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "for (var i = 1; i < 10; i = i + 1)\n" + + " println(i)\n"; + it.setExpectation(expectation); + String toBeFormatted = + "for ( var i = 1 ; i < 10; i = i + 1 ) println(i)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatBasicFor2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "for (;;) {\n" + + " return true\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "for ( ; ; ) { return true }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatBasicFor3() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "var int x\n" + + "var int y\n" + + "for (x = 1, y = 2;;) {\n" + + " return x + y\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "var int x\n" + + "var int y \n" + + "for ( x = 1 , y = 2 ; ; ) { return x + y }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatBasicFor4() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val x = 1\n" + + "for (; x < 10;)\n" + + " println(x)\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val x = 1\n" + + "for ( ; x < 10 ; ) println(x)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatBasicFor5() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val x = 1\n" + + "for (;; x = x + 1, x = x + 2)\n" + + " println(x)\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val x = 1\n" + + "for ( ; ; x = x + 1 , x = x + 2 ) println(x)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatBasicFor6() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "for (val x = 1;; x = x + 1, x = x + 2)\n" + + " println(x)\n"; + it.setExpectation(expectation); + String toBeFormatted = + "for ( val x = 1 ; ; x = x + 1 , x = x + 2 ) println(x)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatWhile11() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, true); + }); + String toBeFormatted = + "while (true)\n" + + " println(\"x\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatWhile12() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, false); + }); + String toBeFormatted = + "while(true)\n" + + " println(\"x\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatWhile2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, false); + }); + String toBeFormatted = + "while (true) {\n" + + " println(\"x\")\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatWhile21() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, true); + }); + String toBeFormatted = + "while (true)\n" + + "{\n" + + " println(\"x\")\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatDoWhile11() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, true); + }); + String toBeFormatted = + "do\n" + + " println(\"x\")\n" + + "while (true)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatDoWhile12() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, false); + }); + String toBeFormatted = + "do\n" + + " println(\"x\")\n" + + "while(true)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatDoWhile2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, false); + }); + String toBeFormatted = + "do {\n" + + " println(\"x\")\n" + + "} while (true)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatDoWhile3() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, true); + }); + String toBeFormatted = + "do\n" + + "{\n" + + " println(\"x\")\n" + + "}\n" + + "while (true)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchSL() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, false); + }); + String toBeFormatted = + "switch 'x' { case 'x': println('x') case 'y': println('y') }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchSL1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, true); + }); + String toBeFormatted = + "switch 'x' { case 'x': println('x') case 'y': println('y') }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchDefaultSL() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, false); + }); + String toBeFormatted = + "switch 'x' { case 'y': println('y') default: println('z') }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchDefaultSL1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, true); + }); + String toBeFormatted = + "switch 'x' { case 'y': println('y') default: println('z') }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchCaseSL1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, true); + }); + String toBeFormatted = + "switch 'x'\n" + + "{\n" + + " case 'x': println('x')\n" + + " case 'y': println('y')\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchCaseSLParenthesis() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "switch 'x' {\n" + + " case 'x': println('x')\n" + + " case 'y': println('y')\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch 'x' { \n" + + " case 'x': println('x') case 'y': println('y')\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchCaseDefaultSL1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, true); + }); + String toBeFormatted = + "switch 'x'\n" + + "{\n" + + " case 'x': println('x')\n" + + " case 'y': println('y')\n" + + " default: println('z')\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchCaseDefaultSLParenthesis() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "switch 'x' {\n" + + " case 'x': println('x')\n" + + " case 'y': println('y')\n" + + " default: println('z')\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch 'x' { \n" + + " case 'x': println('x') case 'y': println('y') default : println('z')\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchML() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "switch 'x' {\n" + + " case 'x':\n" + + " println('x')\n" + + " case 'y':\n" + + " println('y')\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch 'x' { \n" + + " case 'x': \n" + + " println('x') case 'y': println('y')\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchDefaultML() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "switch 'x' {\n" + + " case 'x':\n" + + " println('x')\n" + + " case 'y':\n" + + " println('y')\n" + + " default:\n" + + " println('z')\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch 'x' { \n" + + " case 'x': \n" + + " println('x') case 'y': println('y') default : println('z')\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchDefault2ML() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "switch 'x' {\n" + + " case 'x':\n" + + " println('x')\n" + + " case 'y':\n" + + " println('y')\n" + + " default:\n" + + " println('z')\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch 'x' { \n" + + " case 'x': println('x') case 'y': println('y') \n" + + " default : \n" + + " println('z')\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchDefault2MLFallThrough() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "switch 'x' {\n" + + " case 'x',\n" + + " case 'y':\n" + + " println('y')\n" + + " default:\n" + + " println('z')\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch 'x' { \n" + + " case 'x' , case 'y': println('y') \n" + + " default : \n" + + " println('z')\n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchMLBlock() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, false); + }); + String expectation = + "switch 'x' {\n" + + " case 'x': {\n" + + " println('x')\n" + + " }\n" + + " case 'y': {\n" + + " println('y')\n" + + " }\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch 'x' { case 'x': { println('x') } case 'y': { println('y') } }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchDefaultMLBlock() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, false); + }); + String expectation = + "switch 'x' {\n" + + " case 'x': {\n" + + " println('x')\n" + + " }\n" + + " case 'y': {\n" + + " println('y')\n" + + " }\n" + + " default: {\n" + + " println('z')\n" + + " }\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch 'x' { case 'x': { println('x') } case 'y': { println('y') } default: { println('z') } }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatSwitchMLBlock1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, true); + }); + String expectation = + "switch 'x'\n" + + "{\n" + + " case 'x':\n" + + " {\n" + + " println('x')\n" + + " }\n" + + " case 'y':\n" + + " {\n" + + " println('y')\n" + + " }\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch 'x' { case 'x': { println('x') } case 'y': { println('y') } }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatFeatureCallNoParenthesis() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "val v1 = newArrayList\n" + + "val v2 = newArrayList\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatFeatureCallNoParams() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "val v1 = newArrayList()\n" + + "val v2 = newArrayList()\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatFeatureCall1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML2 = newArrayList(newArrayList(1, 2, 3, 4, 5, 6),\n" + + " newArrayList(5, 6, 7, 8), newArrayList(9, 10, 11, 12),\n" + + " newArrayList(13, 14, 15, 16))\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML2 = newArrayList(newArrayList(1, 2, 3, 4, 5, 6), newArrayList(5, 6, 7, 8), newArrayList(9, 10, 11, 12), newArrayList(13, 14, 15, 16))\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatFeatureCall2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML2 = newArrayList(newArrayList(1, 2, 3, 4),\n" + + " newArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109,\n" + + " 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120),\n" + + " newArrayList(9, 10, 11, 12), newArrayList(13, 14, 15, 16))\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML2 = newArrayList(newArrayList(1, 2, 3, 4), newArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), newArrayList(9, 10, 11, 12), newArrayList(13, 14, 15, 16))\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatFeatureCallMultiline() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML2 = newArrayList(\n" + + " newArrayList(1, 2, 3, 4),\n" + + " newArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109,\n" + + " 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120),\n" + + " newArrayList(9),\n" + + " newArrayList(10)\n" + + ")\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML2 = newArrayList(newArrayList(1, 2, 3, 4), newArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), newArrayList(9), newArrayList(10)\n" + + ")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatConstructorCallNoParenthesis() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "val v1 = new ArrayList\n" + + "val v2 = new ArrayList\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatConstructorCallClosure() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "new Thread[|println(\"foo\")]\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatConstructorCallNoParams() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "val v1 = new ArrayList()\n" + + "val v2 = new ArrayList()\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatConstructorCall1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4, 5, 6),\n" + + " new ArrayList(5, 6, 7, 8), new ArrayList(9, 10, 11, 12),\n" + + " new ArrayList(13, 14, 15, 16))\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4, 5, 6), new ArrayList(5, 6, 7, 8), new ArrayList(9, 10, 11, 12), new ArrayList(13, 14, 15, 16))\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatConstructorCall2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4),\n" + + " new ArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109,\n" + + " 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120),\n" + + " new ArrayList(9, 10, 11, 12), new ArrayList(13, 14, 15, 16))\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4), new ArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), new ArrayList(9, 10, 11, 12), new ArrayList(13, 14, 15, 16))\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatConstructorCallMultiline() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML2 = new ArrayList(\n" + + " new ArrayList(1, 2, 3, 4),\n" + + " new ArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109,\n" + + " 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120),\n" + + " new ArrayList(9, 10, 11, 12),\n" + + " new ArrayList(13, 14, 15, 16)\n" + + ")\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4), new ArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), new ArrayList(9, 10, 11, 12), new ArrayList(13, 14, 15, 16)\n" + + ")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMemberFeatureCallNoParenthesis() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "val v1 = \"x\".toString\n" + + "val v2 = \"x\".toString\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMemberFeatureCallNoParams() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String toBeFormatted = + "val v1 = \"x\".toString()\n" + + "val v2 = \"x\".toString()\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMemberFeatureCall1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML1 = \"x\".substring(0).substring(1).substring(2).substring(3).\n" + + " substring(4).substring(5).substring(6).substring(7).substring(8).\n" + + " substring(9).substring(10).substring(11)\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML1 = \"x\".substring(0).substring(1).substring(2).substring(3).substring(4).substring(5).substring(6).substring(7).substring(8).substring(9).substring(10).substring(11)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMemberFeatureCall2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML1 = \"x\".substring(0).substring(1)\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML1 = \"x\"\n" + + ".\n" + + "substring(0)\n" + + ".\n" + + "substring(1)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMemberFeatureCall21() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML1 = \"x\".toString.toString\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML1 = \"x\"\n" + + ".\n" + + "toString\n" + + ".\n" + + "toString\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMemberFeatureCall3() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML1 = \"x\".substring(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,\n" + + " 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28)\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML1 = \"x\".substring(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMemberFeatureCall4() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML1 = \"x\".substring(0, 1, 2)\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML1 = \"x\".substring (\n" + + "\n" + + "0, \n" + + "\n" + + "1, \n" + + "\n" + + "2)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMemberFeatureCallMultiline() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML1 = \"x\".substring(\n" + + " 0,\n" + + " 1,\n" + + " 2\n" + + ")\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML1 = \"x\".substring (\n" + + "\n" + + "0, \n" + + "\n" + + "1, \n" + + "\n" + + "2\n" + + ")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMemberFeatureCallBuilder1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "newArrayList(\"x\").map()[]\n"; + it.setExpectation(expectation); + String toBeFormatted = + "newArrayList(\"x\") . map ( ) [ ]\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMemberFeatureCallBuilder2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "newArrayList(\"x\").map()[lenght]\n"; + it.setExpectation(expectation); + String toBeFormatted = + "newArrayList(\"x\") . map ( ) [ lenght ]\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMemberFeatureCallBuilderMultiline1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "newArrayList(\"x\").map(\n" + + " length\n" + + ")[lenght]\n"; + it.setExpectation(expectation); + String toBeFormatted = + "newArrayList(\"x\") . map ( length \n" + + ") [ lenght ]\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatMemberFeatureCallBuilderMultiline2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "newArrayList(\"x\").map(length) [\n" + + " length\n" + + "]\n"; + it.setExpectation(expectation); + String toBeFormatted = + "newArrayList(\"x\") . map ( length ) [ length \n" + + "]\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=461033 + */ + @Test + public void formatMemberFeatureCallParenthesized() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val s = (\"a\" + \"b\").substring(1)\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val s = (\"a\" + \"b\") . substring(1)\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatBinaryExpression1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 +\n" + + " 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 +\n" + + " 30 + 31 + 32 + 33 + 34 + 35 + 36\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 \n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatBinaryExpression2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val ML1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 +\n" + + " 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 + 19 + 20 + 21 + 22 + 23 + 24 +\n" + + " 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val ML1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 \n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatXTypeLiteral() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.setExpectation("typeof(String)\n"); + it.setToBeFormatted("typeof ( String )\n"); + }); + } + + @Test + public void formatXTypeLiteralArray1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.setExpectation("typeof(String[])\n"); + it.setToBeFormatted("typeof ( String [ ])\n"); + }); + } + + @Test + public void formatXTypeLiteralArray2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.setExpectation("typeof(String[][])\n"); + it.setToBeFormatted("typeof ( String [ ] [ ] )\n"); + }); + } + + @Test + public void formatXThrowExpression() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.setExpectation("throw new RuntimeException()\n"); + it.setToBeFormatted("throw new RuntimeException()\n"); + }); + } + + @Test + public void formatXReturnExpression1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.setExpectation("return \"foo\"\n"); + it.setToBeFormatted("return \"foo\"\n"); + }); + } + + @Test + public void formatXReturnExpression2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.setExpectation("\"foo\"\n" + + "return\n"); + it.setToBeFormatted("\"foo\" return\n"); + }); + } + + @Test + public void formatXReturnExpression3() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.setExpectation("return;\n"); + it.setToBeFormatted("return ;\n"); + }); + } + + @Test + public void formatTryFinallyExpression1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "try\n" + + " println(\"x\")\n" + + "finally\n" + + " println(\"y\")\n"; + it.setExpectation(expectation); + String toBeFormatted = + "try println(\"x\") finally println(\"y\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatTryFinallyExpression2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "try {\n" + + " println(\"x\")\n" + + "} finally {\n" + + " println(\"y\")\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "try { println(\"x\") } finally { println(\"y\") }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatTryCatchExpression11() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, true); + }); + String toBeFormatted = + "try\n" + + " println(\"x\")\n" + + "catch (Exception e)\n" + + " println(\"y\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatTryCatchExpression12() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, false); + }); + String toBeFormatted = + "try\n" + + " println(\"x\")\n" + + "catch(Exception e)\n" + + " println(\"y\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatTryCatchExpression2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "try {\n" + + " println(\"x\")\n" + + "} catch (Exception e) {\n" + + " println(\"y\")\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "try { println(\"x\") } catch ( Exception e ) { println(\"y\") }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatTryCatchFinallyExpression1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "try\n" + + " println(\"x\")\n" + + "catch (Exception e)\n" + + " println(\"y\")\n" + + "finally\n" + + " println(\"z\")\n"; + it.setExpectation(expectation); + String toBeFormatted = + "try println(\"x\") catch ( Exception e ) println(\"y\") finally println(\"z\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatTryCatchFinallyExpressionBug474022() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, false); + }); + String expectation = + "val i = try {\n" + + " println(\"x\")\n" + + " 1\n" + + " } catch (Exception e) {\n" + + " println(\"y\")\n" + + " 2\n" + + " } finally {\n" + + " println(\"z\")\n" + + " }\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val i = try { println(\"x\") 1 } catch ( Exception e ) { println(\"y\") 2 } finally { println(\"z\") }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatTryCatchFinallyExpression2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, false); + }); + String expectation = + "try {\n" + + " println(\"x\")\n" + + "} catch (Exception e) {\n" + + " println(\"y\")\n" + + "} finally {\n" + + " println(\"z\")\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "try { println(\"x\") } catch ( Exception e ) { println(\"y\") } finally { println(\"z\") }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatTryCatchFinallyExpression3() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + it.preferences((MapBasedPreferenceValues p) -> { + p.put(XbaseFormatterPreferenceKeys.bracesInNewLine, true); + }); + String expectation = + "try\n" + + "{\n" + + " println(\"x\")\n" + + "}\n" + + "catch (Exception e)\n" + + "{\n" + + " println(\"y\")\n" + + "}\n" + + "finally\n" + + "{\n" + + " println(\"z\")\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "try { println(\"x\") } catch ( Exception e ) { println(\"y\") } finally { println(\"z\") }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatTryCatchCatchFinallyExpression1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "try\n" + + " println(\"x\")\n" + + "catch (Exception e)\n" + + " println(\"y\")\n" + + "catch (Exception f)\n" + + " println(\"z\")\n" + + "finally\n" + + " println(\"a\")\n"; + it.setExpectation(expectation); + String toBeFormatted = + "try println(\"x\") catch ( Exception e ) println(\"y\") catch ( Exception f ) println(\"z\") finally println(\"a\")\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatTryCatchCatchFinallyExpression2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "try {\n" + + " println(\"x\")\n" + + "} catch (Exception e) {\n" + + " println(\"y\")\n" + + "} catch (Exception f) {\n" + + " println(\"z\")\n" + + "} finally {\n" + + " println(\"a\")\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "try { println(\"x\") } catch ( Exception e ) { println(\"y\") } catch ( Exception f ) { println(\"z\") } finally { println(\"a\") }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatListLiteral1() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "#[12, 13, 14]\n"; + it.setExpectation(expectation); + String toBeFormatted = + "#[12, 13 , 14 ]\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatListLiteral3() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "#[\n" + + " 12,\n" + + " 13,\n" + + " 14\n" + + "]\n"; + it.setExpectation(expectation); + String toBeFormatted = + "#[12, 13 , 14 \n" + + "]\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatEmptySwitchSL() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "switch null { }\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch null { }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatEmptySwitchSL_2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "switch null { default: 1 }\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch null { default : 1 }\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatEmptySwitchML() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "switch null {\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch null { \n" + + " \n" + + " \n" + + " \n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatEmptySwitchML_2() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "switch null {\n" + + " default: 1\n" + + "}\n"; + it.setExpectation(expectation); + String toBeFormatted = + "switch null { \n" + + " \n" + + " \n" + + " \n" + + " default : 1\n" + + " \n" + + "}\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatInstanceOf() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "\"x\".toString instanceof String\n"; + it.setExpectation(expectation); + String toBeFormatted = + "\"x\".toString instanceof String\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatCast() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "\"x\" as String\n"; + it.setExpectation(expectation); + String toBeFormatted = + "\"x\" as String\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void formatPostfix() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val i = j++\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val i = j ++\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void testFeatureCallWithParentheses() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val it = \"xxxx\"\n" + + "val j = true && (startsWith(\"x\"))\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val it = \"xxxx\"\n" + + "val j = true&&(startsWith(\"x\"))\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void testMemberFeatureCallWithParentheses() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "val j = true && (class.startsWith(\"Hugo\"))\n"; + it.setExpectation(expectation); + String toBeFormatted = + "val j = true&&(class.startsWith(\"Hugo\"))\n"; + it.setToBeFormatted(toBeFormatted); + }); + } + + @Test + public void testIssue527() { + xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> { + String expectation = + "var veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname = #[\n" + + " 1, 2, 3, 4, 5]\n" + + "veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname.\n" + + " map [ l |\n" + + " veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname\n" + + " ]\n"; + it.setExpectation(expectation); + String toBeFormatted = + "var veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname = #[1,2,3,4,5]\n" + + "veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname.map[l|veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname]\n" + + "\n"; + it.setToBeFormatted(toBeFormatted); + }); + + } +} diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterTest.xtend b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterTest.xtend deleted file mode 100644 index 256ea5f6a5..0000000000 --- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterTest.xtend +++ /dev/null @@ -1,1763 +0,0 @@ -package org.eclipse.xtext.xbase.tests.formatting - -import com.google.inject.Inject -import org.eclipse.xtext.testing.InjectWith -import org.eclipse.xtext.testing.XtextRunner -import org.junit.Test -import org.junit.runner.RunWith - -import static org.eclipse.xtext.xbase.formatting2.XbaseFormatterPreferenceKeys.* - -@RunWith(typeof(XtextRunner)) -@InjectWith(typeof(XbaseFormatterTestInjectorProvider)) -class XbaseFormatterTest { - - @Inject extension XbaseFormatterTester - - @Test def formatGenerics() { - assertFormattedExpression [ - toBeFormatted = ''' - val x = >newArrayList() - ''' - ] - } - - @Test def formatBlockExpression() { - assertFormattedExpression [ - expectation = ''' - val x = newArrayList("A", "b"); - val y = 'foo'; - x.join - ''' - toBeFormatted = ''' - val x = newArrayList("A", "b") ; val y = 'foo' ; x.join - ''' - ] - } - - @Test def formatBlockExpressionPreserveNewLines() { - assertFormatted[ - expectation = ''' - { - - val x = newArrayList("A", "b"); - - val y = 'foo' - - x.join - - } - '''.toString.trim - toBeFormatted = ''' - { - - - val x = newArrayList("A", "b") ; - - - val y = 'foo' - - - x.join - - - } - ''' - ] - } - - @Test def formatClosures() { - assertFormattedExpression [ - toBeFormatted = ''' - val x = newArrayList("A", "b") - val y = x.filter[toUpperCase == it] - y.join - ''' - ] - } - - @Test def formatClosuresParenthesis() { - assertFormattedExpression [ - toBeFormatted = ''' - val x = newArrayList("A", "b") - val y = x.filter(toUpperCase == it) - y.join - ''' - ] - } - - @Test def formatClosuresParenthesis2() { - assertFormattedExpression [ - toBeFormatted = ''' - val x = newArrayList("A", "b") - val y = x.filter(foo|foo.toUpperCase == foo) - y.join - ''' - ] - } - - @Test def formatClosuresSemicolon() { - assertFormattedExpression [ - expectation = ''' - newArrayList("A", "b").filter[val b = it; b.toUpperCase == b] - ''' - toBeFormatted = ''' - newArrayList("A", "b").filter[ val b = it ; b.toUpperCase == b ] - ''' - ] - } - - @Test def formatClosuresEmpty() { - assertFormattedExpression [ - expectation = ''' - val x = newArrayList("A", "b") - val y = x.filter[] - y.join - ''' - toBeFormatted = ''' - val x = newArrayList("A", "b") val y = x.filter[ ] y.join - ''' - ] - } - - @Test def formatClosuresParam() { - assertFormattedExpression [ - toBeFormatted = ''' - val x = newArrayList("A", "b") - val y = x.filter[z|z.toUpperCase == z] - y.join - ''' - ] - } - - @Test def formatClosuresEmptyParam() { - assertFormattedExpression [ - toBeFormatted = ''' - val Iterable x = [|#[].iterator] - ''' - ] - } - - @Test def formatClosuresMultiLine() { - assertFormattedExpression [ - expectation = ''' - val x = newArrayList("A", "b") - val y = x.filter [ - val z = it - z.toUpperCase == z - ] - y.join - ''' - toBeFormatted = ''' - val x = newArrayList("A", "b") val y = x.filter [ - val z = it z.toUpperCase == z - ] y.join - ''' - ] - } - - @Test def formatClosuresMultiLine_02() { - assertFormattedExpression [ - expectation = ''' - val x = newArrayList("A", "b") - val y = x.filter [ - val z = it - z.toUpperCase == z - ] - y.join - ''' - toBeFormatted = ''' - val x = newArrayList("A", "b") val y = x.filter[ - val z = it z.toUpperCase == z - ] y.join - ''' - ] - } - - @Test def formatClosuresMultiLine03() { - assertFormattedExpression [ - expectation = ''' - new Thread [| - println("foo") - ] - ''' - toBeFormatted = ''' - new Thread[ | println("foo") - ] - ''' - ] - } - - @Test def formatClosuresMultiLineSemicolon() { - assertFormattedExpression [ - expectation = ''' - val x = newArrayList("A", "b") - val y = x.filter [ - val z = it; - z.toUpperCase == z; - ] - y.join - ''' - toBeFormatted = ''' - val x = newArrayList("A", "b") val y = x.filter [ - val z = it ; z.toUpperCase == z ; - ] y.join - ''' - ] - - } - - @Test def formatClosuresWrapIfNeeded() { - assertFormattedExpression [ - expectation = ''' - val x = newArrayList("A", "b") - val y = x.filter [ - val z = it - z.toUpperCase == z - z.toUpperCase == z - z.toUpperCase == z - ] - y.join - ''' - toBeFormatted = ''' - val x = newArrayList("A", "b") val y = x.filter [ val z = it z.toUpperCase == z z.toUpperCase == z z.toUpperCase == z ] y.join - ''' - ] - } - - @Test def formatClosuresParamMultiLine() { - assertFormattedExpression [ - expectation = ''' - val x = newArrayList("A", "b") - val y = x.filter [ z | - val w = z - w.toUpperCase == w - ] - y.join - ''' - toBeFormatted = ''' - val x = newArrayList("A", "b") val y = x.filter[ z | - val w = z w.toUpperCase == w - ] y.join - ''' - ] - } - - @Test def formatClosuresWithOperator() { - assertFormattedExpression [ - expectation = ''' - val x = new StringBuffer() => [ - append("x") - append("y") - ] - ''' - toBeFormatted = ''' - val x = new StringBuffer() => [ - append("x") - append("y") - ] - ''' - ] - } - - @Test def formatMultiLineClosureWithAssignment() { - assertFormattedExpression [ - expectation = ''' - x += foo.myBuilder [ - foo - bar - ] - ''' - toBeFormatted = ''' - x += foo.myBuilder [ - foo bar - ] - ''' - ] - } - - @Test def formatSynchronizedBlock_1() { - assertFormattedExpression [ - expectation = ''' - synchronized (new Object) { - } - ''' - toBeFormatted = ''' - synchronized(new Object){} - ''' - ] - } - - @Test def formatSynchronizedBlock_2() { - assertFormattedExpression [ - expectation = ''' - synchronized (new Object) { - } - ''' - toBeFormatted = ''' - synchronized ( new Object ) { } - ''' - ] - } - - @Test def formatIf1SL1() { - assertFormattedExpression [ - preferences[ - put(whitespaceBetweenKeywordAndParenthesisSL, true) - ] - toBeFormatted = ''' - if (true) println("foo") - ''' - ] - } - - @Test def formatIf1SL2() { - assertFormattedExpression [ - preferences[ - put(whitespaceBetweenKeywordAndParenthesisSL, false) - ] - toBeFormatted = ''' - if(true) println("foo") - ''' - ] - } - - @Test def formatIf1ML1() { - assertFormattedExpression [ - preferences[ - put(whitespaceBetweenKeywordAndParenthesisML, true) - ] - toBeFormatted = ''' - if (true) - println("foo") - ''' - ] - } - - @Test def formatIf1ML2() { - assertFormattedExpression [ - preferences[ - put(whitespaceBetweenKeywordAndParenthesisML, false) - ] - toBeFormatted = ''' - if(true) - println("foo") - ''' - ] - } - - @Test def formatIf1MLVar() { - assertFormattedExpression [ - expectation = ''' - var x = if (true) - println("foo") - else - println("bar") - ''' - toBeFormatted = ''' - var x = if(true) - println("foo") else println("bar") - ''' - ] - } - - @Test def formatIf1MLSemicolon1() { - assertFormattedExpression [ - expectation = ''' - if (true) - println("foo"); - ''' - toBeFormatted = ''' - if(true) - println("foo"); - ''' - ] - } - - @Test def formatIf1MLSemicolon2() { - assertFormattedExpression [ - expectation = ''' - if (true) - println("foo"); - println("bar") - ''' - toBeFormatted = ''' - if(true) - println("foo"); - println("bar") - ''' - ] - } - - @Test def formatIf2() { - assertFormattedExpression [ - toBeFormatted = ''' - if (true) { - println("foo") - } - ''' - ] - } - - @Test def formatIfElse1SL() { - assertFormattedExpression [ - expectation = ''' - if(true) println("foo") else println("bar") - ''' - toBeFormatted = ''' - if(true)println("foo")else println("bar") - ''' - ] - } - - @Test def formatIfElse1ML() { - assertFormattedExpression [ - expectation = ''' - if (true) - println("foo") - else - println("bar") - ''' - toBeFormatted = ''' - if(true) - println("foo") - else - println("bar") - ''' - ] - } - - @Test def formatIfElse2() { - assertFormattedExpression [ - toBeFormatted = ''' - if (true) { - println("foo") - } else { - println("bar") - } - ''' - ] - } - - @Test def formatIfElse3() { - assertFormattedExpression [ - preferences[ - put(bracesInNewLine, true) - ] - toBeFormatted = ''' - if (true) - { - println("foo") - } - else - { - println("bar") - } - ''' - ] - } - - @Test def formatIfElseIf1() { - assertFormattedExpression [ - expectation = ''' - if (true) - println("foo") - else if (false) - println("bar") - ''' - toBeFormatted = ''' - if(true) - println("foo") - else if(false) - println("bar") - ''' - ] - } - - @Test def formatIfElseIf2() { - assertFormattedExpression [ - expectation = ''' - if (true) { - println("foo") - } else if (false) { - println("bar") - } - ''' - toBeFormatted = ''' - if(true) { - println("foo") - } else if(false) { - println("bar") - } - ''' - ] - } - - @Test def formatIfElseIf3() { - assertFormattedExpression [ - expectation = ''' - if (true) { - println("foo") - } else if (false) - println("bar") - ''' - toBeFormatted = ''' - if(true) { - println("foo") - } else if(false) - println("bar") - ''' - ] - } - - @Test def formatFor1() { - assertFormattedExpression [ - expectation = ''' - for (i : 1 .. 2) - println(i) - ''' - toBeFormatted = ''' - for ( i : 1 .. 2 ) println(i) - ''' - ] - } - - @Test def formatFor2() { - assertFormattedExpression [ - preferences[ - put(bracesInNewLine, false) - ] - toBeFormatted = ''' - for (i : 1 .. 2) { - println(i) - } - ''' - ] - } - - @Test def formatFor3() { - assertFormattedExpression [ - preferences[ - put(bracesInNewLine, true) - ] - toBeFormatted = ''' - for (i : 1 .. 2) - { - println(i) - } - ''' - ] - } - - @Test def formatBasicFor() { - assertFormattedExpression [ - expectation = ''' - for (var i = 1; i < 10; i = i + 1) - println(i) - ''' - toBeFormatted = ''' - for ( var i = 1 ; i < 10; i = i + 1 ) println(i) - ''' - ] - } - - @Test def formatBasicFor2() { - assertFormattedExpression [ - expectation = ''' - for (;;) { - return true - } - ''' - toBeFormatted = ''' - for ( ; ; ) { return true } - ''' - ] - } - - @Test def formatBasicFor3() { - assertFormattedExpression [ - expectation = ''' - var int x - var int y - for (x = 1, y = 2;;) { - return x + y - } - ''' - toBeFormatted = ''' - var int x - var int y - for ( x = 1 , y = 2 ; ; ) { return x + y } - ''' - ] - } - - @Test def formatBasicFor4() { - assertFormattedExpression [ - expectation = ''' - val x = 1 - for (; x < 10;) - println(x) - ''' - toBeFormatted = ''' - val x = 1 - for ( ; x < 10 ; ) println(x) - ''' - ] - } - - @Test def formatBasicFor5() { - assertFormattedExpression [ - expectation = ''' - val x = 1 - for (;; x = x + 1, x = x + 2) - println(x) - ''' - toBeFormatted = ''' - val x = 1 - for ( ; ; x = x + 1 , x = x + 2 ) println(x) - ''' - ] - } - - @Test def formatBasicFor6() { - assertFormattedExpression [ - expectation = ''' - for (val x = 1;; x = x + 1, x = x + 2) - println(x) - ''' - toBeFormatted = ''' - for ( val x = 1 ; ; x = x + 1 , x = x + 2 ) println(x) - ''' - ] - } - - @Test def formatWhile11() { - assertFormattedExpression [ - preferences[ - put(whitespaceBetweenKeywordAndParenthesisML, true) - ] - toBeFormatted = ''' - while (true) - println("x") - ''' - ] - } - - @Test def formatWhile12() { - assertFormattedExpression [ - preferences[ - put(whitespaceBetweenKeywordAndParenthesisML, false) - ] - toBeFormatted = ''' - while(true) - println("x") - ''' - ] - } - - @Test def formatWhile2() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, false) - ] - toBeFormatted = ''' - while (true) { - println("x") - } - ''' - ] - } - - @Test def formatWhile21() { - assertFormattedExpression [ - preferences[ - put(bracesInNewLine, true) - ] - toBeFormatted = ''' - while (true) - { - println("x") - } - ''' - ] - } - - @Test def formatDoWhile11() { - assertFormattedExpression [ - preferences[ - put(whitespaceBetweenKeywordAndParenthesisML, true) - ] - toBeFormatted = ''' - do - println("x") - while (true) - ''' - ] - } - - @Test def formatDoWhile12() { - assertFormattedExpression [ - preferences[ - put(whitespaceBetweenKeywordAndParenthesisML, false) - ] - toBeFormatted = ''' - do - println("x") - while(true) - ''' - ] - } - - @Test def formatDoWhile2() { - assertFormattedExpression [ - preferences[ - put(bracesInNewLine, false) - ] - toBeFormatted = ''' - do { - println("x") - } while (true) - ''' - ] - } - - @Test def formatDoWhile3() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, true) - ] - toBeFormatted = ''' - do - { - println("x") - } - while (true) - ''' - ] - } - - @Test def formatSwitchSL() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, false) - ] - toBeFormatted = ''' - switch 'x' { case 'x': println('x') case 'y': println('y') } - ''' - ] - } - - @Test def formatSwitchSL1() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, true) - ] - toBeFormatted = ''' - switch 'x' { case 'x': println('x') case 'y': println('y') } - ''' - ] - } - - @Test def formatSwitchDefaultSL() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, false) - ] - toBeFormatted = ''' - switch 'x' { case 'y': println('y') default: println('z') } - ''' - ] - } - - @Test def formatSwitchDefaultSL1() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, true) - ] - toBeFormatted = ''' - switch 'x' { case 'y': println('y') default: println('z') } - ''' - ] - } - - @Test def formatSwitchCaseSL1() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, true) - ] - toBeFormatted = ''' - switch 'x' - { - case 'x': println('x') - case 'y': println('y') - } - ''' - ] - } - - @Test def formatSwitchCaseSLParenthesis() { - assertFormattedExpression [ - expectation = ''' - switch 'x' { - case 'x': println('x') - case 'y': println('y') - } - ''' - toBeFormatted = ''' - switch 'x' { - case 'x': println('x') case 'y': println('y') - } - ''' - ] - } - - @Test def formatSwitchCaseDefaultSL1() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, true) - ] - toBeFormatted = ''' - switch 'x' - { - case 'x': println('x') - case 'y': println('y') - default: println('z') - } - ''' - ] - } - - @Test def formatSwitchCaseDefaultSLParenthesis() { - assertFormattedExpression [ - expectation = ''' - switch 'x' { - case 'x': println('x') - case 'y': println('y') - default: println('z') - } - ''' - toBeFormatted = ''' - switch 'x' { - case 'x': println('x') case 'y': println('y') default : println('z') - } - ''' - ] - } - - @Test def formatSwitchML() { - assertFormattedExpression [ - expectation = ''' - switch 'x' { - case 'x': - println('x') - case 'y': - println('y') - } - ''' - toBeFormatted = ''' - switch 'x' { - case 'x': - println('x') case 'y': println('y') - } - ''' - ] - } - - @Test def formatSwitchDefaultML() { - assertFormattedExpression [ - expectation = ''' - switch 'x' { - case 'x': - println('x') - case 'y': - println('y') - default: - println('z') - } - ''' - toBeFormatted = ''' - switch 'x' { - case 'x': - println('x') case 'y': println('y') default : println('z') - } - ''' - ] - } - - @Test def formatSwitchDefault2ML() { - assertFormattedExpression [ - expectation = ''' - switch 'x' { - case 'x': - println('x') - case 'y': - println('y') - default: - println('z') - } - ''' - toBeFormatted = ''' - switch 'x' { - case 'x': println('x') case 'y': println('y') - default : - println('z') - } - ''' - ] - } - - @Test def formatSwitchDefault2MLFallThrough() { - assertFormattedExpression [ - expectation = ''' - switch 'x' { - case 'x', - case 'y': - println('y') - default: - println('z') - } - ''' - toBeFormatted = ''' - switch 'x' { - case 'x' , case 'y': println('y') - default : - println('z') - } - ''' - ] - } - - @Test def formatSwitchMLBlock() { - assertFormattedExpression [ - preferences [ - it.put(bracesInNewLine, false) - ] - expectation = ''' - switch 'x' { - case 'x': { - println('x') - } - case 'y': { - println('y') - } - } - ''' - toBeFormatted = ''' - switch 'x' { case 'x': { println('x') } case 'y': { println('y') } } - ''' - ] - } - - @Test def formatSwitchDefaultMLBlock() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, false) - ] - expectation = ''' - switch 'x' { - case 'x': { - println('x') - } - case 'y': { - println('y') - } - default: { - println('z') - } - } - ''' - toBeFormatted = ''' - switch 'x' { case 'x': { println('x') } case 'y': { println('y') } default: { println('z') } } - ''' - ] - } - - @Test def formatSwitchMLBlock1() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, true) - ] - expectation = ''' - switch 'x' - { - case 'x': - { - println('x') - } - case 'y': - { - println('y') - } - } - ''' - toBeFormatted = ''' - switch 'x' { case 'x': { println('x') } case 'y': { println('y') } } - ''' - ] - } - - @Test def formatFeatureCallNoParenthesis() { - assertFormattedExpression [ - toBeFormatted = ''' - val v1 = newArrayList - val v2 = newArrayList - ''' - ] - } - - @Test def formatFeatureCallNoParams() { - assertFormattedExpression [ - toBeFormatted = ''' - val v1 = newArrayList() - val v2 = newArrayList() - ''' - ] - } - - @Test def formatFeatureCall1() { - assertFormattedExpression [ - expectation = ''' - val ML2 = newArrayList(newArrayList(1, 2, 3, 4, 5, 6), - newArrayList(5, 6, 7, 8), newArrayList(9, 10, 11, 12), - newArrayList(13, 14, 15, 16)) - ''' - toBeFormatted = ''' - val ML2 = newArrayList(newArrayList(1, 2, 3, 4, 5, 6), newArrayList(5, 6, 7, 8), newArrayList(9, 10, 11, 12), newArrayList(13, 14, 15, 16)) - ''' - ] - } - - @Test def formatFeatureCall2() { - assertFormattedExpression [ - expectation = ''' - val ML2 = newArrayList(newArrayList(1, 2, 3, 4), - newArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), - newArrayList(9, 10, 11, 12), newArrayList(13, 14, 15, 16)) - ''' - toBeFormatted = ''' - val ML2 = newArrayList(newArrayList(1, 2, 3, 4), newArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), newArrayList(9, 10, 11, 12), newArrayList(13, 14, 15, 16)) - ''' - ] - } - - @Test def formatFeatureCallMultiline() { - assertFormattedExpression [ - expectation = ''' - val ML2 = newArrayList( - newArrayList(1, 2, 3, 4), - newArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), - newArrayList(9), - newArrayList(10) - ) - ''' - toBeFormatted = ''' - val ML2 = newArrayList(newArrayList(1, 2, 3, 4), newArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), newArrayList(9), newArrayList(10) - ) - ''' - ] - } - - @Test def formatConstructorCallNoParenthesis() { - assertFormattedExpression [ - toBeFormatted = ''' - val v1 = new ArrayList - val v2 = new ArrayList - ''' - ] - } - - @Test def formatConstructorCallClosure() { - assertFormattedExpression [ - toBeFormatted = ''' - new Thread[|println("foo")] - ''' - ] - } - - @Test def formatConstructorCallNoParams() { - assertFormattedExpression [ - toBeFormatted = ''' - val v1 = new ArrayList() - val v2 = new ArrayList() - ''' - ] - } - - @Test def formatConstructorCall1() { - assertFormattedExpression [ - expectation = ''' - val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4, 5, 6), - new ArrayList(5, 6, 7, 8), new ArrayList(9, 10, 11, 12), - new ArrayList(13, 14, 15, 16)) - ''' - toBeFormatted = ''' - val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4, 5, 6), new ArrayList(5, 6, 7, 8), new ArrayList(9, 10, 11, 12), new ArrayList(13, 14, 15, 16)) - ''' - ] - } - - @Test def formatConstructorCall2() { - assertFormattedExpression [ - expectation = ''' - val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4), - new ArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), - new ArrayList(9, 10, 11, 12), new ArrayList(13, 14, 15, 16)) - ''' - toBeFormatted = ''' - val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4), new ArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), new ArrayList(9, 10, 11, 12), new ArrayList(13, 14, 15, 16)) - ''' - ] - } - - @Test def formatConstructorCallMultiline() { - assertFormattedExpression [ - expectation = ''' - val ML2 = new ArrayList( - new ArrayList(1, 2, 3, 4), - new ArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), - new ArrayList(9, 10, 11, 12), - new ArrayList(13, 14, 15, 16) - ) - ''' - toBeFormatted = ''' - val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4), new ArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), new ArrayList(9, 10, 11, 12), new ArrayList(13, 14, 15, 16) - ) - ''' - ] - } - - @Test def formatMemberFeatureCallNoParenthesis() { - assertFormattedExpression [ - toBeFormatted = ''' - val v1 = "x".toString - val v2 = "x".toString - ''' - ] - } - - @Test def formatMemberFeatureCallNoParams() { - assertFormattedExpression [ - toBeFormatted = ''' - val v1 = "x".toString() - val v2 = "x".toString() - ''' - ] - } - - @Test def formatMemberFeatureCall1() { - assertFormattedExpression [ - expectation = ''' - val ML1 = "x".substring(0).substring(1).substring(2).substring(3). - substring(4).substring(5).substring(6).substring(7).substring(8). - substring(9).substring(10).substring(11) - ''' - toBeFormatted = ''' - val ML1 = "x".substring(0).substring(1).substring(2).substring(3).substring(4).substring(5).substring(6).substring(7).substring(8).substring(9).substring(10).substring(11) - ''' - ] - } - - @Test def formatMemberFeatureCall2() { - assertFormattedExpression [ - expectation = ''' - val ML1 = "x".substring(0).substring(1) - ''' - toBeFormatted = ''' - val ML1 = "x" - . - substring(0) - . - substring(1) - ''' - ] - } - - @Test def formatMemberFeatureCall21() { - assertFormattedExpression [ - expectation = ''' - val ML1 = "x".toString.toString - ''' - toBeFormatted = ''' - val ML1 = "x" - . - toString - . - toString - ''' - ] - } - - @Test def formatMemberFeatureCall3() { - assertFormattedExpression [ - expectation = ''' - val ML1 = "x".substring(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28) - ''' - toBeFormatted = ''' - val ML1 = "x".substring(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28) - ''' - ] - } - - @Test def formatMemberFeatureCall4() { - assertFormattedExpression [ - expectation = ''' - val ML1 = "x".substring(0, 1, 2) - ''' - toBeFormatted = ''' - val ML1 = "x".substring ( - - 0, - - 1, - - 2) - ''' - ] - } - - @Test def formatMemberFeatureCallMultiline() { - assertFormattedExpression [ - expectation = ''' - val ML1 = "x".substring( - 0, - 1, - 2 - ) - ''' - toBeFormatted = ''' - val ML1 = "x".substring ( - - 0, - - 1, - - 2 - ) - ''' - ] - } - - @Test def formatMemberFeatureCallBuilder1() { - assertFormattedExpression [ - expectation = ''' - newArrayList("x").map()[] - ''' - toBeFormatted = ''' - newArrayList("x") . map ( ) [ ] - ''' - ] - } - - @Test def formatMemberFeatureCallBuilder2() { - assertFormattedExpression [ - expectation = ''' - newArrayList("x").map()[lenght] - ''' - toBeFormatted = ''' - newArrayList("x") . map ( ) [ lenght ] - ''' - ] - } - - @Test def formatMemberFeatureCallBuilderMultiline1() { - assertFormattedExpression [ - expectation = ''' - newArrayList("x").map( - length - )[lenght] - ''' - toBeFormatted = ''' - newArrayList("x") . map ( length - ) [ lenght ] - ''' - ] - } - - @Test def formatMemberFeatureCallBuilderMultiline2() { - assertFormattedExpression [ - expectation = ''' - newArrayList("x").map(length) [ - length - ] - ''' - toBeFormatted = ''' - newArrayList("x") . map ( length ) [ length - ] - ''' - ] - } - - /** - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=461033 - */ - @Test def formatMemberFeatureCallParenthesized() { - assertFormattedExpression [ - expectation = ''' - val s = ("a" + "b").substring(1) - ''' - toBeFormatted = ''' - val s = ("a" + "b") . substring(1) - ''' - ] - } - - @Test def formatBinaryExpression1() { - assertFormattedExpression [ - expectation = ''' - val ML1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + - 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + - 30 + 31 + 32 + 33 + 34 + 35 + 36 - ''' - toBeFormatted = ''' - val ML1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 - ''' - ] - } - - @Test def formatBinaryExpression2() { - assertFormattedExpression [ - expectation = ''' - val ML1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + - 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 + 19 + 20 + 21 + 22 + 23 + 24 + - 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 - ''' - toBeFormatted = ''' - val ML1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 - ''' - ] - } - - @Test def formatXTypeLiteral() { - assertFormattedExpression [ - expectation = ''' - typeof(String) - ''' - toBeFormatted = ''' - typeof ( String ) - ''' - ] - } - - @Test def formatXTypeLiteralArray1() { - assertFormattedExpression [ - expectation = ''' - typeof(String[]) - ''' - toBeFormatted = ''' - typeof ( String [ ]) - ''' - ] - } - - @Test def formatXTypeLiteralArray2() { - assertFormattedExpression [ - expectation = ''' - typeof(String[][]) - ''' - toBeFormatted = ''' - typeof ( String [ ] [ ] ) - ''' - ] - } - - @Test def formatXThrowExpression() { - assertFormattedExpression [ - expectation = ''' - throw new RuntimeException() - ''' - toBeFormatted = ''' - throw new RuntimeException() - ''' - ] - } - - @Test def formatXReturnExpression1() { - assertFormattedExpression [ - expectation = ''' - return "foo" - ''' - toBeFormatted = ''' - return "foo" - ''' - ] - } - - @Test def formatXReturnExpression2() { - assertFormattedExpression [ - expectation = ''' - "foo" - return - ''' - toBeFormatted = ''' - "foo" return - ''' - ] - } - - @Test def formatXReturnExpression3() { - assertFormattedExpression [ - expectation = ''' - return; - ''' - toBeFormatted = ''' - return ; - ''' - ] - } - - @Test def formatTryFinallyExpression1() { - assertFormattedExpression [ - expectation = ''' - try - println("x") - finally - println("y") - ''' - toBeFormatted = ''' - try println("x") finally println("y") - ''' - ] - } - - @Test def formatTryFinallyExpression2() { - assertFormattedExpression [ - expectation = ''' - try { - println("x") - } finally { - println("y") - } - ''' - toBeFormatted = ''' - try { println("x") } finally { println("y") } - ''' - ] - } - - @Test def formatTryCatchExpression11() { - assertFormattedExpression [ - preferences [ - put(whitespaceBetweenKeywordAndParenthesisML, true) - ] - toBeFormatted = ''' - try - println("x") - catch (Exception e) - println("y") - ''' - ] - } - - @Test def formatTryCatchExpression12() { - assertFormattedExpression [ - preferences [ - put(whitespaceBetweenKeywordAndParenthesisML, false) - ] - toBeFormatted = ''' - try - println("x") - catch(Exception e) - println("y") - ''' - ] - } - - @Test def formatTryCatchExpression2() { - assertFormattedExpression [ - expectation = ''' - try { - println("x") - } catch (Exception e) { - println("y") - } - ''' - toBeFormatted = ''' - try { println("x") } catch ( Exception e ) { println("y") } - ''' - ] - } - - @Test def formatTryCatchFinallyExpression1() { - assertFormattedExpression [ - expectation = ''' - try - println("x") - catch (Exception e) - println("y") - finally - println("z") - ''' - toBeFormatted = ''' - try println("x") catch ( Exception e ) println("y") finally println("z") - ''' - ] - } - - @Test def formatTryCatchFinallyExpressionBug474022() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, false) - ] - expectation = ''' - val i = try { - println("x") - 1 - } catch (Exception e) { - println("y") - 2 - } finally { - println("z") - } - ''' - toBeFormatted = ''' - val i = try { println("x") 1 } catch ( Exception e ) { println("y") 2 } finally { println("z") } - ''' - ] - } - - @Test def formatTryCatchFinallyExpression2() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, false) - ] - expectation = ''' - try { - println("x") - } catch (Exception e) { - println("y") - } finally { - println("z") - } - ''' - toBeFormatted = ''' - try { println("x") } catch ( Exception e ) { println("y") } finally { println("z") } - ''' - ] - } - - @Test def formatTryCatchFinallyExpression3() { - assertFormattedExpression [ - preferences [ - put(bracesInNewLine, true) - ] - expectation = ''' - try - { - println("x") - } - catch (Exception e) - { - println("y") - } - finally - { - println("z") - } - ''' - toBeFormatted = ''' - try { println("x") } catch ( Exception e ) { println("y") } finally { println("z") } - ''' - ] - } - - @Test def formatTryCatchCatchFinallyExpression1() { - assertFormattedExpression [ - expectation = ''' - try - println("x") - catch (Exception e) - println("y") - catch (Exception f) - println("z") - finally - println("a") - ''' - toBeFormatted = ''' - try println("x") catch ( Exception e ) println("y") catch ( Exception f ) println("z") finally println("a") - ''' - ] - } - - @Test def formatTryCatchCatchFinallyExpression2() { - assertFormattedExpression [ - expectation = ''' - try { - println("x") - } catch (Exception e) { - println("y") - } catch (Exception f) { - println("z") - } finally { - println("a") - } - ''' - toBeFormatted = ''' - try { println("x") } catch ( Exception e ) { println("y") } catch ( Exception f ) { println("z") } finally { println("a") } - ''' - ] - } - - @Test def formatListLiteral1() { - assertFormattedExpression [ - expectation = ''' - #[12, 13, 14] - ''' - toBeFormatted = ''' - #[12, 13 , 14 ] - ''' - ] - } - - @Test def formatListLiteral3() { - assertFormattedExpression [ - expectation = ''' - #[ - 12, - 13, - 14 - ] - ''' - toBeFormatted = ''' - #[12, 13 , 14 - ] - ''' - ] - } - - @Test def formatEmptySwitchSL() { - assertFormattedExpression [ - expectation = ''' - switch null { } - ''' - toBeFormatted = ''' - switch null { } - ''' - ] - } - - @Test def formatEmptySwitchSL_2() { - assertFormattedExpression [ - expectation = ''' - switch null { default: 1 } - ''' - toBeFormatted = ''' - switch null { default : 1 } - ''' - ] - } - - @Test def formatEmptySwitchML() { - assertFormattedExpression [ - expectation = ''' - switch null { - } - ''' - toBeFormatted = ''' - switch null { - - - - } - ''' - ] - } - - @Test def formatEmptySwitchML_2() { - assertFormattedExpression [ - expectation = ''' - switch null { - default: 1 - } - ''' - toBeFormatted = ''' - switch null { - - - - default : 1 - - } - ''' - ] - } - - @Test def formatInstanceOf() { - assertFormattedExpression [ - expectation = ''' - "x".toString instanceof String - ''' - toBeFormatted = ''' - "x".toString instanceof String - ''' - ] - } - - @Test def formatCast() { - assertFormattedExpression [ - expectation = ''' - "x" as String - ''' - toBeFormatted = ''' - "x" as String - ''' - ] - } - - @Test def formatPostfix() { - assertFormattedExpression [ - expectation = ''' - val i = j++ - ''' - toBeFormatted = ''' - val i = j ++ - ''' - ] - } - - @Test def void testFeatureCallWithParentheses() { - assertFormattedExpression [ - expectation = ''' - val it = "xxxx" - val j = true && (startsWith("x")) - ''' - toBeFormatted = ''' - val it = "xxxx" - val j = true&&(startsWith("x")) - ''' - ] - } - - @Test def void testMemberFeatureCallWithParentheses() { - assertFormattedExpression [ - expectation = ''' - val j = true && (class.startsWith("Hugo")) - ''' - toBeFormatted = ''' - val j = true&&(class.startsWith("Hugo")) - ''' - ] - } - - @Test def void testIssue527() { - assertFormattedExpression[ - expectation = ''' - var veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname = #[ - 1, 2, 3, 4, 5] - veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname. - map [ l | - veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname - ] - ''' - toBeFormatted = ''' - var veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname = #[1,2,3,4,5] - veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname.map[l|veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname] - - ''' - ] - } -} diff --git a/org.eclipse.xtext.xbase.tests/xtend-gen/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.java b/org.eclipse.xtext.xbase.tests/xtend-gen/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.java deleted file mode 100644 index 349ea292e4..0000000000 --- a/org.eclipse.xtext.xbase.tests/xtend-gen/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.eclipse.xtext.xbase.tests.formatting; - -import com.google.inject.Inject; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.testing.InjectWith; -import org.eclipse.xtext.testing.XtextRunner; -import org.eclipse.xtext.testing.formatter.FormatterTestRequest; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(XtextRunner.class) -@InjectWith(XbaseFormatterTestInjectorProvider.class) -@SuppressWarnings("all") -public class XbaseCommentFormatterTest { - @Inject - @Extension - private XbaseFormatterTester _xbaseFormatterTester; - - @Test - public void commentInIfExpression() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if (true)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\")"); - _builder.newLine(); - _builder.append("else // if (true)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"bar\")"); - _builder.newLine(); - _builder.append("println(\"end\")"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void commentAfterForExpression1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("for (f : #[])"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("if (1 < 2) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.newLine(); - _builder.append("// foo"); - _builder.newLine(); - _builder.append("var lastOffset = \"\""); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void commentAfterForExpression3() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ll = #[].map(e|e.toString) // error here"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } -} diff --git a/org.eclipse.xtext.xbase.tests/xtend-gen/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterTest.java b/org.eclipse.xtext.xbase.tests/xtend-gen/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterTest.java deleted file mode 100644 index fcde779f4c..0000000000 --- a/org.eclipse.xtext.xbase.tests/xtend-gen/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterTest.java +++ /dev/null @@ -1,2858 +0,0 @@ -package org.eclipse.xtext.xbase.tests.formatting; - -import com.google.inject.Inject; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.preferences.MapBasedPreferenceValues; -import org.eclipse.xtext.testing.InjectWith; -import org.eclipse.xtext.testing.XtextRunner; -import org.eclipse.xtext.testing.formatter.FormatterTestRequest; -import org.eclipse.xtext.xbase.formatting2.XbaseFormatterPreferenceKeys; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(XtextRunner.class) -@InjectWith(XbaseFormatterTestInjectorProvider.class) -@SuppressWarnings("all") -public class XbaseFormatterTest { - @Inject - @Extension - private XbaseFormatterTester _xbaseFormatterTester; - - @Test - public void formatGenerics() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = >newArrayList()"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatBlockExpression() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = newArrayList(\"A\", \"b\");"); - _builder.newLine(); - _builder.append("val y = \'foo\';"); - _builder.newLine(); - _builder.append("x.join"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val x = newArrayList(\"A\", \"b\") ; val y = \'foo\' ; x.join"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatBlockExpressionPreserveNewLines() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("{"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val x = newArrayList(\"A\", \"b\");"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val y = \'foo\'"); - _builder.newLine(); - _builder.newLine(); - _builder.append("\t"); - _builder.append("x.join"); - _builder.newLine(); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder.toString().trim()); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append(" "); - _builder_1.append("{ "); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("val x = newArrayList(\"A\", \"b\") ;"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("val y = \'foo\'"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("x.join"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("}"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormatted(_function); - } - - @Test - public void formatClosures() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = newArrayList(\"A\", \"b\")"); - _builder.newLine(); - _builder.append("val y = x.filter[toUpperCase == it]"); - _builder.newLine(); - _builder.append("y.join"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresParenthesis() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = newArrayList(\"A\", \"b\")"); - _builder.newLine(); - _builder.append("val y = x.filter(toUpperCase == it)"); - _builder.newLine(); - _builder.append("y.join"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresParenthesis2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = newArrayList(\"A\", \"b\")"); - _builder.newLine(); - _builder.append("val y = x.filter(foo|foo.toUpperCase == foo)"); - _builder.newLine(); - _builder.append("y.join"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresSemicolon() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("newArrayList(\"A\", \"b\").filter[val b = it; b.toUpperCase == b]"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("newArrayList(\"A\", \"b\").filter[ val b = it ; b.toUpperCase == b ]"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresEmpty() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = newArrayList(\"A\", \"b\")"); - _builder.newLine(); - _builder.append("val y = x.filter[]"); - _builder.newLine(); - _builder.append("y.join"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val x = newArrayList(\"A\", \"b\") val y = x.filter[ ] y.join"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresParam() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = newArrayList(\"A\", \"b\")"); - _builder.newLine(); - _builder.append("val y = x.filter[z|z.toUpperCase == z]"); - _builder.newLine(); - _builder.append("y.join"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresEmptyParam() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val Iterable x = [|#[].iterator]"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresMultiLine() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = newArrayList(\"A\", \"b\")"); - _builder.newLine(); - _builder.append("val y = x.filter ["); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val z = it"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("z.toUpperCase == z"); - _builder.newLine(); - _builder.append("]"); - _builder.newLine(); - _builder.append("y.join"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val x = newArrayList(\"A\", \"b\") val y = x.filter ["); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("val z = it z.toUpperCase == z "); - _builder_1.newLine(); - _builder_1.append("] y.join"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresMultiLine_02() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = newArrayList(\"A\", \"b\")"); - _builder.newLine(); - _builder.append("val y = x.filter ["); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val z = it"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("z.toUpperCase == z"); - _builder.newLine(); - _builder.append("]"); - _builder.newLine(); - _builder.append("y.join"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val x = newArrayList(\"A\", \"b\") val y = x.filter["); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("val z = it z.toUpperCase == z "); - _builder_1.newLine(); - _builder_1.append("] y.join"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresMultiLine03() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("new Thread [|"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\")"); - _builder.newLine(); - _builder.append("]"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("new Thread[ | println(\"foo\")"); - _builder_1.newLine(); - _builder_1.append("]"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresMultiLineSemicolon() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = newArrayList(\"A\", \"b\")"); - _builder.newLine(); - _builder.append("val y = x.filter ["); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val z = it;"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("z.toUpperCase == z;"); - _builder.newLine(); - _builder.append("]"); - _builder.newLine(); - _builder.append("y.join"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val x = newArrayList(\"A\", \"b\") val y = x.filter ["); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("val z = it ; z.toUpperCase == z ; "); - _builder_1.newLine(); - _builder_1.append("] y.join"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresWrapIfNeeded() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = newArrayList(\"A\", \"b\")"); - _builder.newLine(); - _builder.append("val y = x.filter ["); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val z = it"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("z.toUpperCase == z"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("z.toUpperCase == z"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("z.toUpperCase == z"); - _builder.newLine(); - _builder.append("]"); - _builder.newLine(); - _builder.append("y.join"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val x = newArrayList(\"A\", \"b\") val y = x.filter [ val z = it z.toUpperCase == z z.toUpperCase == z z.toUpperCase == z ] y.join"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresParamMultiLine() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = newArrayList(\"A\", \"b\")"); - _builder.newLine(); - _builder.append("val y = x.filter [ z |"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("val w = z"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("w.toUpperCase == w"); - _builder.newLine(); - _builder.append("]"); - _builder.newLine(); - _builder.append("y.join"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val x = newArrayList(\"A\", \"b\") val y = x.filter[ z |"); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("val w = z w.toUpperCase == w"); - _builder_1.newLine(); - _builder_1.append("] y.join"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatClosuresWithOperator() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = new StringBuffer() => ["); - _builder.newLine(); - _builder.append("\t"); - _builder.append("append(\"x\")"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("append(\"y\")"); - _builder.newLine(); - _builder.append("]"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val x = new StringBuffer() => ["); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("append(\"x\")"); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("append(\"y\")"); - _builder_1.newLine(); - _builder_1.append("]"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMultiLineClosureWithAssignment() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("x += foo.myBuilder ["); - _builder.newLine(); - _builder.append("\t"); - _builder.append("foo"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("bar"); - _builder.newLine(); - _builder.append("]"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("x += foo.myBuilder ["); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("foo bar"); - _builder_1.newLine(); - _builder_1.append("]"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSynchronizedBlock_1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("synchronized (new Object) {"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("synchronized(new Object){}"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSynchronizedBlock_2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("synchronized (new Object) {"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("synchronized ( new Object ) { }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIf1SL1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisSL, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if (true) println(\"foo\")"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIf1SL2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisSL, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if(true) println(\"foo\")"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIf1ML1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if (true)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\")"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIf1ML2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if(true)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\")"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIf1MLVar() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("var x = if (true)"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\"foo\")"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\"bar\")"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("var x = if(true)"); - _builder_1.newLine(); - _builder_1.append("println(\"foo\") else println(\"bar\")"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIf1MLSemicolon1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if (true)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\");"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("if(true)"); - _builder_1.newLine(); - _builder_1.append("println(\"foo\");"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIf1MLSemicolon2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if (true)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\");"); - _builder.newLine(); - _builder.append("println(\"bar\")"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("if(true)"); - _builder_1.newLine(); - _builder_1.append("println(\"foo\");"); - _builder_1.newLine(); - _builder_1.append("println(\"bar\")"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIf2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if (true) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIfElse1SL() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if(true) println(\"foo\") else println(\"bar\")"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("if(true)println(\"foo\")else println(\"bar\")"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIfElse1ML() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if (true)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\")"); - _builder.newLine(); - _builder.append("else"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"bar\")"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("if(true)"); - _builder_1.newLine(); - _builder_1.append("println(\"foo\")"); - _builder_1.newLine(); - _builder_1.append("else"); - _builder_1.newLine(); - _builder_1.append("println(\"bar\")"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIfElse2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if (true) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\")"); - _builder.newLine(); - _builder.append("} else {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"bar\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIfElse3() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if (true)"); - _builder.newLine(); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("else"); - _builder.newLine(); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"bar\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIfElseIf1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if (true)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\")"); - _builder.newLine(); - _builder.append("else if (false)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"bar\")"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("if(true)"); - _builder_1.newLine(); - _builder_1.append("println(\"foo\")"); - _builder_1.newLine(); - _builder_1.append("else if(false)"); - _builder_1.newLine(); - _builder_1.append("println(\"bar\")"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIfElseIf2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if (true) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\")"); - _builder.newLine(); - _builder.append("} else if (false) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"bar\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("if(true) {"); - _builder_1.newLine(); - _builder_1.append("println(\"foo\")"); - _builder_1.newLine(); - _builder_1.append("} else if(false) {"); - _builder_1.newLine(); - _builder_1.append("println(\"bar\")"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatIfElseIf3() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("if (true) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"foo\")"); - _builder.newLine(); - _builder.append("} else if (false)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"bar\")"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("if(true) {"); - _builder_1.newLine(); - _builder_1.append("println(\"foo\")"); - _builder_1.newLine(); - _builder_1.append("} else if(false)"); - _builder_1.newLine(); - _builder_1.append("println(\"bar\")"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatFor1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("for (i : 1 .. 2)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(i)"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("for ( i : 1 .. 2 ) println(i)"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatFor2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("for (i : 1 .. 2) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(i)"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatFor3() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("for (i : 1 .. 2)"); - _builder.newLine(); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(i)"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatBasicFor() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("for (var i = 1; i < 10; i = i + 1)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(i)"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("for ( var i = 1 ; i < 10; i = i + 1 ) println(i)"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatBasicFor2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("for (;;) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("return true"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("for ( ; ; ) { return true }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatBasicFor3() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("var int x"); - _builder.newLine(); - _builder.append("var int y"); - _builder.newLine(); - _builder.append("for (x = 1, y = 2;;) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("return x + y"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("var int x"); - _builder_1.newLine(); - _builder_1.append("var int y "); - _builder_1.newLine(); - _builder_1.append("for ( x = 1 , y = 2 ; ; ) { return x + y }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatBasicFor4() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = 1"); - _builder.newLine(); - _builder.append("for (; x < 10;)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(x)"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val x = 1"); - _builder_1.newLine(); - _builder_1.append("for ( ; x < 10 ; ) println(x)"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatBasicFor5() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val x = 1"); - _builder.newLine(); - _builder.append("for (;; x = x + 1, x = x + 2)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(x)"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val x = 1"); - _builder_1.newLine(); - _builder_1.append("for ( ; ; x = x \t+ 1 , x = x + 2 ) println(x)"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatBasicFor6() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("for (val x = 1;; x = x + 1, x = x + 2)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(x)"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("for (\t\t\tval \t\tx \t\t= \t\t1\t\t; ; x = x \t+ 1 , x = x + 2 ) println(x)"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatWhile11() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("while (true)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatWhile12() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("while(true)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatWhile2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("while (true) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatWhile21() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("while (true)"); - _builder.newLine(); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatDoWhile11() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("do"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("while (true)"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatDoWhile12() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("do"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("while(true)"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatDoWhile2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("do {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("} while (true)"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatDoWhile3() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("do"); - _builder.newLine(); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("while (true)"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchSL() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\' { case \'x\': println(\'x\') case \'y\': println(\'y\') }"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchSL1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\' { case \'x\': println(\'x\') case \'y\': println(\'y\') }"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchDefaultSL() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\' { case \'y\': println(\'y\') default: println(\'z\') }"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchDefaultSL1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\' { case \'y\': println(\'y\') default: println(\'z\') }"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchCaseSL1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\'"); - _builder.newLine(); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'x\': println(\'x\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'y\': println(\'y\')"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchCaseSLParenthesis() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\' {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'x\': println(\'x\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'y\': println(\'y\')"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch \'x\' { "); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("case \'x\': println(\'x\') case \'y\': println(\'y\')"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchCaseDefaultSL1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\'"); - _builder.newLine(); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'x\': println(\'x\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'y\': println(\'y\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("default: println(\'z\')"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchCaseDefaultSLParenthesis() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\' {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'x\': println(\'x\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'y\': println(\'y\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("default: println(\'z\')"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch \'x\' { "); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("case \'x\': println(\'x\') case \'y\': println(\'y\') default : println(\'z\')"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchML() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\' {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'x\':"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'x\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'y\':"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'y\')"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch \'x\' { "); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("case \'x\': "); - _builder_1.newLine(); - _builder_1.append("\t\t"); - _builder_1.append("println(\'x\') case \'y\': println(\'y\')"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchDefaultML() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\' {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'x\':"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'x\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'y\':"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'y\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("default:"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'z\')"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch \'x\' { "); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("case \'x\': "); - _builder_1.newLine(); - _builder_1.append("\t\t"); - _builder_1.append("println(\'x\') case \'y\': println(\'y\') default : println(\'z\')"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchDefault2ML() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\' {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'x\':"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'x\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'y\':"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'y\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("default:"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'z\')"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch \'x\' { "); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("case \'x\': println(\'x\') case \'y\': println(\'y\') "); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("default : "); - _builder_1.newLine(); - _builder_1.append("\t\t"); - _builder_1.append("println(\'z\')"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchDefault2MLFallThrough() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\' {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'x\',"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'y\':"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'y\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("default:"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'z\')"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch \'x\' { "); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("case \'x\' , case \'y\': println(\'y\') "); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("default : "); - _builder_1.newLine(); - _builder_1.append("\t\t"); - _builder_1.append("println(\'z\')"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchMLBlock() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\' {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'x\': {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'x\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'y\': {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'y\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch \'x\' { case \'x\': { println(\'x\') } case \'y\': { println(\'y\') } }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchDefaultMLBlock() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\' {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'x\': {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'x\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'y\': {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'y\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("default: {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'z\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch \'x\' { case \'x\': { println(\'x\') } case \'y\': { println(\'y\') } default: { println(\'z\') } }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatSwitchMLBlock1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch \'x\'"); - _builder.newLine(); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'x\':"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'x\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("case \'y\':"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\'y\')"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch \'x\' { case \'x\': { println(\'x\') } case \'y\': { println(\'y\') } }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatFeatureCallNoParenthesis() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val v1 = newArrayList"); - _builder.newLine(); - _builder.append("val v2 = newArrayList"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatFeatureCallNoParams() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val v1 = newArrayList()"); - _builder.newLine(); - _builder.append("val v2 = newArrayList()"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatFeatureCall1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML2 = newArrayList(newArrayList(1, 2, 3, 4, 5, 6),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("newArrayList(5, 6, 7, 8), newArrayList(9, 10, 11, 12),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("newArrayList(13, 14, 15, 16))"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML2 = newArrayList(newArrayList(1, 2, 3, 4, 5, 6), newArrayList(5, 6, 7, 8), newArrayList(9, 10, 11, 12), newArrayList(13, 14, 15, 16))"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatFeatureCall2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML2 = newArrayList(newArrayList(1, 2, 3, 4),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("newArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("newArrayList(9, 10, 11, 12), newArrayList(13, 14, 15, 16))"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML2 = newArrayList(newArrayList(1, 2, 3, 4), newArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), newArrayList(9, 10, 11, 12), newArrayList(13, 14, 15, 16))"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatFeatureCallMultiline() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML2 = newArrayList("); - _builder.newLine(); - _builder.append("\t"); - _builder.append("newArrayList(1, 2, 3, 4),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("newArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("newArrayList(9),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("newArrayList(10)"); - _builder.newLine(); - _builder.append(")"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML2 = newArrayList(newArrayList(1, 2, 3, 4), newArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), newArrayList(9), newArrayList(10)"); - _builder_1.newLine(); - _builder_1.append(")"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatConstructorCallNoParenthesis() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val v1 = new ArrayList"); - _builder.newLine(); - _builder.append("val v2 = new ArrayList"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatConstructorCallClosure() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("new Thread[|println(\"foo\")]"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatConstructorCallNoParams() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val v1 = new ArrayList()"); - _builder.newLine(); - _builder.append("val v2 = new ArrayList()"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatConstructorCall1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4, 5, 6),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("new ArrayList(5, 6, 7, 8), new ArrayList(9, 10, 11, 12),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("new ArrayList(13, 14, 15, 16))"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4, 5, 6), new ArrayList(5, 6, 7, 8), new ArrayList(9, 10, 11, 12), new ArrayList(13, 14, 15, 16))"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatConstructorCall2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("new ArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("new ArrayList(9, 10, 11, 12), new ArrayList(13, 14, 15, 16))"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4), new ArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), new ArrayList(9, 10, 11, 12), new ArrayList(13, 14, 15, 16))"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatConstructorCallMultiline() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML2 = new ArrayList("); - _builder.newLine(); - _builder.append("\t"); - _builder.append("new ArrayList(1, 2, 3, 4),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("new ArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109,"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("new ArrayList(9, 10, 11, 12),"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("new ArrayList(13, 14, 15, 16)"); - _builder.newLine(); - _builder.append(")"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML2 = new ArrayList(new ArrayList(1, 2, 3, 4), new ArrayList(5, 6, 7, 8, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120), new ArrayList(9, 10, 11, 12), new ArrayList(13, 14, 15, 16)"); - _builder_1.newLine(); - _builder_1.append(")"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMemberFeatureCallNoParenthesis() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val v1 = \"x\".toString"); - _builder.newLine(); - _builder.append("val v2 = \"x\".toString"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMemberFeatureCallNoParams() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val v1 = \"x\".toString()"); - _builder.newLine(); - _builder.append("val v2 = \"x\".toString()"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMemberFeatureCall1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML1 = \"x\".substring(0).substring(1).substring(2).substring(3)."); - _builder.newLine(); - _builder.append("\t"); - _builder.append("substring(4).substring(5).substring(6).substring(7).substring(8)."); - _builder.newLine(); - _builder.append("\t"); - _builder.append("substring(9).substring(10).substring(11)"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML1 = \"x\".substring(0).substring(1).substring(2).substring(3).substring(4).substring(5).substring(6).substring(7).substring(8).substring(9).substring(10).substring(11)"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMemberFeatureCall2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML1 = \"x\".substring(0).substring(1)"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML1 = \"x\""); - _builder_1.newLine(); - _builder_1.append("."); - _builder_1.newLine(); - _builder_1.append("substring(0)"); - _builder_1.newLine(); - _builder_1.append("."); - _builder_1.newLine(); - _builder_1.append("substring(1)"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMemberFeatureCall21() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML1 = \"x\".toString.toString"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML1 = \"x\""); - _builder_1.newLine(); - _builder_1.append("."); - _builder_1.newLine(); - _builder_1.append("toString"); - _builder_1.newLine(); - _builder_1.append("."); - _builder_1.newLine(); - _builder_1.append("toString"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMemberFeatureCall3() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML1 = \"x\".substring(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28)"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML1 = \"x\".substring(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28)"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMemberFeatureCall4() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML1 = \"x\".substring(0, 1, 2)"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML1 = \"x\".substring ("); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("0, "); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("1, "); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("2)"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMemberFeatureCallMultiline() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML1 = \"x\".substring("); - _builder.newLine(); - _builder.append("\t"); - _builder.append("0,"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("1,"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("2"); - _builder.newLine(); - _builder.append(")"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML1 = \"x\".substring ("); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("0, "); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("1, "); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("2"); - _builder_1.newLine(); - _builder_1.append(")"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMemberFeatureCallBuilder1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("newArrayList(\"x\").map()[]"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("newArrayList(\"x\") . map ( ) [ ]"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMemberFeatureCallBuilder2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("newArrayList(\"x\").map()[lenght]"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("newArrayList(\"x\") . map ( ) [ lenght ]"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMemberFeatureCallBuilderMultiline1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("newArrayList(\"x\").map("); - _builder.newLine(); - _builder.append("\t"); - _builder.append("length"); - _builder.newLine(); - _builder.append(")[lenght]"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("newArrayList(\"x\") . map ( length "); - _builder_1.newLine(); - _builder_1.append(") [ lenght ]"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatMemberFeatureCallBuilderMultiline2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("newArrayList(\"x\").map(length) ["); - _builder.newLine(); - _builder.append("\t"); - _builder.append("length"); - _builder.newLine(); - _builder.append("]"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("newArrayList(\"x\") . map ( length ) [ length "); - _builder_1.newLine(); - _builder_1.append("]"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - /** - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=461033 - */ - @Test - public void formatMemberFeatureCallParenthesized() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val s = (\"a\" + \"b\").substring(1)"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val s = (\"a\" + \"b\") . substring(1)"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatBinaryExpression1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 +"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 +"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("30 + 31 + 32 + 33 + 34 + 35 + 36"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 "); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatBinaryExpression2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val ML1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 +"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 + 19 + 20 + 21 + 22 + 23 + 24 +"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val ML1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 "); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatXTypeLiteral() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("typeof(String)"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("typeof ( String )"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatXTypeLiteralArray1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("typeof(String[])"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("typeof ( String [ ])"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatXTypeLiteralArray2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("typeof(String[][])"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("typeof ( String [ ] [ ] )"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatXThrowExpression() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("throw new RuntimeException()"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("throw new RuntimeException()"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatXReturnExpression1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("return \"foo\""); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("return \"foo\""); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatXReturnExpression2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("\"foo\""); - _builder.newLine(); - _builder.append("return"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("\"foo\" return"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatXReturnExpression3() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("return;"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("return ;"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatTryFinallyExpression1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("try"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("finally"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"y\")"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("try println(\"x\") finally println(\"y\")"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatTryFinallyExpression2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("try {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("} finally {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"y\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("try { println(\"x\") } finally { println(\"y\") }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatTryCatchExpression11() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("try"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("catch (Exception e)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"y\")"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatTryCatchExpression12() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.whitespaceBetweenKeywordAndParenthesisML, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("try"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("catch(Exception e)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"y\")"); - _builder.newLine(); - it.setToBeFormatted(_builder); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatTryCatchExpression2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("try {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("} catch (Exception e) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"y\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("try { println(\"x\") } catch ( Exception e ) { println(\"y\") }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatTryCatchFinallyExpression1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("try"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("catch (Exception e)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"y\")"); - _builder.newLine(); - _builder.append("finally"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"z\")"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("try println(\"x\") catch ( Exception e ) println(\"y\") finally println(\"z\")"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatTryCatchFinallyExpressionBug474022() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val i = try {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("1"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("} catch (Exception e) {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\"y\")"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("2"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("} finally {"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("println(\"z\")"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val i = try { println(\"x\") 1 } catch ( Exception e ) { println(\"y\") 2 } finally { println(\"z\") }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatTryCatchFinallyExpression2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("try {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("} catch (Exception e) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"y\")"); - _builder.newLine(); - _builder.append("} finally {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"z\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("try { println(\"x\") } catch ( Exception e ) { println(\"y\") } finally { println(\"z\") }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatTryCatchFinallyExpression3() { - final Procedure1 _function = (FormatterTestRequest it) -> { - final Procedure1 _function_1 = (MapBasedPreferenceValues it_1) -> { - it_1.put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(true)); - }; - it.preferences(_function_1); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("try"); - _builder.newLine(); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("catch (Exception e)"); - _builder.newLine(); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"y\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - _builder.append("finally"); - _builder.newLine(); - _builder.append("{"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"z\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("try { println(\"x\") } catch ( Exception e ) { println(\"y\") } finally { println(\"z\") }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatTryCatchCatchFinallyExpression1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("try"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("catch (Exception e)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"y\")"); - _builder.newLine(); - _builder.append("catch (Exception f)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"z\")"); - _builder.newLine(); - _builder.append("finally"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"a\")"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("try println(\"x\") catch ( Exception e ) println(\"y\") catch ( Exception f ) println(\"z\") finally println(\"a\")"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatTryCatchCatchFinallyExpression2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("try {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"x\")"); - _builder.newLine(); - _builder.append("} catch (Exception e) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"y\")"); - _builder.newLine(); - _builder.append("} catch (Exception f) {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"z\")"); - _builder.newLine(); - _builder.append("} finally {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("println(\"a\")"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("try { println(\"x\") } catch ( Exception e ) { println(\"y\") } catch ( Exception f ) { println(\"z\") } finally { println(\"a\") }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatListLiteral1() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("#[12, 13, 14]"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("#[12, 13 ,\t14\t\t]"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatListLiteral3() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("#["); - _builder.newLine(); - _builder.append("\t"); - _builder.append("12,"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("13,"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("14"); - _builder.newLine(); - _builder.append("]"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("#[12, 13 ,\t14\t\t"); - _builder_1.newLine(); - _builder_1.append("]"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatEmptySwitchSL() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch null { }"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch null { }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatEmptySwitchSL_2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch null { default: 1 }"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch null { default : 1 }"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatEmptySwitchML() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch null {"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch null { "); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatEmptySwitchML_2() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("switch null {"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("default: 1"); - _builder.newLine(); - _builder.append("}"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("switch null { "); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.append("default : 1"); - _builder_1.newLine(); - _builder_1.append("\t"); - _builder_1.newLine(); - _builder_1.append("}"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatInstanceOf() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("\"x\".toString instanceof String"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("\"x\".toString instanceof String"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatCast() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("\"x\" as String"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("\"x\" as String"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void formatPostfix() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val i = j++"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val i = j ++"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void testFeatureCallWithParentheses() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val it = \"xxxx\""); - _builder.newLine(); - _builder.append("val j = true && (startsWith(\"x\"))"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val it = \"xxxx\""); - _builder_1.newLine(); - _builder_1.append("val j = true&&(startsWith(\"x\"))"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void testMemberFeatureCallWithParentheses() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("val j = true && (class.startsWith(\"Hugo\"))"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("val j = true&&(class.startsWith(\"Hugo\"))"); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } - - @Test - public void testIssue527() { - final Procedure1 _function = (FormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("var veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname = #["); - _builder.newLine(); - _builder.append("\t"); - _builder.append("1, 2, 3, 4, 5]"); - _builder.newLine(); - _builder.append("veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname."); - _builder.newLine(); - _builder.append("\t"); - _builder.append("map [ l |"); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("]"); - _builder.newLine(); - it.setExpectation(_builder); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("var veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname = #[1,2,3,4,5]"); - _builder_1.newLine(); - _builder_1.append("veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname.map[l|veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryname]"); - _builder_1.newLine(); - _builder_1.newLine(); - it.setToBeFormatted(_builder_1); - }; - this._xbaseFormatterTester.assertFormattedExpression(_function); - } -}