Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 11668 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/workbench/texteditor/tests/WorkbenchTextEditorTestSuite.java (+1 lines)
Lines 27-32 Link Here
27
		//$JUnit-BEGIN$
27
		//$JUnit-BEGIN$
28
		suite.addTest(DiffTestSuite.suite());
28
		suite.addTest(DiffTestSuite.suite());
29
		suite.addTest(FindReplaceDialogTest.suite());
29
		suite.addTest(FindReplaceDialogTest.suite());
30
        suite.addTest(HippieCompletionTest.suite());
30
		//$JUnit-END$
31
		//$JUnit-END$
31
		return suite;
32
		return suite;
32
	}
33
	}
(-).settings/org.eclipse.core.resources.prefs (+3 lines)
Added Link Here
1
#Fri Jan 14 17:26:55 IST 2005
2
eclipse.preferences.version=1
3
encoding//src/org/eclipse/ui/workbench/texteditor/tests/HippieCompletionTest.java=Cp1255
(-)src/org/eclipse/ui/workbench/texteditor/tests/HippieCompletionTest.java (+178 lines)
Added Link Here
1
package org.eclipse.ui.workbench.texteditor.tests;
2
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.List;
6
7
import junit.framework.Test;
8
import junit.framework.TestCase;
9
import junit.framework.TestSuite;
10
11
import org.eclipse.jface.text.BadLocationException;
12
import org.eclipse.jface.text.Document;
13
import org.eclipse.jface.text.IDocument;
14
import org.eclipse.ui.texteditor.HippieCompleteAction;
15
16
/**
17
 * Tests for the Hippie completion action of the text editor
18
 * 
19
 * @author Genady Beryozkin, me@genady.org
20
 */
