Search in sources :

Example 6 with FormatterTestRequest

use of org.eclipse.xtext.testing.formatter.FormatterTestRequest in project xtext-xtend by eclipse.

the class XtendFormatterBugTests method bug403340.

@Test
public void bug403340() {
    final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(120));
        };
        it.preferences(_function_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void format(String v1, String v2) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (v1 === v2)");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.append("Same");
        _builder.append("\'", "\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("else");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.append("Not the Same");
        _builder.append("\'", "\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        it.setToBeFormatted(_builder);
    };
    this.tester.assertFormatted(_function);
}
Also used : Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) FormatterTestRequest(org.eclipse.xtext.testing.formatter.FormatterTestRequest) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 7 with FormatterTestRequest

use of org.eclipse.xtext.testing.formatter.FormatterTestRequest in project xtext-xtend by eclipse.

the class XtendFormatterBugTests method bug403823.

@Test
public void bug403823() {
    final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(120));
        };
        it.preferences(_function_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void format(String a, String b, String c) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (a != b)");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.append("(");
        _builder.append("�", "\t\t\t");
        _builder.append("c");
        _builder.append("�", "\t\t\t");
        _builder.append(")");
        _builder.append("\'", "\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.append("\'", "\t\t\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("else");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("\'\'");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        it.setToBeFormatted(_builder);
    };
    this.tester.assertFormatted(_function);
}
Also used : Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) FormatterTestRequest(org.eclipse.xtext.testing.formatter.FormatterTestRequest) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 8 with FormatterTestRequest

use of org.eclipse.xtext.testing.formatter.FormatterTestRequest in project xtext-eclipse by eclipse.

the class FormatterTest method example1.

/**
 * This example tests if the formatted document equals the unformatted document.
 * This is the most convenient way to test a formatter.
 */
@Test
public void example1() {
    final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("entity Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("propertyName:String");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("op name() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("val x = 1 + 2 + 4");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("val foo = {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("println()");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("println()");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("null");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        it.setToBeFormatted(_builder);
    };
    this._formatterTestHelper.assertFormatted(_function);
}
Also used : FormatterTestRequest(org.eclipse.xtext.testing.formatter.FormatterTestRequest) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 9 with FormatterTestRequest

use of org.eclipse.xtext.testing.formatter.FormatterTestRequest in project xtext-eclipse by eclipse.

the class FormatterTest method example2.

/**
 * This example tests whether a messy document is being formatted properly.
 * In contrast to the first example, this approach also allows to test formatting strategies that are input-aware.
 * Example: "Change newLines between tokens to be one at minimum, two at maximum."
 * Here, it depends on the formatters input document whether there will be one or two newLines on the output.
 */
@Test
public void example2() {
    final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("entity Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("op foo():String {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("\"xx\"");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        it.setExpectation(_builder);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("entity Foo {  op  foo  (  )  :  String  {  \"xx\"  }  }");
        _builder_1.newLine();
        it.setToBeFormatted(_builder_1);
    };
    this._formatterTestHelper.assertFormatted(_function);
}
Also used : FormatterTestRequest(org.eclipse.xtext.testing.formatter.FormatterTestRequest) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 10 with FormatterTestRequest

use of org.eclipse.xtext.testing.formatter.FormatterTestRequest in project xtext-eclipse by eclipse.

the class FormatterTest method example3.

/**
 * This example shows how to test property-dependent formatting behavior.
 */
@Test
public void example3() {
    final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<String>put(FormatterPreferenceKeys.indentation, " ");
        };
        it.preferences(_function_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("entity Foo {");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("op foo():String {");
        _builder.newLine();
        _builder.append("  ");
        _builder.append("\"xx\"");
        _builder.newLine();
        _builder.append(" ");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        it.setExpectation(_builder);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("entity Foo {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("op foo():String {");
        _builder_1.newLine();
        _builder_1.append("\t\t");
        _builder_1.append("\"xx\"");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        it.setToBeFormatted(_builder_1);
    };
    this._formatterTestHelper.assertFormatted(_function);
}
Also used : Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) FormatterTestRequest(org.eclipse.xtext.testing.formatter.FormatterTestRequest) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Aggregations

FormatterTestRequest (org.eclipse.xtext.testing.formatter.FormatterTestRequest)10 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)9 Test (org.junit.Test)9 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)8 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)8 Collection (java.util.Collection)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1 TextRegion (org.eclipse.xtext.util.TextRegion)1