use of org.eclipse.xtext.testing.FormattingConfiguration in project xtext-core by eclipse.
the class FormattingTest method testFormattingClosedFile.
@Test
public void testFormattingClosedFile() {
final Procedure1<FormattingConfiguration> _function = (FormattingConfiguration it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Foo{int bar} type Bar{Foo foo}");
Pair<String, String> _mappedTo = Pair.<String, String>of("foo.testlang", _builder.toString());
it.setFilesInScope(Collections.<String, CharSequence>unmodifiableMap(CollectionLiterals.<String, CharSequence>newHashMap(_mappedTo)));
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("type Foo{");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("int bar");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("type Bar{");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo foo");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
it.setExpectedText(_builder_1.toString());
};
this.testFormatting(_function);
}
use of org.eclipse.xtext.testing.FormattingConfiguration in project xtext-core by eclipse.
the class AbstractLanguageServerTest method testFormatting.
protected void testFormatting(final Procedure1<? super DocumentFormattingParams> paramsConfigurator, final Procedure1<? super FormattingConfiguration> configurator) {
try {
@Extension final FormattingConfiguration configuration = new FormattingConfiguration();
configuration.setFilePath(("MyModel." + this.fileExtension));
configurator.apply(configuration);
final FileInfo fileInfo = this.initializeContext(configuration);
DocumentFormattingParams _documentFormattingParams = new DocumentFormattingParams();
final Procedure1<DocumentFormattingParams> _function = (DocumentFormattingParams it) -> {
String _uri = fileInfo.getUri();
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
it.setTextDocument(_textDocumentIdentifier);
if ((paramsConfigurator != null)) {
paramsConfigurator.apply(it);
}
};
DocumentFormattingParams _doubleArrow = ObjectExtensions.<DocumentFormattingParams>operator_doubleArrow(_documentFormattingParams, _function);
final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.formatting(_doubleArrow);
String _contents = fileInfo.getContents();
final Document result = new Document(1, _contents).applyChanges(ListExtensions.<TextEdit>reverse(CollectionLiterals.<TextEdit>newArrayList(((TextEdit[]) Conversions.unwrapArray(changes.get(), TextEdit.class)))));
this.assertEqualsStricter(configuration.getExpectedText(), result.getContents());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.testing.FormattingConfiguration in project xtext-core by eclipse.
the class FormattingTest method testFormattingService.
@Test
public void testFormattingService() {
final Procedure1<FormattingConfiguration> _function = (FormattingConfiguration it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Foo{int bar} type Bar{Foo foo}");
it.setModel(_builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("type Foo{");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("int bar");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("type Bar{");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("Foo foo");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
it.setExpectedText(_builder_1.toString());
};
this.testFormatting(_function);
}
use of org.eclipse.xtext.testing.FormattingConfiguration in project xtext-core by eclipse.
the class FormattingTest method testFormattingService_02.
@Test
public void testFormattingService_02() {
final Procedure1<DocumentFormattingParams> _function = (DocumentFormattingParams it) -> {
FormattingOptions _formattingOptions = new FormattingOptions(4, true);
it.setOptions(_formattingOptions);
};
final Procedure1<FormattingConfiguration> _function_1 = (FormattingConfiguration it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Foo{int bar} type Bar{Foo foo}");
it.setModel(_builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("type Foo{");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("int bar");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("type Bar{");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("Foo foo");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
it.setExpectedText(_builder_1.toString());
};
this.testFormatting(_function, _function_1);
}
Aggregations