Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
******************************************************************************/ |
11 |
|
12 |
package org.eclipse.equinox.bidi.internal.tests; |
13 |
|
14 |
import junit.framework.Test; |
15 |
import junit.framework.TestCase; |
16 |
import junit.framework.TestSuite; |
17 |
|
18 |
import org.eclipse.equinox.bidi.complexp.IComplExpProcessor; |
19 |
import org.eclipse.equinox.bidi.complexp.StringProcessor; |
20 |
import org.eclipse.equinox.bidi.complexp.IBiDiProcessor; |
21 |
|
22 |
/** |
23 |
* Tests fullToLean method |
24 |
*/ |
25 |
|
26 |
public class FullToLeanTest extends TestCase { |
27 |
public static Test suite() { |
28 |
return new TestSuite(FullToLeanTest.class); |
29 |
} |
30 |
|
31 |
public FullToLeanTest() { |
32 |
super(); |
33 |
} |
34 |
|
35 |
public FullToLeanTest(String name) { |
36 |
super(name); |
37 |
} |
38 |
|
39 |
static int[] getpos(IComplExpProcessor complexp, boolean leanToFull) |
40 |
{ |
41 |
int[] pos = new int[5]; |
42 |
|
43 |
if (leanToFull) { |
44 |
pos[0] = complexp.leanToFullPos(0); |
45 |
pos[1] = complexp.leanToFullPos(4); |
46 |
pos[2] = complexp.leanToFullPos(7); |
47 |
pos[3] = complexp.leanToFullPos(10); |
48 |
pos[4] = complexp.leanToFullPos(30); |
49 |
} else { |
50 |
pos[0] = complexp.fullToLeanPos(0); |
51 |
pos[1] = complexp.fullToLeanPos(4); |
52 |
pos[2] = complexp.fullToLeanPos(7); |
53 |
pos[3] = complexp.fullToLeanPos(10); |
54 |
pos[4] = complexp.fullToLeanPos(30); |
55 |
} |
56 |
return pos; |
57 |
} |
58 |
|
59 |
static void doTest1(IComplExpProcessor complexp, String data, |
60 |
String leanLTR, String fullLTR, |
61 |
int[] l2fPosLTR, int[] f2lPosLTR, |
62 |
String leanRTL, String fullRTL, |
63 |
int[] l2fPosRTL, int[] f2lPosRTL) |
64 |
{ |
65 |
String text, full, lean; |
66 |
int[] pos; |
67 |
|
68 |
System.out.println(); |
69 |
System.out.println(">>> text=" + data); |
70 |
text = Tools.toUT16(data); |
71 |
complexp.assumeOrientation(IComplExpProcessor.ORIENT_LTR); |
72 |
lean = complexp.fullToLeanText(text); |
73 |
Tools.verify("LTR lean", lean, leanLTR); |
74 |
full = complexp.leanToFullText(lean); |
75 |
Tools.verify("LTR full", full, fullLTR); |
76 |
pos = getpos(complexp, true); |
77 |
Tools.verify("leanToFullPos()", pos, l2fPosLTR); |
78 |
pos = getpos(complexp, false); |
79 |
Tools.verify("fullToLeanPos()", pos, f2lPosLTR); |
80 |
complexp.assumeOrientation(IComplExpProcessor.ORIENT_RTL); |
81 |
lean = complexp.fullToLeanText(text); |
82 |
Tools.verify("RTL lean", lean, leanRTL); |
83 |
full = complexp.leanToFullText(lean); |
84 |
Tools.verify("RTL full", full, fullRTL); |
85 |
pos = getpos(complexp, true); |
86 |
Tools.verify("leanToFullPos()", pos, l2fPosRTL); |
87 |
pos = getpos(complexp, false); |
88 |
Tools.verify("fullToLeanPos()", pos, f2lPosRTL); |
89 |
complexp.assumeOrientation(IComplExpProcessor.ORIENT_RTL); |
90 |
lean = complexp.fullToLeanText(text); |
91 |
} |
92 |
|
93 |
static void doTest2() |
94 |
{ |
95 |
IComplExpProcessor complexp; |
96 |
String text, data, full, lean, model; |
97 |
int state, state2, state3; |
98 |
|
99 |
complexp = StringProcessor.getProcessor(IBiDiProcessor.SQL); |
100 |
complexp.assumeOrientation(IComplExpProcessor.ORIENT_LTR); |
101 |
System.out.println(); |
102 |
data = "update \"AB_CDE\" set \"COL1\"@='01', \"COL2\"@='02' /* GH IJK"; |
103 |
System.out.println(">>> text=" + data); |
104 |
text = Tools.toUT16(data); |
105 |
lean = complexp.fullToLeanText(text); |
106 |
state = complexp.getFinalState(); |
107 |
model = "update \"AB_CDE\" set \"COL1\"='01', \"COL2\"='02' /* GH IJK"; |
108 |
Tools.verify("LTR lean", lean, model); |
109 |
full = complexp.leanToFullText(lean); |
110 |
Tools.verify("LTR full", full, data); |
111 |
Tools.verify("state from leanToFullText", state, complexp.getFinalState()); |
112 |
data = "THIS IS A COMMENT LINE"; |
113 |
System.out.println(">>> text=" + data); |
114 |
text = Tools.toUT16(data); |
115 |
lean = complexp.fullToLeanText(text, state); |
116 |
state2 = complexp.getFinalState(); |
117 |
model = "THIS IS A COMMENT LINE"; |
118 |
Tools.verify("LTR lean", lean, model); |
119 |
full = complexp.leanToFullText(lean, state); |
120 |
Tools.verify("LTR full", full, data); |
121 |
Tools.verify("state from leanToFullText", state2, complexp.getFinalState()); |
122 |
data = "SOME MORE */ where \"COL3\"@=123"; |
123 |
System.out.println(">>> text=" + data); |
124 |
text = Tools.toUT16(data); |
125 |
lean = complexp.fullToLeanText(text, state2); |
126 |
state3 = complexp.getFinalState(); |
127 |
model = "SOME MORE */ where \"COL3\"=123"; |
128 |
Tools.verify("LTR lean", lean, model); |
129 |
full = complexp.leanToFullText(lean, state2); |
130 |
Tools.verify("LTR full", full, data); |
131 |
Tools.verify("state from leanToFullText", state3, complexp.getFinalState()); |
132 |
} |
133 |
|
134 |
public static void testFullToLean() { |
135 |
Tools.separ("FullToLeanTest"); |
136 |
IComplExpProcessor complexp = StringProcessor.getProcessor(IBiDiProcessor.COMMA_DELIMITED); |
137 |
|
138 |
doTest1(complexp, "", |
139 |
"", "", |
140 |
new int[]{0,4,7,10,30}, new int[]{0,0,0,0,0}, |
141 |
"", "", |
142 |
new int[]{0,4,7,10,30}, new int[]{0,0,0,0,0}); |
143 |
doTest1(complexp, "1.abc", |
144 |
"1.abc", "1.abc", |
145 |
new int[]{0,4,7,10,30}, new int[]{0,4,5,5,5}, |
146 |
"1.abc", ">@1.abc@^", |
147 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,5,5}); |
148 |
doTest1(complexp, "2.abc,def", |
149 |
"2.abc,def", "2.abc,def", |
150 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9}, |
151 |
"2.abc,def", ">@2.abc,def@^", |
152 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9}); |
153 |
doTest1(complexp, "@a.3.bc,def", |
154 |
"a.3.bc,def", "a.3.bc,def", |
155 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,10,10}, |
156 |
"a.3.bc,def", ">@a.3.bc,def@^", |
157 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,10}); |
158 |
doTest1(complexp, "@@a.4.bc,def", |
159 |
"a.4.bc,def", "a.4.bc,def", |
160 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,10,10}, |
161 |
"a.4.bc,def", ">@a.4.bc,def@^", |
162 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,10}); |
163 |
doTest1(complexp, "@5.abc,def", |
164 |
"5.abc,def", "5.abc,def", |
165 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9}, |
166 |
"5.abc,def", ">@5.abc,def@^", |
167 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9}); |
168 |
doTest1(complexp, "@@6.abc,def", |
169 |
"6.abc,def", "6.abc,def", |
170 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9}, |
171 |
"6.abc,def", ">@6.abc,def@^", |
172 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9}); |
173 |
doTest1(complexp, "7abc,@def", |
174 |
"7abc,@def", "7abc,@def", |
175 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9}, |
176 |
"7abc,@def", ">@7abc,@def@^", |
177 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9}); |
178 |
doTest1(complexp, "8abc,@@def", |
179 |
"8abc,@def", "8abc,@def", |
180 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9}, |
181 |
"8abc,@def", ">@8abc,@def@^", |
182 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9}); |
183 |
doTest1(complexp, "9abc,def@", |
184 |
"9abc,def", "9abc,def", |
185 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,8,8}, |
186 |
"9abc,def", ">@9abc,def@^", |
187 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,8}); |
188 |
doTest1(complexp, "10abc,def@@", |
189 |
"10abc,def", "10abc,def", |
190 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9}, |
191 |
"10abc,def", ">@10abc,def@^", |
192 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9}); |
193 |
doTest1(complexp, "@a.11.bc,@def@", |
194 |
"a.11.bc,@def", "a.11.bc,@def", |
195 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,10,12}, |
196 |
"a.11.bc,@def", ">@a.11.bc,@def@^", |
197 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,12}); |
198 |
doTest1(complexp, "@@a.12.bc,@@def@@", |
199 |
"a.12.bc,@def", "a.12.bc,@def", |
200 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,10,12}, |
201 |
"a.12.bc,@def", ">@a.12.bc,@def@^", |
202 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,12}); |
203 |
doTest1(complexp, "13ABC", |
204 |
"13ABC", "13ABC", |
205 |
new int[]{0,4,7,10,30}, new int[]{0,4,5,5,5}, |
206 |
"13ABC", ">@13ABC@^", |
207 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,5,5}); |
208 |
doTest1(complexp, "14ABC,DE", |
209 |
"14ABC,DE", "14ABC@,DE", |
210 |
new int[]{0,4,8,11,31}, new int[]{0,4,6,8,8}, |
211 |
"14ABC,DE", ">@14ABC@,DE@^", |
212 |
new int[]{2,6,10,13,33}, new int[]{0,2,5,7,8}); |
213 |
doTest1(complexp, "15ABC@,DE", |
214 |
"15ABC,DE", "15ABC@,DE", |
215 |
new int[]{0,4,8,11,31}, new int[]{0,4,6,8,8}, |
216 |
"15ABC,DE", ">@15ABC@,DE@^", |
217 |
new int[]{2,6,10,13,33}, new int[]{0,2,5,7,8}); |
218 |
doTest1(complexp, "16ABC@@,DE", |
219 |
"16ABC,DE", "16ABC@,DE", |
220 |
new int[]{0,4,8,11,31}, new int[]{0,4,6,8,8}, |
221 |
"16ABC,DE", ">@16ABC@,DE@^", |
222 |
new int[]{2,6,10,13,33}, new int[]{0,2,5,7,8}); |
223 |
doTest1(complexp, "17ABC,@@DE", |
224 |
"17ABC,@DE", "17ABC,@DE", |
225 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,9,9}, |
226 |
"17ABC,@DE", ">@17ABC,@DE@^", |
227 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,9}); |
228 |
doTest1(complexp, "18ABC,DE,FGH", |
229 |
"18ABC,DE,FGH", "18ABC@,DE@,FGH", |
230 |
new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12}, |
231 |
"18ABC,DE,FGH", ">@18ABC@,DE@,FGH@^", |
232 |
new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12}); |
233 |
doTest1(complexp, "19ABC@,DE@,FGH", |
234 |
"19ABC,DE,FGH", "19ABC@,DE@,FGH", |
235 |
new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12}, |
236 |
"19ABC,DE,FGH", ">@19ABC@,DE@,FGH@^", |
237 |
new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12}); |
238 |
doTest1(complexp, "20ABC,@DE,@FGH", |
239 |
"20ABC,@DE,@FGH", "20ABC,@DE,@FGH", |
240 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,10,14}, |
241 |
"20ABC,@DE,@FGH", ">@20ABC,@DE,@FGH@^", |
242 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,14}); |
243 |
doTest1(complexp, "21ABC@@,DE@@,FGH", |
244 |
"21ABC,DE,FGH", "21ABC@,DE@,FGH", |
245 |
new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12}, |
246 |
"21ABC,DE,FGH", ">@21ABC@,DE@,FGH@^", |
247 |
new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12}); |
248 |
doTest1(complexp, "22ABC,@@DE,@@FGH", |
249 |
"22ABC,@DE,@FGH", "22ABC,@DE,@FGH", |
250 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,10,14}, |
251 |
"22ABC,@DE,@FGH", ">@22ABC,@DE,@FGH@^", |
252 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,14}); |
253 |
doTest1(complexp, ">@23abc@^", |
254 |
"23abc", "23abc", |
255 |
new int[]{0,4,7,10,30}, new int[]{0,4,5,5,5}, |
256 |
"23abc", ">@23abc@^", |
257 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,5,5}); |
258 |
doTest1(complexp, "24abc@^", |
259 |
"24abc", "24abc", |
260 |
new int[]{0,4,7,10,30}, new int[]{0,4,5,5,5}, |
261 |
"24abc", ">@24abc@^", |
262 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,5,5}); |
263 |
doTest1(complexp, ">@25abc", |
264 |
"25abc", "25abc", |
265 |
new int[]{0,4,7,10,30}, new int[]{0,4,5,5,5}, |
266 |
"25abc", ">@25abc@^", |
267 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,5,5}); |
268 |
doTest1(complexp, "26AB,CD@EF,GHI", |
269 |
"26AB,CD@EF,GHI", "26AB@,CD@EF@,GHI", |
270 |
new int[]{0,5,8,12,32}, new int[]{0,4,6,9,14}, |
271 |
"26AB,CD@EF,GHI", ">@26AB@,CD@EF@,GHI@^", |
272 |
new int[]{2,7,10,14,34}, new int[]{0,2,4,7,14}); |
273 |
doTest1(complexp, "27AB,CD@123ef,GHI", |
274 |
"27AB,CD@123ef,GHI", "27AB@,CD@123ef,GHI", |
275 |
new int[]{0,5,8,11,31}, new int[]{0,4,6,9,17}, |
276 |
"27AB,CD@123ef,GHI", ">@27AB@,CD@123ef,GHI@^", |
277 |
new int[]{2,7,10,13,33}, new int[]{0,2,4,7,17}); |
278 |
doTest1(complexp, ">28ABC@,DE@,FGH^", |
279 |
"28ABC,DE,FGH", "28ABC@,DE@,FGH", |
280 |
new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12}, |
281 |
"28ABC,DE,FGH", ">@28ABC@,DE@,FGH@^", |
282 |
new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12}); |
283 |
doTest1(complexp, ">>29ABC@,DE@,FGH^^", |
284 |
"29ABC,DE,FGH", "29ABC@,DE@,FGH", |
285 |
new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12}, |
286 |
"29ABC,DE,FGH", ">@29ABC@,DE@,FGH@^", |
287 |
new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12}); |
288 |
doTest1(complexp, ">30AB>C^@,DE@,FGH^", |
289 |
"30AB>C^,DE,FGH", "30AB>C^@,DE@,FGH", |
290 |
new int[]{0,4,8,12,32}, new int[]{0,4,7,9,14}, |
291 |
"30AB>C^,DE,FGH", ">@30AB>C^@,DE@,FGH@^", |
292 |
new int[]{2,6,10,14,34}, new int[]{0,2,5,7,14}); |
293 |
doTest1(complexp, ">31AB>C@,DE@,FGH^^", |
294 |
"31AB>C,DE,FGH", "31AB>C@,DE@,FGH", |
295 |
new int[]{0,4,8,12,32}, new int[]{0,4,6,9,13}, |
296 |
"31AB>C,DE,FGH", ">@31AB>C@,DE@,FGH@^", |
297 |
new int[]{2,6,10,14,34}, new int[]{0,2,5,7,13}); |
298 |
doTest1(complexp, ">@32ABC@,DE@,FGH@^", |
299 |
"32ABC,DE,FGH", "32ABC@,DE@,FGH", |
300 |
new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12}, |
301 |
"32ABC,DE,FGH", ">@32ABC@,DE@,FGH@^", |
302 |
new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12}); |
303 |
doTest1(complexp, "@33ABC@,DE@,FGH@^", |
304 |
"33ABC,DE,FGH", "33ABC@,DE@,FGH", |
305 |
new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12}, |
306 |
"33ABC,DE,FGH", ">@33ABC@,DE@,FGH@^", |
307 |
new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12}); |
308 |
doTest1(complexp, ">@34ABC@,DE@,FGH@", |
309 |
"34ABC,DE,FGH", "34ABC@,DE@,FGH", |
310 |
new int[]{0,4,8,12,32}, new int[]{0,4,6,8,12}, |
311 |
"34ABC,DE,FGH", ">@34ABC@,DE@,FGH@^", |
312 |
new int[]{2,6,10,14,34}, new int[]{0,2,5,7,12}); |
313 |
doTest1(complexp, "35ABC@@DE@@@GH@", |
314 |
"35ABC@DE@GH", "35ABC@DE@GH", |
315 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,10,11}, |
316 |
"35ABC@DE@GH", ">@35ABC@DE@GH@^", |
317 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,11}); |
318 |
doTest1(complexp, "36ABC@@DE@@@@@@", |
319 |
"36ABC@DE", "36ABC@DE", |
320 |
new int[]{0,4,7,10,30}, new int[]{0,4,7,8,8}, |
321 |
"36ABC@DE", ">@36ABC@DE@^", |
322 |
new int[]{2,6,9,12,32}, new int[]{0,2,5,8,8}); |
323 |
doTest1(complexp, ">>>@@@@@^^^", |
324 |
"", "", |
325 |
new int[]{0,4,7,10,30}, new int[]{0,0,0,0,0}, |
326 |
"", "", |
327 |
new int[]{0,4,7,10,30}, new int[]{0,0,0,0,0}); |
328 |
|
329 |
// test fullToLeanText with initial state |
330 |
doTest2(); |
331 |
|
332 |
Tools.printStepErrorCount(); |
333 |
} |
334 |
} |