mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
add test for IProjectConfig#isIndexOnly
Signed-off-by: mmews <marcus.mews@numberfour.eu>
This commit is contained in:
parent
c59ce4d0db
commit
8e3550e61b
2 changed files with 274 additions and 0 deletions
|
@ -0,0 +1,118 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.tests.server
|
||||
|
||||
import org.eclipse.lsp4j.DidChangeWatchedFilesParams
|
||||
import org.eclipse.lsp4j.FileChangeType
|
||||
import org.eclipse.lsp4j.FileEvent
|
||||
import org.junit.Test
|
||||
|
||||
import static org.junit.Assert.*
|
||||
import com.google.inject.Module
|
||||
import org.eclipse.xtext.util.Modules2
|
||||
import org.eclipse.xtext.ide.server.ServerModule
|
||||
import org.eclipse.xtext.ide.server.IWorkspaceConfigFactory
|
||||
import org.eclipse.xtext.ide.server.ProjectWorkspaceConfigFactory
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.xtext.workspace.WorkspaceConfig
|
||||
import org.eclipse.xtext.workspace.FileProjectConfig
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Checks functionality of method IProjectConfig#isIndexOnly()
|
||||
*
|
||||
* @author Marcus Mews - Initial contribution and API
|
||||
*/
|
||||
class IndexOnlyProjectTest extends AbstractTestLangLanguageServerTest {
|
||||
|
||||
override Module getServerModule() {
|
||||
Modules2.mixin(new ServerModule, [
|
||||
bind(IWorkspaceConfigFactory).toInstance(new ProjectWorkspaceConfigFactory() {
|
||||
|
||||
override findProjects(WorkspaceConfig workspaceConfig, URI location) {
|
||||
if (location !== null) {
|
||||
val FileProjectConfig project = new FileProjectConfig(location, workspaceConfig){
|
||||
override boolean isIndexOnly() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
project.addSourceFolder(".");
|
||||
workspaceConfig.addProject(project);
|
||||
}
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
/** Shows that the resource is indexed */
|
||||
@Test
|
||||
def void testIndexByUsingReferences() {
|
||||
testReferences[
|
||||
model = '''
|
||||
type Foo {}
|
||||
type Bar {
|
||||
Foo foo
|
||||
}
|
||||
'''
|
||||
column = 'type F'.length
|
||||
expectedReferences = '''
|
||||
MyModel.testlang [[2, 1] .. [2, 4]]
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
/** Shows that the resource is not validated during initial build */
|
||||
@Test
|
||||
def void testInitializeBuildNoValidation() {
|
||||
'MyType1.testlang'.writeFile( '''
|
||||
type Test {
|
||||
NonExisting foo
|
||||
}
|
||||
''')
|
||||
initialize
|
||||
assertTrue(diagnostics.entrySet.join(','), diagnostics.empty)
|
||||
}
|
||||
|
||||
/** Shows that the error-free resource is not generated during initial build */
|
||||
@Test
|
||||
def void testInitializeBuildNoGeneration() {
|
||||
'MyType1.testlang'.writeFile( '''
|
||||
type TestType {
|
||||
int foo
|
||||
}
|
||||
''')
|
||||
initialize
|
||||
|
||||
val outputFile = new File(root, "src-gen/TestType.java");
|
||||
assertFalse(diagnostics.entrySet.join(','), outputFile.isFile)
|
||||
}
|
||||
|
||||
/** Shows that the resource is not validated during incremental build */
|
||||
@Test
|
||||
def void testIncrementalBuildNoValidation() {
|
||||
'MyType1.testlang'.writeFile( '''
|
||||
type Test {
|
||||
NonExisting foo
|
||||
}
|
||||
''')
|
||||
initialize
|
||||
assertTrue(diagnostics.entrySet.join(','), diagnostics.empty)
|
||||
|
||||
val path = 'MyType2.testlang'.writeFile('''
|
||||
type NonExisting {
|
||||
}
|
||||
''')
|
||||
|
||||
languageServer.getWorkspaceService.didChangeWatchedFiles(
|
||||
new DidChangeWatchedFilesParams(#[new FileEvent(path, FileChangeType.Created)])
|
||||
)
|
||||
assertTrue(diagnostics.entrySet.join(','), diagnostics.empty)
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.xtext.ide.tests.server;
|
||||
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.binder.AnnotatedBindingBuilder;
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
|
||||
import org.eclipse.lsp4j.FileChangeType;
|
||||
import org.eclipse.lsp4j.FileEvent;
|
||||
import org.eclipse.lsp4j.services.WorkspaceService;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.server.IWorkspaceConfigFactory;
|
||||
import org.eclipse.xtext.ide.server.ProjectWorkspaceConfigFactory;
|
||||
import org.eclipse.xtext.ide.server.ServerModule;
|
||||
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
|
||||
import org.eclipse.xtext.testing.ReferenceTestConfiguration;
|
||||
import org.eclipse.xtext.util.Modules2;
|
||||
import org.eclipse.xtext.workspace.FileProjectConfig;
|
||||
import org.eclipse.xtext.workspace.WorkspaceConfig;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Checks functionality of method IProjectConfig#isIndexOnly()
|
||||
*
|
||||
* @author Marcus Mews - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class IndexOnlyProjectTest extends AbstractTestLangLanguageServerTest {
|
||||
@Override
|
||||
public com.google.inject.Module getServerModule() {
|
||||
ServerModule _serverModule = new ServerModule();
|
||||
final com.google.inject.Module _function = (Binder it) -> {
|
||||
AnnotatedBindingBuilder<IWorkspaceConfigFactory> _bind = it.<IWorkspaceConfigFactory>bind(IWorkspaceConfigFactory.class);
|
||||
_bind.toInstance(new ProjectWorkspaceConfigFactory() {
|
||||
@Override
|
||||
public void findProjects(final WorkspaceConfig workspaceConfig, final URI location) {
|
||||
if ((location != null)) {
|
||||
final FileProjectConfig project = new FileProjectConfig(location, workspaceConfig) {
|
||||
@Override
|
||||
public boolean isIndexOnly() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
project.addSourceFolder(".");
|
||||
workspaceConfig.addProject(project);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
return Modules2.mixin(_serverModule, _function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows that the resource is indexed
|
||||
*/
|
||||
@Test
|
||||
public void testIndexByUsingReferences() {
|
||||
final Procedure1<ReferenceTestConfiguration> _function = (ReferenceTestConfiguration 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.setColumn("type F".length());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("MyModel.testlang [[2, 1] .. [2, 4]]");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedReferences(_builder_1.toString());
|
||||
};
|
||||
this.testReferences(_function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows that the resource is not validated during initial build
|
||||
*/
|
||||
@Test
|
||||
public void testInitializeBuildNoValidation() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Test {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("NonExisting foo");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
this.writeFile("MyType1.testlang", _builder);
|
||||
this.initialize();
|
||||
Assert.assertTrue(IterableExtensions.join(this.getDiagnostics().entrySet(), ","), this.getDiagnostics().isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows that the error-free resource is not generated during initial build
|
||||
*/
|
||||
@Test
|
||||
public void testInitializeBuildNoGeneration() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type TestType {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("int foo");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
this.writeFile("MyType1.testlang", _builder);
|
||||
this.initialize();
|
||||
final File outputFile = new File(this.root, "src-gen/TestType.java");
|
||||
Assert.assertFalse(IterableExtensions.join(this.getDiagnostics().entrySet(), ","), outputFile.isFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows that the resource is not validated during incremental build
|
||||
*/
|
||||
@Test
|
||||
public void testIncrementalBuildNoValidation() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Test {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("NonExisting foo");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
this.writeFile("MyType1.testlang", _builder);
|
||||
this.initialize();
|
||||
Assert.assertTrue(IterableExtensions.join(this.getDiagnostics().entrySet(), ","), this.getDiagnostics().isEmpty());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("type NonExisting {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
final String path = this.writeFile("MyType2.testlang", _builder_1);
|
||||
WorkspaceService _workspaceService = this.languageServer.getWorkspaceService();
|
||||
FileEvent _fileEvent = new FileEvent(path, FileChangeType.Created);
|
||||
DidChangeWatchedFilesParams _didChangeWatchedFilesParams = new DidChangeWatchedFilesParams(Collections.<FileEvent>unmodifiableList(CollectionLiterals.<FileEvent>newArrayList(_fileEvent)));
|
||||
_workspaceService.didChangeWatchedFiles(_didChangeWatchedFilesParams);
|
||||
Assert.assertTrue(IterableExtensions.join(this.getDiagnostics().entrySet(), ","), this.getDiagnostics().isEmpty());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue