use of org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.SpecfileElementHyperlink in project linuxtools by eclipse.
the class SpecfileElementHyperlinkDetectorTest method testDetectHyperlinks.
@Test
public void testDetectHyperlinks() throws PartInitException {
String testText = "%define smth other\nSource0: test.zip\nPatch0: first.patch\n" + "%build\n %{SOURCE0}\n%patch0\n%{smth}\n";
newFile(testText);
SpecfileElementHyperlinkDetector elementDetector = new SpecfileElementHyperlinkDetector();
elementDetector.setSpecfile(specfile);
IEditorPart openEditor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), testFile, "org.eclipse.linuxtools.rpm.ui.editor.SpecfileEditor");
editor = (SpecfileEditor) openEditor;
editor.doRevertToSaved();
// test source element
IRegion region = new Region(74, 0);
IHyperlink[] returned = elementDetector.detectHyperlinks(editor.getSpecfileSourceViewer(), region, false);
SpecfileElementHyperlink element = (SpecfileElementHyperlink) returned[0];
assertTrue(element.getSource() instanceof SpecfileSource);
SpecfileSource source = (SpecfileSource) element.getSource();
assertEquals(source.getSourceType(), SpecfileSource.SourceType.SOURCE);
assertEquals(source.getFileName(), "test.zip");
// test patch element
region = new Region(83, 0);
returned = elementDetector.detectHyperlinks(editor.getSpecfileSourceViewer(), region, false);
element = (SpecfileElementHyperlink) returned[0];
assertTrue(element.getSource() instanceof SpecfileSource);
source = (SpecfileSource) element.getSource();
assertEquals(source.getSourceType(), SpecfileSource.SourceType.PATCH);
assertEquals(source.getFileName(), "first.patch");
// test define
region = new Region(89, 0);
returned = elementDetector.detectHyperlinks(editor.getSpecfileSourceViewer(), region, false);
element = (SpecfileElementHyperlink) returned[0];
assertTrue(element.getSource() instanceof SpecfileDefine);
SpecfileDefine define = (SpecfileDefine) element.getSource();
assertEquals(define.getName(), "smth");
assertEquals(define.getStringValue(), "other");
}
Aggregations