下面列出了怎么用org.eclipse.ui.tests.harness.util.DisplayHelper的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testXMLFile() throws Exception {
final IFile file = project.getFile("blah.xml");
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<plugin></");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testXSLFile() throws Exception {
final IFile file = project.getFile("blah.xsl");
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testXSDFile() throws Exception {
final IFile file = project.getFile("blah.xsd");
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("a<");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testDTDFile() throws Exception {
final IFile file = project.getFile("blah.dtd");
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<!--<!-- -->");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testComplexXML() throws Exception {
final IFile file = project.getFile("blah.xml");
String content = "<layout:BlockLayoutCell\n" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" +
" xsi:schemaLocation=\"sap.ui.layout https://openui5.hana.ondemand.com/downloads/schemas/sap.ui.layout.xsd\"\n" +
" xmlns:layout=\"sap.ui.layout\">\n" +
" |\n" +
"</layout:BlockLayoutCell>";
int offset = content.indexOf('|');
content = content.replace("|", "");
file.create(new ByteArrayInputStream(content.getBytes()), true, null);
AbstractTextEditor editor = (AbstractTextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file, "org.eclipse.ui.genericeditor.GenericEditor");
editor.getSelectionProvider().setSelection(new TextSelection(offset, 0));
LSContentAssistProcessor processor = new LSContentAssistProcessor();
proposals = processor.computeCompletionProposals(Utils.getViewer(editor), offset);
DisplayHelper.sleep(editor.getSite().getShell().getDisplay(), 2000);
assertTrue(proposals.length > 1);
}
@Test
public void testCSSFile() throws Exception {
final IFile file = project.getFile("blah.css");
file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testHTMLFile() throws Exception {
final IFile file = project.getFile("blah.html");
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<style\n<html><");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testYAMLFile() throws Exception {
final IFile file = project.getFile("blah.yaml");
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("hello: '");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testJSONFile() throws Exception {
final IFile file = project.getFile("blah.json");
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("ERROR");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testJSFile() throws Exception {
final IFile file = project.getFile("blah.js");
file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
DisplayHelper.sleep(2000); // Give time for LS to initialize enough before making edit and sending a didChange
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("a<");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testTSFile() throws Exception {
final IFile file = project.getFile("blah.ts");
file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testJSXFile() throws Exception {
final IFile file = project.getFile("blah.jsx");
file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("a<");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testTSXFile() throws Exception {
final IFile file = project.getFile("blah.tsx");
file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testHTMLFile() throws Exception {
final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("testHTMLFile" + System.currentTimeMillis());
project.create(null);
project.open(null);
final IFile file = project.getFile("blah.html");
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<style\n<html><");
assertTrue("Diagnostic not published", new DisplayHelper() {
@Override
protected boolean condition() {
try {
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000));
}
@Test
public void testFalseDetectionAsKubernetes() throws Exception {
IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject("p");
p.create(new NullProgressMonitor());
p.open(new NullProgressMonitor());
IFile file = p.getFile("blah.yaml");
file.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ITextEditor editor = (ITextEditor)IDE.openEditor(activePage, file, true);
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
document.set("name: a\ndescrition: b");
boolean markerFound = new DisplayHelper() {
@Override protected boolean condition() {
try {
return file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO).length > 0;
} catch (CoreException e) {
return false;
}
}
}.waitForCondition(activePage.getWorkbenchWindow().getShell().getDisplay(), 3000);
assertFalse(Arrays.stream(file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO)).map(Object::toString).collect(Collectors.joining("\n")), markerFound);
}
private void workaroundOmniSharpIssue1088(IDocument document) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Wait for document to be connected
Method getDocumentListenersMethod = AbstractDocument.class.getDeclaredMethod("getDocumentListeners");
getDocumentListenersMethod.setAccessible(true);
new DisplayHelper() {
@Override protected boolean condition() {
try {
return ((Collection<?>)getDocumentListenersMethod.invoke(document)).stream().anyMatch(o -> o.getClass().getName().contains("lsp4e"));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
return false;
}
}
}.waitForCondition(Display.getDefault(), 5000);
assertNotEquals("LS Document listener was not setup after 5s", Collections.emptyList(), getDocumentListenersMethod.invoke(document));
// workaround https://github.com/OmniSharp/omnisharp-roslyn/issues/1445
DisplayHelper.sleep(5000);
// force fake modification for OmniSharp to wake up
document.set(document.get().replace("Hello", "Kikoo"));
DisplayHelper.sleep(500);
}
@Test
public void testLSFindsDiagnosticsCSProj() throws Exception {
IProject project = getProject("csprojWithError");
IFile csharpSourceFile = project.getFile("Program.cs");
IEditorPart editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), csharpSourceFile);
SourceViewer viewer = (SourceViewer)getTextViewer(editor);
workaroundOmniSharpIssue1088(viewer.getDocument());
new DisplayHelper() {
@Override
protected boolean condition() {
try {
return csharpSourceFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO).length > 0;
} catch (Exception e) {
return false;
}
}
}.waitForCondition(Display.getDefault(), 5000);
DisplayHelper.sleep(500); // time to fill marker details
IMarker marker = csharpSourceFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO)[0];
assertTrue(marker.getType().contains("lsp4e"));
assertEquals(12, marker.getAttribute(IMarker.LINE_NUMBER, -1));
}
@Test
public void testBasicRun() throws IOException, CoreException, InterruptedException {
CargoRunDelegate delegate = new CargoRunDelegate();
IProject project = getProject(BASIC_PROJECT_NAME);
delegate.launch(new StructuredSelection(project), "run");
new DisplayHelper() {
@Override
protected boolean condition() {
return DebugPlugin.getDefault().getLaunchManager().getProcesses().length != 0 || getErrorPopup() != null;
}
}.waitForCondition(Display.getCurrent(), 15000);
assertNull(getErrorPopup());
assertTrue(DebugPlugin.getDefault().getLaunchManager().getProcesses().length != 0);
for (IProcess process : DebugPlugin.getDefault().getLaunchManager().getProcesses()) {
if (process.getLabel().equals("cargo run")) {
while (!process.isTerminated()) {
Thread.sleep(50);
}
assertEquals(0, process.getExitValue());
return;
}
}
}
@Test
public void testCreateNewProject() {
Collection<IProject> initialProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
NewCargoProjectWizard wizard = new NewCargoProjectWizard();
WizardDialog dialog = new WizardDialog(getShell(), wizard);
wizard.init(getWorkbench(), new StructuredSelection());
dialog.create();
assertTrue(wizard.canFinish());
assertTrue(wizard.performFinish());
dialog.close();
new DisplayHelper() {
@Override
protected boolean condition() {
return ResourcesPlugin.getWorkspace().getRoot().getProjects().length > 0;
}
}.waitForCondition(getShell().getDisplay(), 15000);
Set<IProject> newProjects = new HashSet<>(Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects()));
newProjects.removeAll(initialProjects);
assertEquals(1, newProjects.size());
assertTrue(newProjects.iterator().next().getFile("Cargo.toml").exists());
}
@Test
public void testDebugLaunch() throws Exception {
IProject project = getProject(BASIC_PROJECT_NAME);
IFile file = project.getFile("src/main.rs");
assertTrue(file.exists());
RustDebugDelegate delegate = new RustDebugDelegate();
delegate.launch(new StructuredSelection(project), "debug");
assertEquals(Collections.emptyList(), errors);
Assume.assumeTrue("rust-gdb not found, skipping test continuation", Runtime.getRuntime().exec("rust-gdb --version").waitFor() == 0);
new DisplayHelper() {
@Override
protected boolean condition() {
IConsole console = getApplicationConsole("basic");
return (console != null && console.getDocument().get().contains("5 is positive")) || getErrorPopupMessage() != null;
}
}.waitForCondition(Display.getCurrent(), 15000);
assertNull(getErrorPopupMessage());
assertTrue(getApplicationConsole("basic").getDocument().get().contains("5 is positive"));
}
@Test
public void testExportProject() throws IOException, CoreException {
IProject basic = getProject(BASIC_PROJECT_NAME);
createWizard(BASIC_PROJECT_NAME);
Composite composite = (Composite) wizard.getPages()[0].getControl();
Button allowDirty = (Button) composite.getChildren()[10];
allowDirty.setSelection(true); // required of another test updates the project
new DisplayHelper() {
@Override
protected boolean condition() {
return allowDirty.getSelection();
}
}.waitForCondition(getShell().getDisplay(), 3000);
assertTrue(wizard.canFinish());
assertTrue(wizard.performFinish());
new DisplayHelper() {
@Override
protected boolean condition() {
return basic.getFolder("target").getFolder("package").exists();
}
}.waitForCondition(getShell().getDisplay(), 15000);
assertTrue(basic.getFolder("target").getFolder("package").members().length > 0);
}
@Test
public void testTMHighlightInGenericEditor() throws IOException, PartInitException {
f = File.createTempFile("test" + System.currentTimeMillis(), ".ts");
FileOutputStream fileOutputStream = new FileOutputStream(f);
fileOutputStream.write("let a = '';\nlet b = 10;\nlet c = true;".getBytes());
fileOutputStream.close();
f.deleteOnExit();
editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
f.toURI(), editorDescriptor.getId(), true);
StyledText text = (StyledText)editor.getAdapter(Control.class);
Assert.assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return text.getStyleRanges().length > 1;
}
}.waitForCondition(text.getDisplay(), 3000));
}
@Test
public void testTMHighlightInGenericEditorEdit() throws IOException, PartInitException {
f = File.createTempFile("test" + System.currentTimeMillis(), ".ts");
FileOutputStream fileOutputStream = new FileOutputStream(f);
fileOutputStream.write("let a = '';".getBytes());
fileOutputStream.close();
f.deleteOnExit();
editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
f.toURI(), editorDescriptor.getId(), true);
StyledText text = (StyledText)editor.getAdapter(Control.class);
Assert.assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return text.getStyleRanges().length > 1;
}
}.waitForCondition(text.getDisplay(), 3000));
int initialNumberOfRanges = text.getStyleRanges().length;
text.setText("let a = '';\nlet b = 10;\nlet c = true;");
Assert.assertTrue("More styles should have been added", new DisplayHelper() {
@Override protected boolean condition() {
return text.getStyleRanges().length > initialNumberOfRanges + 3;
}
}.waitForCondition(text.getDisplay(), 300000));
}
@Test
public void testJSXHighlighting() throws CoreException {
IFile file = project.getFile("test.jsx");
file.create(new ByteArrayInputStream("var n = 4;\n".getBytes()), true, null);
ITextEditor editor = (ITextEditor)IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
StyledText widget = (StyledText) editor.getAdapter(Control.class);
Color defaultTextColor = widget.getForeground();
assertTrue("Missing syntax highlighting", new DisplayHelper() {
@Override protected boolean condition() {
return Arrays.stream(widget.getStyleRanges()).anyMatch(range -> range.foreground != null && !defaultTextColor.equals(range.foreground));
}
}.waitForCondition(widget.getDisplay(), 2000));
}
@Test
public void testHTMLinTSXFile() throws Exception {
IFile file = project.getFile("test.tsx");
file.create(getClass().getResourceAsStream("/testProjects/htmlIn.tsx"), true, null);
AbstractTextEditor editor = (AbstractTextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
IDocument document = LSPEclipseUtils.getDocument(editor);
DisplayHelper.sleep(2000); // Give time for LS to initialize enough before making edit and sending a didChange
HoverParams params = new HoverParams(new TextDocumentIdentifier(LSPEclipseUtils.toUri(document).toString()), new Position(0, 18));
Hover hover = LanguageServiceAccessor.getLanguageServers(document, null).get().get(0).getTextDocumentService().hover(params).get();
Assert.assertTrue(hover.getContents().toString().contains("button"));
}
@Test
public void testFormat() throws Exception {
final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("testHTMLFile" + System.currentTimeMillis());
project.create(null);
project.open(null);
final IFile file = project.getFile("blah.html");
file.create(new ByteArrayInputStream("<html><body><a></a></body></html>".getBytes()), true, null);
ITextEditor editor = (ITextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
editor.setFocus();
editor.getSelectionProvider().setSelection(new TextSelection(0, 0));
IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
AtomicReference<Exception> ex = new AtomicReference<>();
new DisplayHelper() {
@Override protected boolean condition() {
try {
handlerService.executeCommand("org.eclipse.lsp4e.format", null);
return true;
} catch (Exception e) {
return false;
}
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 3000);
if (ex.get() != null) {
throw ex.get();
}
new DisplayHelper() {
@Override protected boolean condition() {
return editor.getDocumentProvider().getDocument(editor.getEditorInput()).getNumberOfLines() > 1;
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 3000);
}
@Test
public void testSyntaxHighlighting() throws Exception {
IFile csharpSourceFile = getProject("csproj").getFile("Program.cs");
TextEditor editor = (TextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), csharpSourceFile, "org.eclipse.ui.genericeditor.GenericEditor");
StyledText editorTextWidget = (StyledText)editor.getAdapter(Control.class);
new DisplayHelper() {
@Override
protected boolean condition() {
return editorTextWidget.getStyleRanges().length > 1;
}
}.waitForCondition(editorTextWidget.getDisplay(), 4000);
Assert.assertTrue("There should be multiple styles in editor", editorTextWidget.getStyleRanges().length > 1);
}
@Test
public void testRustSyntaxHighlighting() throws CoreException, IOException {
IFile rustFile = getProject(BASIC_PROJECT_NAME).getFolder("src").getFile("main.rs");
TextEditor editor = (TextEditor) IDE.openEditor(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), rustFile,
"org.eclipse.ui.genericeditor.GenericEditor");
StyledText editorTextWidget = (StyledText) editor.getAdapter(Control.class);
new DisplayHelper() {
@Override
protected boolean condition() {
return editorTextWidget.getStyleRanges().length > 1;
}
}.waitForCondition(editorTextWidget.getDisplay(), 4000);
Assert.assertTrue("There should be multiple styles in editor", editorTextWidget.getStyleRanges().length > 1);
}
@Test
public void testManifestSyntaxHighlighting() throws CoreException, IOException {
IFile rustFile = getProject(BASIC_PROJECT_NAME).getFile("Cargo.toml");
TextEditor editor = (TextEditor) IDE.openEditor(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), rustFile,
"org.eclipse.ui.genericeditor.GenericEditor");
StyledText editorTextWidget = (StyledText) editor.getAdapter(Control.class);
new DisplayHelper() {
@Override
protected boolean condition() {
return editorTextWidget.getStyleRanges().length > 1;
}
}.waitForCondition(editorTextWidget.getDisplay(), 4000);
Assert.assertTrue("There should be multiple styles in editor", editorTextWidget.getStyleRanges().length > 1);
}
@Test
public void testTranslateVariablesInBuildCommand() throws InterruptedException, IOException, CoreException {
IProject project = getProject(BASIC_PROJECT_NAME);
ILaunchConfigurationWorkingCopy launchConfiguration = createLaunchConfiguration(project);
launchConfiguration.setAttribute("BUILD_COMMAND", "-- ${workspace_loc}");
ILaunch launch = launchConfiguration.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());
new DisplayHelper() {
@Override
protected boolean condition() {
return launch.getProcesses().length != 0;
}
}.waitForCondition(Display.getDefault(), 15000);
for (IProcess process : launch.getProcesses()) {
if (process.getLabel().equals("cargo run")) {
while (!process.isTerminated()) {
Thread.sleep(50);
}
String command = process.getAttribute(IProcess.ATTR_CMDLINE);
// confirm ${workspace_loc} has been replaced with its actual value
assertTrue(command
.matches(".*" + ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() + ".*"));
assertEquals(0, process.getExitValue());
return;
}
}
fail();
}