Removed
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 org.eclipse.equinox.bidi.complexp.IComplExpProcessor; |
15 |
import org.eclipse.equinox.bidi.complexp.StringProcessor; |
16 |
import org.eclipse.equinox.bidi.complexp.IBiDiProcessor; |
17 |
|
18 |
/** |
19 |
* Tests fullToLean method |
20 |
*/ |
21 |
|
22 |
public class FullToLeanTest extends ComplExpTestBase { |
23 |
|
24 |
private IComplExpProcessor processor; |
25 |
|
26 |
protected void setUp() throws Exception { |
27 |
super.setUp(); |
28 |
processor = StringProcessor |
29 |
.getProcessor(IBiDiProcessor.COMMA_DELIMITED); |
30 |
} |
31 |
|
32 |
static int[] getpos(IComplExpProcessor complexp, boolean leanToFull) { |
33 |
int[] pos = new int[5]; |
34 |
|
35 |
if (leanToFull) { |
36 |
pos[0] = complexp.leanToFullPos(0); |
37 |
pos[1] = complexp.leanToFullPos(4); |
38 |
pos[2] = complexp.leanToFullPos(7); |
39 |
pos[3] = complexp.leanToFullPos(10); |
40 |
pos[4] = complexp.leanToFullPos(30); |
41 |
} else { |
42 |
pos[0] = complexp.fullToLeanPos(0); |
43 |
pos[1] = complexp.fullToLeanPos(4); |
44 |
pos[2] = complexp.fullToLeanPos(7); |
45 |
pos[3] = complexp.fullToLeanPos(10); |
46 |
pos[4] = complexp.fullToLeanPos(30); |
47 |
} |
48 |
return pos; |
49 |
} |
50 |
|
51 |
private void doTest1(String msg, String data, String leanLTR, |
52 |
String fullLTR, int[] l2fPosLTR, int[] f2lPosLTR, String leanRTL, |
53 |
String fullRTL, int[] l2fPosRTL, int[] f2lPosRTL) { |
54 |
String text, full, lean, label; |
55 |
int[] pos; |
56 |
|
57 |
text = toUT16(data); |
58 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_LTR); |
59 |
lean = processor.fullToLeanText(text); |
60 |
assertEquals(msg + "LTR lean", leanLTR, toPseudo(lean)); |
61 |
full = processor.leanToFullText(lean); |
62 |
assertEquals(msg + "LTR full", fullLTR, toPseudo(full)); |
63 |
pos = getpos(processor, true); |
64 |
label = msg + "leanToFullPos() LTR, expected=" |
65 |
+ array_display(l2fPosLTR) + " result=" + array_display(pos); |
66 |
assertTrue(label, arrays_equal(l2fPosLTR, pos)); |
67 |
pos = getpos(processor, false); |
68 |
label = msg + "fullToLeanPos() LTR, expected=" |
69 |
+ array_display(f2lPosLTR) + " result=" + array_display(pos); |
70 |
assertTrue(label, arrays_equal(f2lPosLTR, pos)); |
71 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_RTL); |
72 |
lean = processor.fullToLeanText(text); |
73 |
assertEquals(msg + "RTL lean", leanRTL, toPseudo(lean)); |
74 |
full = processor.leanToFullText(lean); |
75 |
assertEquals(msg + "RTL full", fullRTL, toPseudo(full)); |
76 |
pos = getpos(processor, true); |
77 |
label = msg + "leanToFullPos() RTL, expected=" |
78 |
+ array_display(l2fPosRTL) + " result=" + array_display(pos); |
79 |
assertTrue(label, arrays_equal(l2fPosRTL, pos)); |
80 |
pos = getpos(processor, false); |
81 |
label = msg + "fullToLeanPos() RTL, expected=" |
82 |
+ array_display(f2lPosRTL) + " result=" + array_display(pos); |
83 |
assertTrue(label, arrays_equal(f2lPosRTL, pos)); |
84 |
} |
85 |
|
86 |
private void doTest2(String msg) { |
87 |
String text, data, full, lean, model; |
88 |
int state, state2, state3; |
89 |
|
90 |
processor = StringProcessor.getProcessor(IBiDiProcessor.SQL); |
91 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_LTR); |
92 |
data = "update \"AB_CDE\" set \"COL1\"@='01', \"COL2\"@='02' /* GH IJK"; |
93 |
text = toUT16(data); |
94 |
lean = processor.fullToLeanText(text); |
95 |
state = processor.getFinalState(); |
96 |
model = "update \"AB_CDE\" set \"COL1\"='01', \"COL2\"='02' /* GH IJK"; |
97 |
assertEquals(msg + "LTR lean", model, toPseudo(lean)); |
98 |
full = processor.leanToFullText(lean); |
99 |
assertEquals(msg + "LTR full", data, toPseudo(full)); |
100 |
assertEquals(msg + "state from leanToFullText", processor |
101 |
.getFinalState(), state); |
102 |
data = "THIS IS A COMMENT LINE"; |
103 |
text = toUT16(data); |
104 |
lean = processor.fullToLeanText(text, state); |
105 |
state2 = processor.getFinalState(); |
106 |
model = "THIS IS A COMMENT LINE"; |
107 |
assertEquals(msg + "LTR lean2", model, toPseudo(lean)); |
108 |
full = processor.leanToFullText(lean, state); |
109 |
assertEquals(msg + "LTR full2", data, toPseudo(full)); |
110 |
assertEquals(msg + "state from leanToFullText2", processor |
111 |
.getFinalState(), state2); |
112 |
data = "SOME MORE */ where \"COL3\"@=123"; |
113 |
text = toUT16(data); |
114 |
lean = processor.fullToLeanText(text, state2); |
115 |
state3 = processor.getFinalState(); |
116 |
model = "SOME MORE */ where \"COL3\"=123"; |
117 |
assertEquals(msg + "LTR lean3", model, toPseudo(lean)); |
118 |
full = processor.leanToFullText(lean, state2); |
119 |
assertEquals(msg + "LTR full3", data, toPseudo(full)); |
120 |
assertEquals(msg + "state from leanToFullText3", processor |
121 |
.getFinalState(), state3); |
122 |
} |
123 |
|
124 |
public void testFullToLean() { |
125 |
|
126 |
doTest1("testFullToLean #1 - ", "", "", "", |
127 |
new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 0, 0, 0, 0 }, "", |
128 |
"", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 0, 0, 0, 0 }); |
129 |
doTest1("testFullToLean #01 - ", "1.abc", "1.abc", "1.abc", new int[] { |
130 |
0, 4, 7, 10, 30 }, new int[] { 0, 4, 5, 5, 5 }, "1.abc", |
131 |
">@1.abc@^", new int[] { 2, 6, 9, 12, 32 }, new int[] { 0, 2, |
132 |
5, 5, 5 }); |
133 |
doTest1("testFullToLean #02 - ", "2.abc,def", "2.abc,def", "2.abc,def", |
134 |
new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, 7, 9, 9 }, |
135 |
"2.abc,def", ">@2.abc,def@^", new int[] { 2, 6, 9, 12, 32 }, |
136 |
new int[] { 0, 2, 5, 8, 9 }); |
137 |
doTest1("testFullToLean #03 - ", "@a.3.bc,def", "a.3.bc,def", |
138 |
"a.3.bc,def", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, |
139 |
7, 10, 10 }, "a.3.bc,def", ">@a.3.bc,def@^", new int[] { |
140 |
2, 6, 9, 12, 32 }, new int[] { 0, 2, 5, 8, 10 }); |
141 |
doTest1("testFullToLean #04 - ", "@@a.4.bc,def", "a.4.bc,def", |
142 |
"a.4.bc,def", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, |
143 |
7, 10, 10 }, "a.4.bc,def", ">@a.4.bc,def@^", new int[] { |
144 |
2, 6, 9, 12, 32 }, new int[] { 0, 2, 5, 8, 10 }); |
145 |
doTest1("testFullToLean #05 - ", "@5.abc,def", "5.abc,def", |
146 |
"5.abc,def", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, |
147 |
7, 9, 9 }, "5.abc,def", ">@5.abc,def@^", new int[] { 2, |
148 |
6, 9, 12, 32 }, new int[] { 0, 2, 5, 8, 9 }); |
149 |
doTest1("testFullToLean #06 - ", "@@6.abc,def", "6.abc,def", |
150 |
"6.abc,def", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, |
151 |
7, 9, 9 }, "6.abc,def", ">@6.abc,def@^", new int[] { 2, |
152 |
6, 9, 12, 32 }, new int[] { 0, 2, 5, 8, 9 }); |
153 |
doTest1("testFullToLean #07 - ", "7abc,@def", "7abc,@def", "7abc,@def", |
154 |
new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, 7, 9, 9 }, |
155 |
"7abc,@def", ">@7abc,@def@^", new int[] { 2, 6, 9, 12, 32 }, |
156 |
new int[] { 0, 2, 5, 8, 9 }); |
157 |
doTest1("testFullToLean #08 - ", "8abc,@@def", "8abc,@def", |
158 |
"8abc,@def", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, |
159 |
7, 9, 9 }, "8abc,@def", ">@8abc,@def@^", new int[] { 2, |
160 |
6, 9, 12, 32 }, new int[] { 0, 2, 5, 8, 9 }); |
161 |
doTest1("testFullToLean #09 - ", "9abc,def@", "9abc,def", "9abc,def", |
162 |
new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, 7, 8, 8 }, |
163 |
"9abc,def", ">@9abc,def@^", new int[] { 2, 6, 9, 12, 32 }, |
164 |
new int[] { 0, 2, 5, 8, 8 }); |
165 |
doTest1("testFullToLean #10 - ", "10abc,def@@", "10abc,def", |
166 |
"10abc,def", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, |
167 |
7, 9, 9 }, "10abc,def", ">@10abc,def@^", new int[] { 2, |
168 |
6, 9, 12, 32 }, new int[] { 0, 2, 5, 8, 9 }); |
169 |
doTest1("testFullToLean #11 - ", "@a.11.bc,@def@", "a.11.bc,@def", |
170 |
"a.11.bc,@def", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, |
171 |
4, 7, 10, 12 }, "a.11.bc,@def", ">@a.11.bc,@def@^", |
172 |
new int[] { 2, 6, 9, 12, 32 }, new int[] { 0, 2, 5, 8, 12 }); |
173 |
doTest1("testFullToLean #12 - ", "@@a.12.bc,@@def@@", "a.12.bc,@def", |
174 |
"a.12.bc,@def", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, |
175 |
4, 7, 10, 12 }, "a.12.bc,@def", ">@a.12.bc,@def@^", |
176 |
new int[] { 2, 6, 9, 12, 32 }, new int[] { 0, 2, 5, 8, 12 }); |
177 |
doTest1("testFullToLean #13 - ", "13ABC", "13ABC", "13ABC", new int[] { |
178 |
0, 4, 7, 10, 30 }, new int[] { 0, 4, 5, 5, 5 }, "13ABC", |
179 |
">@13ABC@^", new int[] { 2, 6, 9, 12, 32 }, new int[] { 0, 2, |
180 |
5, 5, 5 }); |
181 |
doTest1("testFullToLean #14 - ", "14ABC,DE", "14ABC,DE", "14ABC@,DE", |
182 |
new int[] { 0, 4, 8, 11, 31 }, new int[] { 0, 4, 6, 8, 8 }, |
183 |
"14ABC,DE", ">@14ABC@,DE@^", new int[] { 2, 6, 10, 13, 33 }, |
184 |
new int[] { 0, 2, 5, 7, 8 }); |
185 |
doTest1("testFullToLean #15 - ", "15ABC@,DE", "15ABC,DE", "15ABC@,DE", |
186 |
new int[] { 0, 4, 8, 11, 31 }, new int[] { 0, 4, 6, 8, 8 }, |
187 |
"15ABC,DE", ">@15ABC@,DE@^", new int[] { 2, 6, 10, 13, 33 }, |
188 |
new int[] { 0, 2, 5, 7, 8 }); |
189 |
doTest1("testFullToLean #16 - ", "16ABC@@,DE", "16ABC,DE", "16ABC@,DE", |
190 |
new int[] { 0, 4, 8, 11, 31 }, new int[] { 0, 4, 6, 8, 8 }, |
191 |
"16ABC,DE", ">@16ABC@,DE@^", new int[] { 2, 6, 10, 13, 33 }, |
192 |
new int[] { 0, 2, 5, 7, 8 }); |
193 |
doTest1("testFullToLean #17 - ", "17ABC,@@DE", "17ABC,@DE", |
194 |
"17ABC,@DE", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, |
195 |
7, 9, 9 }, "17ABC,@DE", ">@17ABC,@DE@^", new int[] { 2, |
196 |
6, 9, 12, 32 }, new int[] { 0, 2, 5, 8, 9 }); |
197 |
doTest1("testFullToLean #18 - ", "18ABC,DE,FGH", "18ABC,DE,FGH", |
198 |
"18ABC@,DE@,FGH", new int[] { 0, 4, 8, 12, 32 }, new int[] { 0, |
199 |
4, 6, 8, 12 }, "18ABC,DE,FGH", ">@18ABC@,DE@,FGH@^", |
200 |
new int[] { 2, 6, 10, 14, 34 }, new int[] { 0, 2, 5, 7, 12 }); |
201 |
doTest1("testFullToLean #19 - ", "19ABC@,DE@,FGH", "19ABC,DE,FGH", |
202 |
"19ABC@,DE@,FGH", new int[] { 0, 4, 8, 12, 32 }, new int[] { 0, |
203 |
4, 6, 8, 12 }, "19ABC,DE,FGH", ">@19ABC@,DE@,FGH@^", |
204 |
new int[] { 2, 6, 10, 14, 34 }, new int[] { 0, 2, 5, 7, 12 }); |
205 |
doTest1("testFullToLean #20 - ", "20ABC,@DE,@FGH", "20ABC,@DE,@FGH", |
206 |
"20ABC,@DE,@FGH", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, |
207 |
4, 7, 10, 14 }, "20ABC,@DE,@FGH", ">@20ABC,@DE,@FGH@^", |
208 |
new int[] { 2, 6, 9, 12, 32 }, new int[] { 0, 2, 5, 8, 14 }); |
209 |
doTest1("testFullToLean #21 - ", "21ABC@@,DE@@,FGH", "21ABC,DE,FGH", |
210 |
"21ABC@,DE@,FGH", new int[] { 0, 4, 8, 12, 32 }, new int[] { 0, |
211 |
4, 6, 8, 12 }, "21ABC,DE,FGH", ">@21ABC@,DE@,FGH@^", |
212 |
new int[] { 2, 6, 10, 14, 34 }, new int[] { 0, 2, 5, 7, 12 }); |
213 |
doTest1("testFullToLean #22 - ", "22ABC,@@DE,@@FGH", "22ABC,@DE,@FGH", |
214 |
"22ABC,@DE,@FGH", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, |
215 |
4, 7, 10, 14 }, "22ABC,@DE,@FGH", ">@22ABC,@DE,@FGH@^", |
216 |
new int[] { 2, 6, 9, 12, 32 }, new int[] { 0, 2, 5, 8, 14 }); |
217 |
doTest1("testFullToLean #23 - ", ">@23abc@^", "23abc", "23abc", |
218 |
new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, 5, 5, 5 }, |
219 |
"23abc", ">@23abc@^", new int[] { 2, 6, 9, 12, 32 }, new int[] { |
220 |
0, 2, 5, 5, 5 }); |
221 |
doTest1("testFullToLean #24 - ", "24abc@^", "24abc", "24abc", |
222 |
new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, 5, 5, 5 }, |
223 |
"24abc", ">@24abc@^", new int[] { 2, 6, 9, 12, 32 }, new int[] { |
224 |
0, 2, 5, 5, 5 }); |
225 |
doTest1("testFullToLean #25 - ", ">@25abc", "25abc", "25abc", |
226 |
new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, 5, 5, 5 }, |
227 |
"25abc", ">@25abc@^", new int[] { 2, 6, 9, 12, 32 }, new int[] { |
228 |
0, 2, 5, 5, 5 }); |
229 |
doTest1("testFullToLean #26 - ", "26AB,CD@EF,GHI", "26AB,CD@EF,GHI", |
230 |
"26AB@,CD@EF@,GHI", new int[] { 0, 5, 8, 12, 32 }, new int[] { |
231 |
0, 4, 6, 9, 14 }, "26AB,CD@EF,GHI", |
232 |
">@26AB@,CD@EF@,GHI@^", new int[] { 2, 7, 10, 14, 34 }, |
233 |
new int[] { 0, 2, 4, 7, 14 }); |
234 |
doTest1("testFullToLean #27 - ", "27AB,CD@123ef,GHI", |
235 |
"27AB,CD@123ef,GHI", "27AB@,CD@123ef,GHI", new int[] { 0, 5, 8, |
236 |
11, 31 }, new int[] { 0, 4, 6, 9, 17 }, |
237 |
"27AB,CD@123ef,GHI", ">@27AB@,CD@123ef,GHI@^", new int[] { 2, |
238 |
7, 10, 13, 33 }, new int[] { 0, 2, 4, 7, 17 }); |
239 |
doTest1("testFullToLean #28 - ", ">28ABC@,DE@,FGH^", "28ABC,DE,FGH", |
240 |
"28ABC@,DE@,FGH", new int[] { 0, 4, 8, 12, 32 }, new int[] { 0, |
241 |
4, 6, 8, 12 }, "28ABC,DE,FGH", ">@28ABC@,DE@,FGH@^", |
242 |
new int[] { 2, 6, 10, 14, 34 }, new int[] { 0, 2, 5, 7, 12 }); |
243 |
doTest1("testFullToLean #29 - ", ">>29ABC@,DE@,FGH^^", "29ABC,DE,FGH", |
244 |
"29ABC@,DE@,FGH", new int[] { 0, 4, 8, 12, 32 }, new int[] { 0, |
245 |
4, 6, 8, 12 }, "29ABC,DE,FGH", ">@29ABC@,DE@,FGH@^", |
246 |
new int[] { 2, 6, 10, 14, 34 }, new int[] { 0, 2, 5, 7, 12 }); |
247 |
doTest1("testFullToLean #30 - ", ">30AB>C^@,DE@,FGH^", |
248 |
"30AB>C^,DE,FGH", "30AB>C^@,DE@,FGH", new int[] { 0, 4, 8, 12, |
249 |
32 }, new int[] { 0, 4, 7, 9, 14 }, "30AB>C^,DE,FGH", |
250 |
">@30AB>C^@,DE@,FGH@^", new int[] { 2, 6, 10, 14, 34 }, |
251 |
new int[] { 0, 2, 5, 7, 14 }); |
252 |
doTest1("testFullToLean #31 - ", ">31AB>C@,DE@,FGH^^", "31AB>C,DE,FGH", |
253 |
"31AB>C@,DE@,FGH", new int[] { 0, 4, 8, 12, 32 }, new int[] { |
254 |
0, 4, 6, 9, 13 }, "31AB>C,DE,FGH", |
255 |
">@31AB>C@,DE@,FGH@^", new int[] { 2, 6, 10, 14, 34 }, |
256 |
new int[] { 0, 2, 5, 7, 13 }); |
257 |
doTest1("testFullToLean #32 - ", ">@32ABC@,DE@,FGH@^", "32ABC,DE,FGH", |
258 |
"32ABC@,DE@,FGH", new int[] { 0, 4, 8, 12, 32 }, new int[] { 0, |
259 |
4, 6, 8, 12 }, "32ABC,DE,FGH", ">@32ABC@,DE@,FGH@^", |
260 |
new int[] { 2, 6, 10, 14, 34 }, new int[] { 0, 2, 5, 7, 12 }); |
261 |
doTest1("testFullToLean #33 - ", "@33ABC@,DE@,FGH@^", "33ABC,DE,FGH", |
262 |
"33ABC@,DE@,FGH", new int[] { 0, 4, 8, 12, 32 }, new int[] { 0, |
263 |
4, 6, 8, 12 }, "33ABC,DE,FGH", ">@33ABC@,DE@,FGH@^", |
264 |
new int[] { 2, 6, 10, 14, 34 }, new int[] { 0, 2, 5, 7, 12 }); |
265 |
doTest1("testFullToLean #34 - ", ">@34ABC@,DE@,FGH@", "34ABC,DE,FGH", |
266 |
"34ABC@,DE@,FGH", new int[] { 0, 4, 8, 12, 32 }, new int[] { 0, |
267 |
4, 6, 8, 12 }, "34ABC,DE,FGH", ">@34ABC@,DE@,FGH@^", |
268 |
new int[] { 2, 6, 10, 14, 34 }, new int[] { 0, 2, 5, 7, 12 }); |
269 |
doTest1("testFullToLean #35 - ", "35ABC@@DE@@@GH@", "35ABC@DE@GH", |
270 |
"35ABC@DE@GH", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, |
271 |
7, 10, 11 }, "35ABC@DE@GH", ">@35ABC@DE@GH@^", |
272 |
new int[] { 2, 6, 9, 12, 32 }, new int[] { 0, 2, 5, 8, 11 }); |
273 |
doTest1("testFullToLean #36 - ", "36ABC@@DE@@@@@@", "36ABC@DE", |
274 |
"36ABC@DE", new int[] { 0, 4, 7, 10, 30 }, new int[] { 0, 4, 7, |
275 |
8, 8 }, "36ABC@DE", ">@36ABC@DE@^", new int[] { 2, 6, |
276 |
9, 12, 32 }, new int[] { 0, 2, 5, 8, 8 }); |
277 |
doTest1("testFullToLean #37 - ", ">>>@@@@@^^^", "", "", new int[] { 0, |
278 |
4, 7, 10, 30 }, new int[] { 0, 0, 0, 0, 0 }, "", "", new int[] { |
279 |
0, 4, 7, 10, 30 }, new int[] { 0, 0, 0, 0, 0 }); |
280 |
|
281 |
// test fullToLeanText with initial state |
282 |
doTest2("testFullToLean #38 - "); |
283 |
} |
284 |
} |