21
public class HippieCompletionTest extends TestCase {
22
23
    IDocument[] documents;
24
25
    public HippieCompletionTest(String name) {
26
        super(name);
27
    }
28
29
    /* (non-Javadoc)
30
     * @see junit.framework.TestCase#setUp()
31
     */
32
    protected void setUp() throws Exception {
33
        documents = new IDocument[4];
34
        documents[0] = new Document("package ui.TestPackage;\n" + 
35
                "\n" + 
36
                "/**\n" + 
37
                " * This is a testing class that tests the hippie completion engine.\n" +
38
                " * it has a simple main with a print method\n" + 
39
                " */\n" + 
40
                "public class TestClass1 {\n" + 
41
                "\n" + 
42
                "    public static void main(String[] args) {\n" + 
43
                "        System.out.println(\"I will be printing Hello world!\");\n" + 
44
                "    }\n" + 
45
                "}");
46
        documents[1] = new Document("This is a simple text file\n" + 
47
                "that is also used in the completion engine tests");
48
        
49
        documents[2] = new Document("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 
50
                "<plugin\n" + 
51
                "   id=\"org.eclipse.ui.workbench.texteditor.tests\"\n" + 
52
                "   name=\"%Plugin.name\"\n" + 
53
                "   version=\"3.1.0\"\n" + 
54
                "   provider-name=\"%Plugin.providerName\">\n" + 
55
                "\n" + 
56
                "   <runtime>\n" + 
57
                "      <library name=\"workbenchtexteditortests.jar\">\n" + 
58
                "         <export name=\"*\"/>\n" + 
59
                "      </library>\n" + 
60
                "   </runtime>\n" + 
61
                "   \n" + 
62
                "   <requires>\n" + 
63
                "      <import plugin=\"org.eclipse.core.runtime.compatibility\"/>\n" + 
64
                "      <import plugin=\"org.junit\"/>\n" + 
65
                "      <import plugin=\"org.eclipse.text.tests\"/>\n" + 
66
                "      <import plugin=\"org.eclipse.jface.text\"/>\n" + 
67
                "      <import plugin=\"org.eclipse.ui.workbench.texteditor\"/>\n" + 
68
                "      <import plugin=\"org.eclipse.ui\"/>\n" + 
69
                "   </requires>\n" + 
70
                "   \n" + 
71
                "</plugin>\n" + 
72
                "");
73
        
74
        documents[3] = new Document("###############################################################################\n" + 
75
                "# Copyright (c) 2000, 2004 IBM Corporation and others.\n" + 
76
                "# All rights reserved. This program and the accompanying materials \n" + 
77
                "# are made available under the terms of the Common Public License v1.0\n" + 
78
                "# which accompanies this distribution, and is available at\n" + 
79
                "# http://www.eclipse.org/legal/cpl-v10.html\n" + 
80
                "# \n" + 
81
                "# Contributors:\n" + 
82
                "#     IBM Corporation - initial API and implementation\n" + 
83
                "###############################################################################\n" + 
84
                "bin.includes = plugin.xml,\\\n" + 
85
                "               plugin.properties,\\\n" + 
86
                "               test.xml,\\\n" + 
87
                "               about.html,\\\n" + 
88
                "               *.jar\n" + 
89
                "\n" + 
90
                "src.includes = about.html\n" + 
91
                "               \n" + 
92
                "source.workbenchtexteditortests.jar = src/\n" + 
93
                "");
94
    }
95
    
96
    public void testSearchBackwards1() {
97
        try {
98
            ArrayList list = HippieCompleteAction.getBackwardsSuggestions(documents[0], 
99
                    "pri", documents[0].get().indexOf("println") + 10);
100
            assertEquals(list.size(), 2);
101
            assertEquals(list.get(0), "ntln");
102
            assertEquals(list.get(1), "nt");
103
104
            list = HippieCompleteAction.getBackwardsSuggestions(documents[0], 
105
                    "pri", documents[0].getLength() - 1);
106
            assertEquals(list.size(), 3);
107
            assertEquals(list.get(0), "nting");
108
            assertEquals(list.get(1), "ntln");
109
            assertEquals(list.get(2), "nt");
110
111
            list = HippieCompleteAction.getBackwardsSuggestions(documents[0], 
112
                    "pri", documents[0].get().indexOf("println") + 1);
113
            assertEquals(list.size(), 1);
114
            assertEquals(list.get(0), "nt");
115
116
        } catch (BadLocationException e) {
117
            assertTrue("Got out of document bounds", false);
118
        }
119
    }
120
    
121
    public void testSearchBackwards2() {
122
        try {
123
            ArrayList list = HippieCompleteAction.getBackwardsSuggestions(documents[2], 
124
                    "plugi", documents[2].getLength() - 1);
125
            assertEquals(8, list.size());
126
            list = HippieCompleteAction.getUnique(list);
127
            assertEquals(1, list.size());
128
            assertEquals("n", list.get(0));
129
130
            list = HippieCompleteAction.getBackwardsSuggestions(documents[2], 
131
                    "plugin", documents[2].getLength() - 1);
132
            assertEquals(0, list.size()); // empty completions discarded
133
134
        } catch (BadLocationException e) {
135
            assertTrue("Got out of document bounds", false);
136
        }
137
    }
138
139
    public void testSearch() {
140
        ArrayList docsList = new ArrayList(Arrays.asList(this.documents));
141
        List result = HippieCompleteAction.createSuggestions("te", docsList);
142
        assertEquals("Number of completions does not match", 12, result.size());
143
        result = HippieCompleteAction.getUnique(result);
144
        assertEquals("Number of completions does not match", 6, result.size());
145
146
        result = HippieCompleteAction.createSuggestions("Plug", docsList);
147
        assertEquals("Number of completions does not match", 2, result.size());
148
149
        result = HippieCompleteAction.createSuggestions("p", docsList);
150
        assertEquals("Number of completions does not match", 20, result.size());
151
        result = HippieCompleteAction.getUnique(result);
152
        assertEquals("Number of completions does not match", 10, result.size());
153
        assertEquals("Incorrect completion", "ackage", result.get(0));
154
        assertEquals("Incorrect completion", "rint", result.get(1));
155
        assertEquals("Incorrect completion", "ublic", result.get(2));
156
        assertEquals("Incorrect completion", "rintln", result.get(3));
157
        assertEquals("Incorrect completion", "rinting", result.get(4));
158
        assertEquals("Incorrect completion", "lugin", result.get(5));
159
        assertEquals("Incorrect completion", "rovider", result.get(6));
160
        assertEquals("Incorrect completion", "roviderName", result.get(7));
161
        assertEquals("Incorrect completion", "rogram", result.get(8));
162
        assertEquals("Incorrect completion", "roperties", result.get(9));
163
    }
164
    
165
    public void testSearch2() {
166
        ArrayList docsList = new ArrayList(Arrays.asList(this.documents));
167
        List result = HippieCompleteAction.createSuggestions("printe", docsList);
168
        assertEquals("Number of completions does not match", 0, result.size());
169
170
        result = HippieCompleteAction.createSuggestions("s", docsList);
171
        assertEquals("Number of completions does not match", 6, result.size());
172
    }
173
    
174
    public static Test suite() {
175
        return new TestSuite(HippieCompletionTest.class); 
176
    }
177
178
}

Return to bug 11668