Search in sources :

Example 1 with DefinitionTestConfiguration

use of org.eclipse.xtext.testing.DefinitionTestConfiguration in project xtext-core by eclipse.

the class AbstractLanguageServerTest method testDefinition.

protected void testDefinition(final Procedure1<? super DefinitionTestConfiguration> configurator) {
    try {
        @Extension final DefinitionTestConfiguration configuration = new DefinitionTestConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String fileUri = this.initializeContext(configuration).getUri();
        TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
        final Procedure1<TextDocumentPositionParams> _function = (TextDocumentPositionParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
            it.setTextDocument(_textDocumentIdentifier);
            int _line = configuration.getLine();
            int _column = configuration.getColumn();
            Position _position = new Position(_line, _column);
            it.setPosition(_position);
        };
        TextDocumentPositionParams _doubleArrow = ObjectExtensions.<TextDocumentPositionParams>operator_doubleArrow(_textDocumentPositionParams, _function);
        final CompletableFuture<List<? extends Location>> definitionsFuture = this.languageServer.definition(_doubleArrow);
        final List<? extends Location> definitions = definitionsFuture.get();
        Procedure1<? super List<? extends Location>> _assertDefinitions = configuration.getAssertDefinitions();
        boolean _tripleNotEquals = (_assertDefinitions != null);
        if (_tripleNotEquals) {
            configuration.getAssertDefinitions().apply(definitions);
        } else {
            final String actualDefinitions = this.toExpectation(definitions);
            this.assertEquals(configuration.getExpectedDefinitions(), actualDefinitions);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) DefinitionTestConfiguration(org.eclipse.xtext.testing.DefinitionTestConfiguration) Extension(org.eclipse.xtext.xbase.lib.Extension) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) Location(org.eclipse.lsp4j.Location)

Example 2 with DefinitionTestConfiguration

use of org.eclipse.xtext.testing.DefinitionTestConfiguration in project xtext-core by eclipse.

the class DefinitionTest method testDefinition_01.

@Test
public void testDefinition_01() {
    final Procedure1<DefinitionTestConfiguration> _function = (DefinitionTestConfiguration it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type Foo {}");
        _builder.newLine();
        _builder.append("type Bar {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("Foo foo");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        it.setModel(_builder.toString());
        it.setLine(2);
        it.setColumn(3);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("MyModel.testlang [[0, 5] .. [0, 8]]");
        _builder_1.newLine();
        it.setExpectedDefinitions(_builder_1.toString());
    };
    this.testDefinition(_function);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) DefinitionTestConfiguration(org.eclipse.xtext.testing.DefinitionTestConfiguration) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Aggregations

DefinitionTestConfiguration (org.eclipse.xtext.testing.DefinitionTestConfiguration)2 List (java.util.List)1 CompletionList (org.eclipse.lsp4j.CompletionList)1 Location (org.eclipse.lsp4j.Location)1 Position (org.eclipse.lsp4j.Position)1 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)1 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 AbstractTestLangLanguageServerTest (org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1 Test (org.junit.Test)1