mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 18:35:32 +02:00
Make inactive code test independent from line delimiters
This commit is contained in:
parent
6b2a7a5842
commit
9e23abbfb2
1 changed files with 14 additions and 13 deletions
|
@ -82,9 +82,11 @@ public class InactiveCodeHighlightingTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Position createPosition(int line, int column, int length) throws BadLocationException {
|
protected Position createPosition(int startLine, int endLine) throws BadLocationException {
|
||||||
IDocument document= fSourceViewer.getDocument();
|
IDocument document= fSourceViewer.getDocument();
|
||||||
return new Position(document.getLineOffset(line) + column, length);
|
int startOffset= document.getLineOffset(startLine);
|
||||||
|
int endOffset= document.getLineOffset(endLine) + document.getLineLength(endLine) - document.getLineDelimiter(endLine).length();
|
||||||
|
return new Position(startOffset, endOffset - startOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
String toString(Position[] positions) throws BadLocationException {
|
String toString(Position[] positions) throws BadLocationException {
|
||||||
|
@ -93,9 +95,9 @@ public class InactiveCodeHighlightingTest extends TestCase {
|
||||||
buf.append("Position[] expected= new Position[] {\n");
|
buf.append("Position[] expected= new Position[] {\n");
|
||||||
for (int i= 0, n= positions.length; i < n; i++) {
|
for (int i= 0, n= positions.length; i < n; i++) {
|
||||||
Position position= positions[i];
|
Position position= positions[i];
|
||||||
int line= document.getLineOfOffset(position.getOffset());
|
int startLine= document.getLineOfOffset(position.getOffset());
|
||||||
int column= position.getOffset() - document.getLineOffset(line);
|
int endLine= document.getLineOfOffset(position.getOffset()+position.getLength()-1);
|
||||||
buf.append("\tcreatePosition(" + line + ", " + column + ", " + position.getLength() + "),\n");
|
buf.append("\tcreatePosition(" + startLine + ", " + endLine + "),\n");
|
||||||
}
|
}
|
||||||
buf.append("};\n");
|
buf.append("};\n");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
|
@ -108,17 +110,16 @@ public class InactiveCodeHighlightingTest extends TestCase {
|
||||||
return (Position[]) positions.toArray(new Position[positions.size()]);
|
return (Position[]) positions.toArray(new Position[positions.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testInactiveCodePositions() throws BadLocationException {
|
public void testInactiveCodePositions() throws BadLocationException {
|
||||||
Position[] actual= getInactiveCodePositions();
|
Position[] actual= getInactiveCodePositions();
|
||||||
Position[] expected= new Position[] {
|
Position[] expected= new Position[] {
|
||||||
createPosition(2, 0, 37),
|
createPosition(2, 4),
|
||||||
createPosition(11, 0, 37),
|
createPosition(11, 13),
|
||||||
createPosition(15, 0, 164),
|
createPosition(15, 22),
|
||||||
createPosition(28, 0, 107),
|
createPosition(28, 34),
|
||||||
createPosition(39, 0, 50),
|
createPosition(39, 41),
|
||||||
createPosition(47, 0, 209),
|
createPosition(47, 58),
|
||||||
createPosition(67, 0, 26),
|
createPosition(67, 69),
|
||||||
};
|
};
|
||||||
if (false) System.out.println(toString(actual));
|
if (false) System.out.println(toString(actual));
|
||||||
assertEqualPositions(expected, actual);
|
assertEqualPositions(expected, actual);
|
||||||
|
|
Loading…
Add table
Reference in a new issue