use of org.eclipse.xtext.testing.RangeFormattingConfiguration in project xtext-core by eclipse.
the class AbstractLanguageServerTest method testRangeFormatting.
protected void testRangeFormatting(final Procedure1<? super DocumentRangeFormattingParams> paramsConfigurator, final Procedure1<? super RangeFormattingConfiguration> configurator) {
try {
@Extension final RangeFormattingConfiguration configuration = new RangeFormattingConfiguration();
configuration.setFilePath(("MyModel." + this.fileExtension));
configurator.apply(configuration);
final FileInfo fileInfo = this.initializeContext(configuration);
DocumentRangeFormattingParams _documentRangeFormattingParams = new DocumentRangeFormattingParams();
final Procedure1<DocumentRangeFormattingParams> _function = (DocumentRangeFormattingParams it) -> {
String _uri = fileInfo.getUri();
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
it.setTextDocument(_textDocumentIdentifier);
it.setRange(configuration.getRange());
if ((paramsConfigurator != null)) {
paramsConfigurator.apply(it);
}
};
DocumentRangeFormattingParams _doubleArrow = ObjectExtensions.<DocumentRangeFormattingParams>operator_doubleArrow(_documentRangeFormattingParams, _function);
final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.rangeFormatting(_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.RangeFormattingConfiguration in project xtext-core by eclipse.
the class FormattingTest method testRangeFormattingService.
@Test
public void testRangeFormattingService() {
final Procedure1<RangeFormattingConfiguration> _function = (RangeFormattingConfiguration it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Foo{int bar} type Bar{Foo foo}");
it.setModel(_builder.toString());
Range _range = new Range();
final Procedure1<Range> _function_1 = (Range it_1) -> {
Position _position = new Position(0, 0);
it_1.setStart(_position);
Position _position_1 = new Position(0, 17);
it_1.setEnd(_position_1);
};
Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
it.setRange(_doubleArrow);
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("} type Bar{Foo foo}");
it.setExpectedText(_builder_1.toString());
};
this.testRangeFormatting(_function);
}
use of org.eclipse.xtext.testing.RangeFormattingConfiguration in project xtext-core by eclipse.
the class FormattingTest method testRangeFormattingService_02.
@Test
public void testRangeFormattingService_02() {
final Procedure1<DocumentRangeFormattingParams> _function = (DocumentRangeFormattingParams it) -> {
FormattingOptions _formattingOptions = new FormattingOptions(4, true);
it.setOptions(_formattingOptions);
};
final Procedure1<RangeFormattingConfiguration> _function_1 = (RangeFormattingConfiguration it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Foo{int bar} type Bar{Foo foo}");
it.setModel(_builder.toString());
Range _range = new Range();
final Procedure1<Range> _function_2 = (Range it_1) -> {
Position _position = new Position(0, 0);
it_1.setStart(_position);
Position _position_1 = new Position(0, 17);
it_1.setEnd(_position_1);
};
Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_2);
it.setRange(_doubleArrow);
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("} type Bar{Foo foo}");
it.setExpectedText(_builder_1.toString());
};
this.testRangeFormatting(_function, _function_1);
}
Aggregations