Line 0
Link Here
|
|
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 2014 Oracle and/or its affiliates. All rights reserved. |
5 |
* |
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
7 |
* Other names may be trademarks of their respective owners. |
8 |
* |
9 |
* The contents of this file are subject to the terms of either the GNU |
10 |
* General Public License Version 2 only ("GPL") or the Common |
11 |
* Development and Distribution License("CDDL") (collectively, the |
12 |
* "License"). You may not use this file except in compliance with the |
13 |
* License. You can obtain a copy of the License at |
14 |
* http://www.netbeans.org/cddl-gplv2.html |
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
16 |
* specific language governing permissions and limitations under the |
17 |
* License. When distributing the software, include this License Header |
18 |
* Notice in each file and include the License file at |
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this |
20 |
* particular file as subject to the "Classpath" exception as provided |
21 |
* by Oracle in the GPL Version 2 section of the License file that |
22 |
* accompanied this code. If applicable, add the following below the |
23 |
* License Header, with the fields enclosed by brackets [] replaced by |
24 |
* your own identifying information: |
25 |
* "Portions Copyrighted [year] [name of copyright owner]" |
26 |
* |
27 |
* If you wish your version of this file to be governed by only the CDDL |
28 |
* or only the GPL Version 2, indicate your decision by adding |
29 |
* "[Contributor] elects to include this software in this distribution |
30 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
31 |
* single choice of license, a recipient has the option to distribute |
32 |
* your version of this file under either the CDDL, the GPL Version 2 or |
33 |
* to extend the choice of license to its licensees as provided above. |
34 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
35 |
* Version 2 license, then the option applies only if the new code is |
36 |
* made subject to such option by the copyright holder. |
37 |
* |
38 |
* Contributor(s): |
39 |
* |
40 |
* Portions Copyrighted 2014 Sun Microsystems, Inc. |
41 |
*/ |
42 |
package org.netbeans.modules.db.sql.editor; |
43 |
|
44 |
import java.util.prefs.Preferences; |
45 |
import org.netbeans.api.editor.mimelookup.MimeLookup; |
46 |
import org.netbeans.modules.csl.api.Formatter; |
47 |
import org.netbeans.modules.csl.api.test.CslTestBase; |
48 |
import org.netbeans.modules.csl.spi.DefaultLanguageConfig; |
49 |
import org.netbeans.modules.db.sql.lexer.SQLLanguageConfig; |
50 |
import org.netbeans.modules.db.sql.lexer.SQLTokenId; |
51 |
|
52 |
public class SQLTypedTextInterceptorTest extends CslTestBase { |
53 |
|
54 |
private final Preferences prefs; |
55 |
|
56 |
public SQLTypedTextInterceptorTest() { |
57 |
super("SQLTypedTextInterceptorTest"); |
58 |
prefs = MimeLookup.getLookup(SQLLanguageConfig.mimeType).lookup(Preferences.class); |
59 |
} |
60 |
|
61 |
@Override |
62 |
protected Formatter getFormatter(IndentPrefs preferences) { |
63 |
return null; |
64 |
} |
65 |
|
66 |
@Override |
67 |
protected boolean runInEQ() { |
68 |
// Must run in AWT thread (BaseKit.install() checks for that) |
69 |
return true; |
70 |
} |
71 |
|
72 |
@Override |
73 |
protected DefaultLanguageConfig getPreferredLanguage() { |
74 |
return new SQLLanguageConfig(); |
75 |
} |
76 |
|
77 |
@Override |
78 |
protected String getPreferredMimeType() { |
79 |
return SQLTokenId.language().mimeType(); |
80 |
} |
81 |
|
82 |
public void testBasicDisabled() throws Exception { |
83 |
prefs.putBoolean(OptionsUtils.PAIR_CHARACTERS_COMPLETION, false); |
84 |
insertChar( |
85 |
"select * from a where b = ^", |
86 |
'\'', |
87 |
"select * from a where b = '^", |
88 |
null, false); |
89 |
insertChar( |
90 |
"select * from a where b = ^", |
91 |
'"', |
92 |
"select * from a where b = \"^", |
93 |
null, false); |
94 |
insertChar( |
95 |
"select * from a where b = ^", |
96 |
'(', |
97 |
"select * from a where b = (^", |
98 |
null, false); |
99 |
insertChar( |
100 |
"select * from a where b = ^", |
101 |
'[', |
102 |
"select * from a where b = [^", |
103 |
null, false); |
104 |
insertChar( |
105 |
"select * from a where b = 'DEMO^'", |
106 |
'\'', |
107 |
"select * from a where b = 'DEMO'^'", |
108 |
null, false); |
109 |
insertChar( |
110 |
"select * from a where b = \"DEMO^\"", |
111 |
'"', |
112 |
"select * from a where b = \"DEMO\"^\"", |
113 |
null, false); |
114 |
insertChar( |
115 |
"select * from a where b = (DEMO^)", |
116 |
')', |
117 |
"select * from a where b = (DEMO)^)", |
118 |
null, false); |
119 |
insertChar( |
120 |
"select * from a where b = [DEMO^]", |
121 |
']', |
122 |
"select * from a where b = [DEMO]^]", |
123 |
null, false); |
124 |
} |
125 |
|
126 |
public void testBasicEnabled() throws Exception { |
127 |
prefs.putBoolean(OptionsUtils.PAIR_CHARACTERS_COMPLETION, true); |
128 |
insertChar( |
129 |
"select * from a where b = ^", |
130 |
'\'', |
131 |
"select * from a where b = '^'", |
132 |
null, false); |
133 |
insertChar( |
134 |
"select * from a where b = ^", |
135 |
'"', |
136 |
"select * from a where b = \"^\"", |
137 |
null, false); |
138 |
insertChar( |
139 |
"select * from a where b = ^", |
140 |
'(', |
141 |
"select * from a where b = (^)", |
142 |
null, false); |
143 |
insertChar( |
144 |
"select * from a where b = ^", |
145 |
'[', |
146 |
"select * from a where b = [^]", |
147 |
null, false); |
148 |
insertChar( |
149 |
"select * from a where b = 'DEMO^'", |
150 |
'\'', |
151 |
"select * from a where b = 'DEMO'^", |
152 |
null, false); |
153 |
insertChar( |
154 |
"select * from a where b = \"DEMO^\"", |
155 |
'"', |
156 |
"select * from a where b = \"DEMO\"^", |
157 |
null, false); |
158 |
insertChar( |
159 |
"select * from a where b = (DEMO^)", |
160 |
')', |
161 |
"select * from a where b = (DEMO)^", |
162 |
null, false); |
163 |
insertChar( |
164 |
"select * from a where b = [DEMO^]", |
165 |
']', |
166 |
"select * from a where b = [DEMO]^", |
167 |
null, false); |
168 |
} |
169 |
|
170 |
public void testEmptyCompletion() throws Exception { |
171 |
prefs.putBoolean(OptionsUtils.PAIR_CHARACTERS_COMPLETION, true); |
172 |
insertChar( |
173 |
"select * from a where b = '^'", |
174 |
'\'', |
175 |
"select * from a where b = ''^", |
176 |
null, false); |
177 |
insertChar( |
178 |
"select * from a where b = \"^\"", |
179 |
'"', |
180 |
"select * from a where b = \"\"^", |
181 |
null, false); |
182 |
insertChar( |
183 |
"select * from a where b = (^)", |
184 |
')', |
185 |
"select * from a where b = ()^", |
186 |
null, false); |
187 |
insertChar( |
188 |
"select * from a where b = [^]", |
189 |
']', |
190 |
"select * from a where b = []^", |
191 |
null, false); |
192 |
} |
193 |
|
194 |
public void testMultiStatementHandling() throws Exception { |
195 |
prefs.putBoolean(OptionsUtils.PAIR_CHARACTERS_COMPLETION, true); |
196 |
insertChar( |
197 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = ^", |
198 |
'\'', |
199 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = '^'", |
200 |
null, false); |
201 |
insertChar( |
202 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = ^", |
203 |
'"', |
204 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = \"^\"", |
205 |
null, false); |
206 |
insertChar( |
207 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = ^", |
208 |
'(', |
209 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = (^)", |
210 |
null, false); |
211 |
insertChar( |
212 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = ^", |
213 |
'[', |
214 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = [^]", |
215 |
null, false); |
216 |
insertChar( |
217 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = 'DEMO^'", |
218 |
'\'', |
219 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = 'DEMO'^", |
220 |
null, false); |
221 |
insertChar( |
222 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = \"DEMO^\"", |
223 |
'"', |
224 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = \"DEMO\"^", |
225 |
null, false); |
226 |
insertChar( |
227 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = (DEMO^)", |
228 |
')', |
229 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = (DEMO)^", |
230 |
null, false); |
231 |
insertChar( |
232 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = [DEMO^]", |
233 |
']', |
234 |
"create table dummy(id integer, titel varchar(255)); select * from a where b = [DEMO]^", |
235 |
null, false); |
236 |
} |
237 |
|
238 |
public void testAlwaysSwallowClosingBraces() throws Exception { |
239 |
prefs.putBoolean(OptionsUtils.PAIR_CHARACTERS_COMPLETION, true); |
240 |
insertChar( |
241 |
"select * from a where (b = a^)", |
242 |
')', |
243 |
"select * from a where (b = a)^", |
244 |
null, false); |
245 |
insertChar( |
246 |
"select * from a where (b = a)^)", |
247 |
')', |
248 |
"select * from a where (b = a))^", |
249 |
null, false); |
250 |
} |
251 |
} |