org.eclipse.xtext.testing.formatter.FormatterTestRequest Java Examples

The following examples show how to use org.eclipse.xtext.testing.formatter.FormatterTestRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatFor1() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #2
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatConstructorCall1() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #3
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatXReturnExpression2() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #4
Source File: AbstractXtendFormatterTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public void assertFormatted(final Procedure1<? super MapBasedPreferenceValues> cfg, final CharSequence expectation, final CharSequence toBeFormatted, final String prefix, final String postfix, final boolean allowErrors) {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
      it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(80));
      it_1.<Boolean>put(XtendFormatterPreferenceKeys.keepOneLineMethods, Boolean.valueOf(false));
      if (cfg!=null) {
        cfg.apply(it_1);
      }
    };
    it.preferences(_function_1);
    it.setExpectation(((prefix + expectation) + postfix));
    it.setToBeFormatted(((prefix + toBeFormatted) + postfix));
    Collection<ITextRegion> _regions = it.getRequest().getRegions();
    int _length = prefix.length();
    int _length_1 = toBeFormatted.length();
    TextRegion _textRegion = new TextRegion(_length, _length_1);
    _regions.add(_textRegion);
    it.setAllowSyntaxErrors(allowErrors);
  };
  this.tester.assertFormatted(_function);
}
 
Example #5
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatMemberFeatureCall4() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #6
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatMemberFeatureCall2() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #7
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatBinaryExpression1() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #8
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatFeatureCall1() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #9
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatDoWhile3() {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
      it_1.<Boolean>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);
}
 
Example #10
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatSynchronizedBlock_1() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #11
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatSynchronizedBlock_2() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #12
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatTryFinallyExpression2() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #13
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatDoWhile11() {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
      it_1.<Boolean>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);
}
 
Example #14
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatIf1MLVar() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #15
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatMemberFeatureCall3() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #16
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatFor2() {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
      it_1.<Boolean>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);
}
 
Example #17
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatTryCatchExpression2() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #18
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatBasicFor() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #19
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatMemberFeatureCallBuilderMultiline2() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #20
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatMemberFeatureCallBuilderMultiline1() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #21
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatBasicFor4() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #22
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatBasicFor5() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #23
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatWhile11() {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
      it_1.<Boolean>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);
}
 
Example #24
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatWhile12() {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
      it_1.<Boolean>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);
}
 
Example #25
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void formatWhile2() {
  final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
    final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
      it_1.<Boolean>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);
}
 
Example #26
Source File: FormatterTester.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void assertFormatted(FormatterTestRequest req) {
	checkNotNull(req);
	checkNotNull(req.getToBeFormatted());

	FormatterRequest request = req.getRequest();
	checkArgument(request.getTextRegionAccess() == null);

	String document = req.getToBeFormatted().toString();
	XtextResource parsed = parse(document);
	if (req.isAllowSyntaxErrors()) {
		request.setExceptionHandler(ExceptionAcceptor.IGNORING);
	} else {
		assertNoSyntaxErrors(parsed);
		request.setExceptionHandler(ExceptionAcceptor.THROWING);
	}
	request.setTextRegionAccess(createRegionAccess(parsed, req));
	if (request.getPreferences() == null)
		request.setPreferences(new MapBasedPreferenceValues(Maps.<String, String> newLinkedHashMap()));
	List<ITextReplacement> replacements = createFormatter(req).format(request);
	assertReplacementsAreInRegion(replacements, request.getRegions(), document);
	if (!req.isAllowUnformattedWhitespace())
		assertAllWhitespaceIsFormatted(request.getTextRegionAccess(), replacements);
	String formatted = request.getTextRegionAccess().getRewriter().renderToString(replacements);

	Assert.assertEquals(req.getExpectationOrToBeFormatted().toString(), formatted);

	// TODO: assert formatting a second time only produces identity replacements
	// TODO: assert formatting with undefined whitespace only
}
 
Example #27
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void formatFeatureCallMultiline() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #28
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testIssue527() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #29
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void formatBasicFor3() {
  final Procedure1<FormatterTestRequest> _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);
}
 
Example #30
Source File: XbaseFormatterTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void formatConstructorCallNoParenthesis() {
  final Procedure1<FormatterTestRequest> _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);
}