Search in sources :

Example 1 with SpecfileElementHyperlinkDetector

use of org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.SpecfileElementHyperlinkDetector in project linuxtools by eclipse.

the class SpecfileElementHyperlinkDetectorTest method testDetectHyperlinksNoRegionAndTextViewer.

@Test
public void testDetectHyperlinksNoRegionAndTextViewer() {
    SpecfileElementHyperlinkDetector elementDetector = new SpecfileElementHyperlinkDetector();
    elementDetector.setSpecfile(specfile);
    IHyperlink[] returned = elementDetector.detectHyperlinks(null, null, false);
    assertNull(returned);
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) SpecfileElementHyperlinkDetector(org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.SpecfileElementHyperlinkDetector) Test(org.junit.Test)

Example 2 with SpecfileElementHyperlinkDetector

use of org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.SpecfileElementHyperlinkDetector 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");
}
Also used : SpecfileElementHyperlink(org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.SpecfileElementHyperlink) SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) SpecfileDefine(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IEditorPart(org.eclipse.ui.IEditorPart) SpecfileElementHyperlinkDetector(org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.SpecfileElementHyperlinkDetector) IRegion(org.eclipse.jface.text.IRegion) Test(org.junit.Test)

Aggregations

IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)2 SpecfileElementHyperlinkDetector (org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.SpecfileElementHyperlinkDetector)2 Test (org.junit.Test)2 IRegion (org.eclipse.jface.text.IRegion)1 Region (org.eclipse.jface.text.Region)1 SpecfileElementHyperlink (org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.SpecfileElementHyperlink)1 SpecfileSource (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource)1 SpecfileDefine (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine)1 IEditorPart (org.eclipse.ui.IEditorPart)1