Add a regression test for '.yaml'.

Checks that boot language server accepts '.yaml' as equivalent
to '.yml' for reconcile, completions and hovers.
This commit is contained in:
Kris De Volder
2019-01-31 16:02:43 -08:00
parent 2a83e31172
commit 306d116681
4 changed files with 52 additions and 9 deletions

View File

@@ -138,10 +138,14 @@ public class Editor {
private LanguageId languageId;
public Editor(LanguageServerHarness harness, String contents, LanguageId languageId) throws Exception {
this(harness, contents, languageId, null);
}
public Editor(LanguageServerHarness harness, String contents, LanguageId languageId, String extension) throws Exception {
this.harness = harness;
this.languageId = LanguageId.of(languageId.getId()); // So we can catch bugs that use == for langauge id comparison.
EditorState state = new EditorState(contents);
this.doc = harness.openDocument(harness.createWorkingCopy(state.documentContents, this.languageId));
this.doc = harness.openDocument(harness.createWorkingCopy(state.documentContents, this.languageId, extension));
this.selectionStart = state.selectionStart;
this.selectionEnd = state.selectionEnd;
this.ignoredTypes = new HashSet<>();

View File

@@ -585,6 +585,12 @@ public class LanguageServerHarness {
return newEditor(getDefaultLanguageId(), contents);
}
public synchronized Editor newEditorWithExt(LanguageId languageId, String extension, String contents) throws Exception {
Editor editor = new Editor(this, contents, languageId, extension);
activeEditors.add(editor);
return editor;
}
public synchronized Editor newEditor(LanguageId languageId, String contents) throws Exception {
Editor editor = new Editor(this, contents, languageId);
activeEditors.add(editor);
@@ -610,11 +616,11 @@ public class LanguageServerHarness {
return docinfo;
}
public synchronized TextDocumentInfo createWorkingCopy(String contents, LanguageId languageId) throws Exception {
public synchronized TextDocumentInfo createWorkingCopy(String contents, LanguageId languageId, String extension) throws Exception {
TextDocumentItem doc = new TextDocumentItem();
doc.setLanguageId(languageId.getId());
doc.setText(contents);
doc.setUri(createTempUri());
doc.setUri(createTempUri(extension));
doc.setVersion(getFirstVersion());
TextDocumentInfo docinfo = new TextDocumentInfo(doc);
documents.put(docinfo.getUri(), docinfo);
@@ -625,8 +631,11 @@ public class LanguageServerHarness {
return 1;
}
public String createTempUri() throws Exception {
return File.createTempFile("workingcopy", getFileExtension()).toURI().toString();
public String createTempUri(String extension) throws Exception {
if (extension == null) {
extension = getFileExtension();
}
return File.createTempFile("workingcopy", extension).toURI().toString();
}
public void assertCompletion(String textBefore, String expectTextAfter) throws Exception {

View File

@@ -112,7 +112,7 @@ public class CompilationUnitCacheTest {
harness.useProject(ProjectsHarness.dummyProject());
harness.intialize(null);
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" +
TextDocument doc = new TextDocument(harness.createTempUri(null), LanguageId.JAVA, 0, "package my.package\n" +
"\n" +
"public class SomeClass {\n" +
"\n" +
@@ -128,7 +128,7 @@ public class CompilationUnitCacheTest {
public void cu_not_generated_without_project() throws Exception {
harness.intialize(null);
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" +
TextDocument doc = new TextDocument(harness.createTempUri(null), LanguageId.JAVA, 0, "package my.package\n" +
"\n" +
"public class SomeClass {\n" +
"\n" +
@@ -147,7 +147,7 @@ public class CompilationUnitCacheTest {
harness.useProject(ProjectsHarness.dummyProject());
harness.intialize(null);
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" +
TextDocument doc = new TextDocument(harness.createTempUri(null), LanguageId.JAVA, 0, "package my.package\n" +
"\n" +
"public class SomeClass {\n" +
"\n" +
@@ -171,7 +171,7 @@ public class CompilationUnitCacheTest {
harness.useProject(ProjectsHarness.dummyProject());
harness.intialize(null);
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" +
TextDocument doc = new TextDocument(harness.createTempUri(null), LanguageId.JAVA, 0, "package my.package\n" +
"\n" +
"public class SomeClass {\n" +
"\n" +

View File

@@ -3253,6 +3253,36 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest {
);
}
@Test public void testYamlExtensionAccepted() throws Exception {
data("server.port", "java.lang.Integer", null, "Port of server");
Editor editor;
// Hovers
editor = harness.newEditorWithExt(LanguageId.BOOT_PROPERTIES_YAML, ".yaml",
"server:\n" +
" port: blah"
);
editor.assertHoverContains("port", "Port of server");
//Reconcile
editor = harness.newEditorWithExt(LanguageId.BOOT_PROPERTIES_YAML, ".yaml",
"server:\n" +
" porter: blah"
);
editor.assertProblems("porter|Unknown");
//Completions
editor = harness.newEditorWithExt(LanguageId.BOOT_PROPERTIES_YAML, ".yaml",
"server:\n" +
" p<*>"
);
editor.assertCompletionLabels("server.port");
}
@Test public void testPropertyMapKeyCompletions() throws Exception {
useProject(createPredefinedMavenProject("empty-boot-1.3.0-app"));
assertCompletionWithLabel(