Search in sources :

Example 6 with SpecfileElement

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement in project linuxtools by eclipse.

the class HeaderRecognitionTest method testGetComplexSectionName4.

@Test
public void testGetComplexSectionName4() {
    // FIXME: check for rest of line when -p is implemented
    // this should be an error case
    String testText = "%post -n name -p";
    String[] tokens = testText.split("\\s+");
    SpecfileElement element;
    newFile(testText);
    element = parser.parseLine(testText, specfile, 0);
    assertEquals(SpecfileSection.class, element.getClass());
    SpecfileSection section = (SpecfileSection) element;
    assertEquals(tokens[0].substring(1), section.getName());
    assertEquals(tokens[2], section.getPackage().getPackageName());
}
Also used : SpecfileSection(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection) SpecfileElement(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement) Test(org.junit.Test)

Example 7 with SpecfileElement

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement in project linuxtools by eclipse.

the class HeaderRecognitionTest method testGetComplexSectionName6.

@Test
public void testGetComplexSectionName6() {
    String testText = "%post -p blah bleh";
    // FIXME: check for rest of line when -p is implemented
    // "blah bleh" should become the actual text of the section
    String[] tokens = testText.split("\\s+");
    SpecfileElement element;
    newFile(testText);
    element = parser.parseLine(testText, specfile, 0);
    assertEquals(SpecfileSection.class, element.getClass());
    SpecfileSection section = (SpecfileSection) element;
    assertEquals(tokens[0].substring(1), section.getName());
    assertNull(section.getPackage());
}
Also used : SpecfileSection(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection) SpecfileElement(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement) Test(org.junit.Test)

Example 8 with SpecfileElement

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement in project linuxtools by eclipse.

the class HeaderRecognitionTest method testGetSimpleSectionName.

@Test
public void testGetSimpleSectionName() {
    String testText = "%prep";
    SpecfileElement element;
    newFile(testText);
    element = parser.parseLine(testText, specfile, 0);
    assertEquals(SpecfileSection.class, element.getClass());
    assertEquals(testText.substring(1), ((SpecfileSection) element).getName());
}
Also used : SpecfileElement(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement) Test(org.junit.Test)

Example 9 with SpecfileElement

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement in project linuxtools by eclipse.

the class PatchApplicationTest method testParsePatchApplication.

@Test
public void testParsePatchApplication() {
    String specText = "Patch3: somefilesomewhere.patch\n%patch3";
    String testText = "%patch3";
    newFile(specText);
    SpecfileElement element = parser.parseLine(testText, specfile, 1);
    assertEquals(SpecfilePatchMacro.class, element.getClass());
    assertEquals(3, ((SpecfilePatchMacro) element).getPatchNumber());
}
Also used : SpecfileElement(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement) Test(org.junit.Test)

Example 10 with SpecfileElement

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement in project linuxtools by eclipse.

the class SpecfileFoldingStructureProvider method addFoldingRegions.

private Set<Position> addFoldingRegions(List<SpecfileElement> elements) {
    Set<Position> regions = new HashSet<>();
    // add folding on the preamble section
    Position position;
    if (elements.size() > 0) {
        SpecfileElement element = elements.get(0);
        position = new Position(0, element.getLineStartPosition() - 1);
        regions.add(position);
    }
    for (int i = 0; i < elements.size(); i++) {
        SpecfileElement startElement = elements.get(i);
        int offsetPos = startElement.getLineStartPosition();
        int lenghtPos;
        if (i < elements.size() - 1) {
            SpecfileElement endElement = elements.get(i + 1);
            lenghtPos = endElement.getLineStartPosition() - startElement.getLineStartPosition() - 1;
        } else {
            lenghtPos = sDocument.getLength() - startElement.getLineStartPosition();
        }
        position = new Position(offsetPos, lenghtPos);
        regions.add(position);
    }
    return regions;
}
Also used : Position(org.eclipse.jface.text.Position) SpecfileElement(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement) HashSet(java.util.HashSet)

Aggregations

SpecfileElement (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement)11 Test (org.junit.Test)7 SpecfileSection (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection)6 HashSet (java.util.HashSet)1 Position (org.eclipse.jface.text.Position)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SpecfilePreamble (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfilePreamble)1 Specfile (org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile)1 SpecfilePackage (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage)1 SpecfilePackageContainer (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackageContainer)1