Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: efdad4029b4542858b645197215c6bf3ef6f4320 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.text.tests;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;



public class PositionUpdatingCornerCasesTest extends TestCase {
	
	private Document fDocument;
	
	
	public PositionUpdatingCornerCasesTest(String name) {
		super(name);
	}
	
	
	protected void checkPositions(Position[] expected) {
	
		try {
			
			Position[] actual= fDocument.getPositions(IDocument.DEFAULT_CATEGORY);
			assertTrue("invalid number of positions", actual.length == expected.length);
	
			for (int i= 0; i < expected.length; i++) {
				assertEquals(print(actual[i]) + " != " + print(expected[i]), expected[i], actual[i]);
			}
			
		} catch (BadPositionCategoryException x) {
			assertTrue("BadPositionCategoryException thrown", false);
		}
		
	}
	
	protected String print(Position p) {
		return "[" + p.getOffset() + "," + p.getLength() + "]";
	}
	
	protected void setUp() {
		
		fDocument= new Document("x-x-x-x-x-x-x-x-x-x-x");
	
		try {
			fDocument.addPosition(new Position( 0, 0));
			fDocument.addPosition(new Position( 0, 1));
			fDocument.addPosition(new Position( 5, 0));
			fDocument.addPosition(new Position( 5, 3));
		} catch (BadLocationException x) {
			assertTrue("initilization failed", false);
		}
	}
	
	public static Test suite() {
		return new TestSuite(PositionUpdatingCornerCasesTest.class); 
	}
	
	protected void tearDown () {
		fDocument= null;
	}
	
	public void testInsert() {
	
		try {
	
			fDocument.replace(0, 0, "yy");
		
		} catch (BadLocationException x) {
			assertTrue("BadLocationException thrown", false);
		}
		
		Position[] positions= new Position[] {
			new Position( 2, 1),
			new Position( 2, 0),
			new Position( 7, 3),
			new Position( 7, 0)
		};
	
		checkPositions(positions);
	}	
}

Back to the top