use of org.eclipse.xtext.ui.editor.selection.AstSelectionProvider in project xtext-eclipse by eclipse.
the class AstSelectionProviderTest method testSelectLast.
@Test
public void testSelectLast() throws Exception {
String zonk = "/* my coment \n*/\nzonk{}";
String zink = "zink{}";
String baz = "baz{\n" + zonk + zink + "}";
String bar = "bar{}";
String all = "foo(baz){" + bar + baz + "}";
EObject model = super.getModel(all);
AstSelectionProvider provider = get(AstSelectionProvider.class);
final XtextResource res = (XtextResource) model.eResource();
int indexOfZonk = all.indexOf("zonk");
Stack<ITextRegion> selections = new Stack<ITextRegion>();
final TextRegion currentEditorSelection = new TextRegion(indexOfZonk, 1);
ITextRegion selection = provider.selectPrevious(res, currentEditorSelection);
selections.push(selection);
assertEquals(region(all, "zonk"), selection);
selection = provider.selectEnclosing(res, selection);
selections.push(selection);
assertEquals(region(all, zonk), selection);
selection = provider.selectPrevious(res, selection);
selections.push(selection);
assertEquals(region(all, baz), selection);
selection = provider.selectPrevious(res, selection);
selections.push(selection);
assertEquals(region(all, bar + baz), selection);
selection = provider.selectPrevious(res, selection);
assertEquals(region(all, all), selection);
assertEquals(ITextRegion.EMPTY_REGION, provider.selectPrevious(res, selection));
while (!selections.isEmpty()) {
ITextRegion previous = selections.pop();
assertEquals(previous, provider.selectLast(res, selection));
selection = previous;
}
assertEquals(ITextRegion.EMPTY_REGION, provider.selectLast(res, currentEditorSelection));
}
use of org.eclipse.xtext.ui.editor.selection.AstSelectionProvider in project xtext-eclipse by eclipse.
the class AstSelectionProviderTest method testSelectNext.
@Test
public void testSelectNext() throws Exception {
String zonk = "zonk{}";
String zink = "zink{}";
String baz = "baz{" + zonk + zink + "}";
String bar = "bar{}";
String all = "foo(baz){" + bar + baz + "}";
EObject model = super.getModel(all);
AstSelectionProvider provider = get(AstSelectionProvider.class);
final XtextResource res = (XtextResource) model.eResource();
int indexOfZonk = all.indexOf(zonk);
ITextRegion selection = provider.selectNext(res, new TextRegion(indexOfZonk, 0));
assertEquals(region(all, "zonk"), selection);
selection = provider.selectEnclosing(res, selection);
assertEquals(region(all, zonk), selection);
selection = provider.selectNext(res, selection);
assertEquals(region(all, zonk + zink), selection);
selection = provider.selectNext(res, selection);
assertEquals(region(all, baz), selection);
selection = provider.selectNext(res, selection);
assertEquals(region(all, all), selection);
assertEquals(ITextRegion.EMPTY_REGION, provider.selectNext(res, selection));
}
Aggregations