Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a5593de633d16ddaf81d5aa3f75099c08704598c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*******************************************************************************
 * Copyright (c) 2006, 2008 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.text.tests;

import static org.junit.Assert.assertEquals;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.ILineTracker;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextStore;

/**
 *
 * @since 3.2
 */
public abstract class AbstractLineTrackerTest {
	protected ITextStore fText;
	protected ILineTracker  fTracker;

	protected final void checkLines(int[] lines) throws BadLocationException {
		assertEquals("number of lines", lines.length, fTracker.getNumberOfLines());

		for (int i= 0; i < lines.length; i++) {
			IRegion line= fTracker.getLineInformation(i);

			assertEquals("line lenght of line " + i, lines[i],  line.getLength());

			assertEquals("line offset of line " + i, getLineOffset(i, lines),  line.getOffset());
		}
	}

	abstract int getLineOffset(int line, int[] lines);

	protected final void replace(int offset, int length, String text) throws BadLocationException {
		fTracker.replace(offset, length, text);
		fText.replace(offset, length, text);
	}

	protected final void set(String string) {
		fText.set(string);
		fTracker.set(string);
	}

}

Back to the top