Porting all the tests from YamlEditorTests in old STS
Moved into ApplicationPropertiesTests suite. All tests running but most are not yet passing. Tests that are expected to fail w.r.t. already implemented functionlaity are marked with @Ignore annotations.
This commit is contained in:
@@ -218,7 +218,7 @@ public class Editor {
|
||||
assertEquals(expect.toString(), actual.toString());
|
||||
}
|
||||
|
||||
private void apply(CompletionItem completion) throws Exception {
|
||||
public void apply(CompletionItem completion) throws Exception {
|
||||
TextEdit edit = completion.getTextEdit();
|
||||
String docText = document.getText();
|
||||
if (edit!=null) {
|
||||
@@ -269,7 +269,7 @@ public class Editor {
|
||||
}
|
||||
}
|
||||
|
||||
private List<? extends CompletionItem> getCompletions() throws Exception {
|
||||
public List<CompletionItem> getCompletions() throws Exception {
|
||||
CompletionList cl = harness.getCompletions(this.document, this.getCursor());
|
||||
ArrayList<CompletionItem> items = new ArrayList<>(cl.getItems());
|
||||
Collections.sort(items, new Comparator<CompletionItem>() {
|
||||
@@ -290,6 +290,10 @@ public class Editor {
|
||||
return items;
|
||||
}
|
||||
|
||||
public CompletionItem getFirstCompletion() throws Exception {
|
||||
return getCompletions().get(0);
|
||||
}
|
||||
|
||||
private Position getCursor() {
|
||||
return document.toPosition(selectionStart);
|
||||
}
|
||||
@@ -302,6 +306,10 @@ public class Editor {
|
||||
throw new UnsupportedOperationException("Not implemented yet!");
|
||||
}
|
||||
|
||||
public void assertNoHover(String string) {
|
||||
throw new UnsupportedOperationException("Not implemented yet!");
|
||||
}
|
||||
|
||||
public void setSelection(int start, int end) {
|
||||
Assert.assertTrue(start>=0);
|
||||
Assert.assertTrue(end>=start);
|
||||
@@ -315,4 +323,44 @@ public class Editor {
|
||||
return "Editor(\n"+getText()+"\n)";
|
||||
}
|
||||
|
||||
public void assertLinkTargets(String hoverOver, String... expecteds) {
|
||||
throw new UnsupportedOperationException("Not implemented yet!");
|
||||
// Editor editor = this;
|
||||
// int pos = editor.middleOf(hoverOver);
|
||||
// assertTrue("Not found in editor: '"+hoverOver+"'", pos>=0);
|
||||
//
|
||||
// List<IJavaElement> targets = getLinkTargets(editor, pos);
|
||||
// assertEquals(expecteds.length, targets.size());
|
||||
// for (int i = 0; i < expecteds.length; i++) {
|
||||
// assertEquals(expecteds[i], JavaElementLabels.getElementLabel(targets.get(i), JavaElementLabels.DEFAULT_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES));
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a problem that covers the given text in the editor. Throws exception
|
||||
* if no matching problem is found.
|
||||
*/
|
||||
public Diagnostic assertProblem(String coveredText) throws Exception {
|
||||
Editor editor = this;
|
||||
List<Diagnostic> problems = editor.reconcile();
|
||||
for (Diagnostic p : problems) {
|
||||
String c = editor.getText(p.getRange());
|
||||
if (c.equals(coveredText)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
fail("No problem found covering the text '"+coveredText+"' in: \n"
|
||||
+ problemSumary(editor, problems)
|
||||
);
|
||||
return null; //unreachable but compiler doesn't know
|
||||
}
|
||||
|
||||
public CompletionItem assertFirstQuickfix(Diagnostic problem, String expectLabel) {
|
||||
throw new UnsupportedOperationException("Not implemented yet!");
|
||||
}
|
||||
|
||||
public void assertText(String expected) {
|
||||
assertEquals(expected, getText());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.springframework.ide.vscode.testharness;
|
||||
|
||||
/**
|
||||
* Replaces eclipse JDT IType. Maybe we keep this maybe not, if keep, it should move to some
|
||||
* other place, not stay here in the testharness.
|
||||
*/
|
||||
public interface IType {
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.springframework.ide.vscode.testharness;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
@@ -252,4 +254,30 @@ public class LanguageServerHarness {
|
||||
return File.createTempFile("workingcopy", getFileExtension()).toURI().toString();
|
||||
}
|
||||
|
||||
public void assertCompletion(String textBefore, String expectTextAfter) throws Exception {
|
||||
Editor editor = newEditor(textBefore);
|
||||
CompletionItem completion = editor.getFirstCompletion();
|
||||
editor.apply(completion);
|
||||
assertEquals(expectTextAfter, editor.getText());
|
||||
}
|
||||
|
||||
public void assertCompletions(String textBefore, String... expectTextAfter) throws Exception {
|
||||
Editor editor = newEditor(textBefore);
|
||||
StringBuilder expect = new StringBuilder();
|
||||
StringBuilder actual = new StringBuilder();
|
||||
for (String after : expectTextAfter) {
|
||||
expect.append(after);
|
||||
expect.append("\n-------------------\n");
|
||||
}
|
||||
|
||||
List<? extends CompletionItem> completions = editor.getCompletions();
|
||||
for (CompletionItem ci : completions) {
|
||||
editor = newEditor(textBefore);
|
||||
editor.apply(ci);
|
||||
actual.append(editor.getText());
|
||||
actual.append("\n-------------------\n");
|
||||
}
|
||||
assertEquals(expect.toString(), actual.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.springframework.ide.vscode.testharness;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface TestProject {
|
||||
|
||||
Path getPath();
|
||||
|
||||
IType findType(String string);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user