KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > core > TextPositionsMapperTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.core;
21
22 import junit.framework.Test;
23 import org.netbeans.modules.tasklist.core.util.*;
24 import org.netbeans.junit.NbTestCase;
25 import org.netbeans.junit.NbTestSuite;
26
27 /**
28  * Tests for org.netbeans.modules.tasklist.core.util.TextPositionsMapper
29  */

30 public class TextPositionsMapperTest extends NbTestCase {
31     public TextPositionsMapperTest(String JavaDoc name) {
32         super(name);
33     }
34
35     public static void main (String JavaDoc args []) {
36         junit.textui.TestRunner.run(TextPositionsMapperTest.class);
37     }
38
39     public static Test suite () {
40         return new NbTestSuite(TextPositionsMapperTest.class);
41     }
42
43     /**
44      * Tests the class
45      */

46     public void testPositions() {
47         TextPositionsMapper m = new TextPositionsMapper(
48             "\n" +
49             "This is the first line\n" +
50             "This is the second line\r\n" +
51             "This is the third line\n" +
52             "\r" +
53             "The fifth line");
54         int[] pos = new int[2];
55
56         m.findPosition(0, pos);
57         assertEquals(0, pos[0]);
58         assertEquals(0, pos[1]);
59
60         m.findPosition(1, pos);
61         assertEquals(1, pos[0]);
62         assertEquals(0, pos[1]);
63
64         m.findPosition(20, pos);
65         assertEquals(1, pos[0]);
66         assertEquals(19, pos[1]);
67
68         m.findPosition(24, pos);
69         assertEquals(2, pos[0]);
70         assertEquals(0, pos[1]);
71
72         m.findPosition(49, pos);
73         assertEquals(3, pos[0]);
74         assertEquals(0, pos[1]);
75
76         m.findPosition(73, pos);
77         assertEquals(5, pos[0]);
78         assertEquals(0, pos[1]);
79     }
80 }
81
Popular Tags