Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 967e546f102f22dbc9b5fbea559d1388aad99729 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************
 * Copyright (c) 2006, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.text.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.eclipse.jface.text.GapTextStore;

/**
 * A test specifically testing the gap property of a gap text store.
 *
 * @since 3.3
 */
public class AbstractGapTextTest {
	protected static class GapText extends GapTextStore {

		/**
		 * Creates a new empty text store using the specified low and high watermarks.
		 *
		 * @param lowWatermark unused - at the lower bound, the array is only resized when the
		 *            content does not fit
		 * @param highWatermark if the gap is ever larger than this, it will automatically be
		 *            shrunken (>= 0)
		 * @deprecated use {@link GapTextStore#GapTextStore(int, int, float)} instead
		 */
		@Deprecated
		public GapText(int lowWatermark, int highWatermark) {
			super(lowWatermark, highWatermark);
		}

		public GapText(int min, int max, float maxGapFactor) {
			super(min, max, maxGapFactor);
		}

		String getText() {
			return super.getContentAsString();
		}

		int getGapStart() {
			return super.getGapStartIndex();
		}

		int getGapEnd() {
			return super.getGapEndIndex();
		}

		int getRawLength() {
			return super.getContentAsString().length();
		}
	}

	protected GapText fText;

	private String printGap() {
		return printGap(fText.getGapStart(), fText.getGapEnd());
	}

	private String printGap(int start, int end) {
		return "[" + start + "," + end + "]";
	}

	protected void assertGap(int start, int end) {
		assertTrue("Invalid gap. Expected: " + printGap(start, end) + " actual:" + printGap() , fText.getGapStart() == start && fText.getGapEnd() == end);
	}

	protected void assertContents(String expected) {
		assertEquals(expected, fText.get(0, fText.getLength()));
	}
}

Back to the top