use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class TokenRegionProviderTest method testTokenMerge_1.
@Test
public void testTokenMerge_1() throws Exception {
String model = " ab ";
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 0));
assertEquals(1, tokenRegion.getOffset());
assertEquals(2, tokenRegion.getLength());
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class TokenRegionProviderTest method testTokenSplit.
@Test
public void testTokenSplit() throws Exception {
String model = " a b ";
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 1));
assertEquals(2, tokenRegion.getOffset());
assertEquals(1, tokenRegion.getLength());
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class TokenRegionProviderTest method testTokenRegionContainsRegion.
@Test
public void testTokenRegionContainsRegion() throws Exception {
String modelAsString = "a1 / /* comment */ b2";
List<CommonToken> tokens = getTokens(modelAsString);
for (int length = 0; length < modelAsString.length(); ++length) {
for (int offset = 0; offset + length < modelAsString.length(); ++offset) {
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(modelAsString, new TextRegion(offset, length));
// System.out.println(offset + ":" + length + " -> " + tokenRegion);
CommonToken firstToken = findTokenStartingAt(tokenRegion.getOffset(), tokens);
assertTrue(firstToken.getStartIndex() <= offset);
if (tokenRegion.getLength() != 0) {
CommonToken lastToken = findTokenStopingAt(tokenRegion.getOffset() + tokenRegion.getLength() - 1, tokens);
assertTrue(lastToken.getStopIndex() >= offset + length - 1);
}
}
}
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class TokenRegionProviderTest method testTokenSplit_1.
@Test
public void testTokenSplit_1() throws Exception {
String model = " axb ";
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 1));
assertEquals(1, tokenRegion.getOffset());
assertEquals(3, tokenRegion.getLength());
}
use of org.eclipse.xtext.util.ITextRegion in project xtext-core by eclipse.
the class TokenRegionProviderTest method testTokenMerge.
@Test
public void testTokenMerge() throws Exception {
String model = " ";
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(1, 0));
assertEquals(0, tokenRegion.getOffset());
assertEquals(2, tokenRegion.getLength());
}
Aggregations