Lines 11-34
Link Here
|
11 |
|
11 |
|
12 |
package org.eclipse.equinox.bidi.internal.tests; |
12 |
package org.eclipse.equinox.bidi.internal.tests; |
13 |
|
13 |
|
14 |
import org.eclipse.equinox.bidi.STextDirection; |
|
|
15 |
import org.eclipse.equinox.bidi.STextTypeHandlerFactory; |
14 |
import org.eclipse.equinox.bidi.STextTypeHandlerFactory; |
16 |
import org.eclipse.equinox.bidi.advanced.*; |
15 |
import org.eclipse.equinox.bidi.advanced.*; |
|
|
16 |
import org.eclipse.equinox.bidi.custom.STextCharTypes; |
17 |
import org.eclipse.equinox.bidi.custom.STextTypeHandler; |
17 |
|
18 |
|
18 |
/** |
19 |
/** |
19 |
* Tests most public methods of BidiComplexEngine |
20 |
* Tests most public methods of BidiComplexEngine |
20 |
*/ |
21 |
*/ |
21 |
public class STextMethodsTest extends STextTestBase { |
22 |
public class STextMethodsTest extends STextTestBase { |
22 |
|
23 |
|
23 |
final static int LTR = STextDirection.DIR_LTR; |
24 |
private final static int LTR = ISTextExpert.DIR_LTR; |
24 |
final static int RTL = STextDirection.DIR_RTL; |
25 |
private final static int RTL = ISTextExpert.DIR_RTL; |
25 |
final static STextEnvironment envLTR = new STextEnvironment(null, false, STextEnvironment.ORIENT_LTR); |
26 |
private final static STextEnvironment envLTR = new STextEnvironment(null, false, STextEnvironment.ORIENT_LTR); |
26 |
final static STextEnvironment envRTL = new STextEnvironment(null, false, STextEnvironment.ORIENT_RTL); |
27 |
private final static STextEnvironment envRTL = new STextEnvironment(null, false, STextEnvironment.ORIENT_RTL); |
27 |
final static STextEnvironment envRTLMIR = new STextEnvironment(null, true, STextEnvironment.ORIENT_RTL); |
28 |
private final static STextEnvironment envRTLMIR = new STextEnvironment(null, true, STextEnvironment.ORIENT_RTL); |
28 |
final static STextEnvironment envIGN = new STextEnvironment(null, false, STextEnvironment.ORIENT_IGNORE); |
29 |
private final static STextEnvironment envIGN = new STextEnvironment(null, false, STextEnvironment.ORIENT_IGNORE); |
29 |
final static STextEnvironment envCLR = new STextEnvironment(null, false, STextEnvironment.ORIENT_CONTEXTUAL_LTR); |
30 |
private final static STextEnvironment envCLR = new STextEnvironment(null, false, STextEnvironment.ORIENT_CONTEXTUAL_LTR); |
30 |
final static STextEnvironment envCRL = new STextEnvironment(null, false, STextEnvironment.ORIENT_CONTEXTUAL_RTL); |
31 |
private final static STextEnvironment envCRL = new STextEnvironment(null, false, STextEnvironment.ORIENT_CONTEXTUAL_RTL); |
31 |
final static STextEnvironment envERR = new STextEnvironment(null, false, 9999); |
32 |
private final static STextEnvironment envERR = new STextEnvironment(null, false, 9999); |
|
|
33 |
private final static TestHandlerMyComma testMyCommaLL = new TestHandlerMyComma(LTR, LTR); |
34 |
private final static TestHandlerMyComma testMyCommaRR = new TestHandlerMyComma(RTL, RTL); |
35 |
private final static TestHandlerMyComma testMyCommaRL = new TestHandlerMyComma(RTL, LTR); |
36 |
|
37 |
private static class TestHandlerMyComma extends STextTypeHandler { |
38 |
|
39 |
private final static byte AL = Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC; |
40 |
|
41 |
final int dirArabic; |
42 |
final int dirHebrew; |
43 |
|
44 |
public TestHandlerMyComma(int dirArabic, int dirHebrew) { |
45 |
this.dirArabic = dirArabic; |
46 |
this.dirHebrew = dirHebrew; |
47 |
} |
48 |
|
49 |
public String getSeparators(ISTextExpert expert) { |
50 |
return ","; //$NON-NLS-1$ |
51 |
} |
52 |
|
53 |
public boolean skipProcessing(ISTextExpert expert, String text, STextCharTypes charTypes) { |
54 |
byte charType = charTypes.getBidiTypeAt(0); |
55 |
if (charType == AL) |
56 |
return true; |
57 |
return false; |
58 |
} |
59 |
|
60 |
public int getDirection(ISTextExpert expert, String text) { |
61 |
return getDirection(expert, text, new STextCharTypes(expert, text)); |
62 |
} |
63 |
|
64 |
public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes) { |
65 |
for (int i = 0; i < text.length(); i++) { |
66 |
byte charType = charTypes.getBidiTypeAt(i); |
67 |
if (charType == AL) |
68 |
return dirArabic; |
69 |
} |
70 |
return dirHebrew; |
71 |
} |
72 |
} |
32 |
|
73 |
|
33 |
private void doTestTools() { |
74 |
private void doTestTools() { |
34 |
|
75 |
|
Lines 47-53
Link Here
|
47 |
|
88 |
|
48 |
private void doTestState() { |
89 |
private void doTestState() { |
49 |
String data, lean, full, model; |
90 |
String data, lean, full, model; |
50 |
ISTextExpert expert = STextExpertFactory.getPrivateExpert(STextTypeHandlerFactory.JAVA); |
91 |
ISTextExpert expert = STextExpertFactory.getStatefulExpert(STextTypeHandlerFactory.JAVA); |
51 |
|
92 |
|
52 |
data = "A=B+C;/* D=E+F;"; |
93 |
data = "A=B+C;/* D=E+F;"; |
53 |
lean = toUT16(data); |
94 |
lean = toUT16(data); |
Lines 88-99
Link Here
|
88 |
assertEquals("orient #4", STextEnvironment.ORIENT_UNKNOWN, orient); |
129 |
assertEquals("orient #4", STextEnvironment.ORIENT_UNKNOWN, orient); |
89 |
} |
130 |
} |
90 |
|
131 |
|
91 |
private void doTestOrient(String handlerDefID, String label, String data, String resLTR, String resRTL, String resCon) { |
132 |
private void doTestOrient(STextTypeHandler handler, String label, String data, String resLTR, String resRTL, String resCon) { |
92 |
String full, lean; |
133 |
String full, lean; |
93 |
|
134 |
|
94 |
ISTextExpert expertLTR = STextExpertFactory.getExpert(handlerDefID, envLTR); |
135 |
ISTextExpert expertLTR = STextExpertFactory.getExpert(handler, envLTR); |
95 |
ISTextExpert expertRTL = STextExpertFactory.getExpert(handlerDefID, envRTL); |
136 |
ISTextExpert expertRTL = STextExpertFactory.getExpert(handler, envRTL); |
96 |
ISTextExpert expertCRL = STextExpertFactory.getExpert(handlerDefID, envCRL); |
137 |
ISTextExpert expertCRL = STextExpertFactory.getExpert(handler, envCRL); |
97 |
|
138 |
|
98 |
lean = toUT16(data); |
139 |
lean = toUT16(data); |
99 |
full = expertLTR.leanToFullText(lean); |
140 |
full = expertLTR.leanToFullText(lean); |
Lines 105-117
Link Here
|
105 |
} |
146 |
} |
106 |
|
147 |
|
107 |
private void doTestSkipProcessing() { |
148 |
private void doTestSkipProcessing() { |
108 |
doTestOrient("test.MyCommaLL", "Skip #1 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF"); |
149 |
doTestOrient(testMyCommaLL, "Skip #1 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF"); |
109 |
doTestOrient("test.MyCommaLL", "Skip #2 ", "#CD,EF", "#CD,EF", ">@#CD,EF@^", "@#CD,EF"); |
150 |
doTestOrient(testMyCommaLL, "Skip #2 ", "#CD,EF", "#CD,EF", ">@#CD,EF@^", "@#CD,EF"); |
110 |
} |
151 |
} |
111 |
|
152 |
|
112 |
private void doTestLeanOffsets() { |
153 |
private void doTestLeanOffsets() { |
113 |
String lean, data, label; |
154 |
String lean, data, label; |
114 |
ISTextExpert expert = STextExpertFactory.getPrivateExpert(STextTypeHandlerFactory.JAVA); |
155 |
ISTextExpert expert = STextExpertFactory.getStatefulExpert(STextTypeHandlerFactory.JAVA); |
115 |
|
156 |
|
116 |
int[] offsets; |
157 |
int[] offsets; |
117 |
int[] model; |
158 |
int[] model; |
Lines 164-180
Link Here
|
164 |
private void doTestDirection() { |
205 |
private void doTestDirection() { |
165 |
String data, lean, full, model; |
206 |
String data, lean, full, model; |
166 |
int dirA, dirH; |
207 |
int dirA, dirH; |
167 |
ISTextExpert expertRL = STextExpertFactory.getExpert("test.MyCommaRL"); |
208 |
ISTextExpert expertRL = STextExpertFactory.getExpert(testMyCommaRL, envLTR); |
168 |
dirA = expertRL.getTextDirection(toUT16("###")); |
209 |
dirA = expertRL.getTextDirection(toUT16("###")); |
169 |
dirH = expertRL.getTextDirection(toUT16("ABC")); |
210 |
dirH = expertRL.getTextDirection(toUT16("ABC")); |
170 |
assertTrue("TestDirection #1", dirA == RTL && dirH == LTR); |
211 |
assertTrue("TestDirection #1", dirA == RTL && dirH == LTR); |
171 |
|
212 |
|
172 |
ISTextExpert expertRR = STextExpertFactory.getExpert("test.MyCommaRR"); |
213 |
ISTextExpert expertRR = STextExpertFactory.getExpert(testMyCommaRR, envLTR); |
173 |
dirA = expertRR.getTextDirection(toUT16("###")); |
214 |
dirA = expertRR.getTextDirection(toUT16("###")); |
174 |
dirH = expertRR.getTextDirection(toUT16("ABC")); |
215 |
dirH = expertRR.getTextDirection(toUT16("ABC")); |
175 |
assertTrue("TestDirection #2", dirA == RTL && dirH == RTL); |
216 |
assertTrue("TestDirection #2", dirA == RTL && dirH == RTL); |
176 |
|
217 |
|
177 |
ISTextExpert expertLL = STextExpertFactory.getExpert("test.MyCommaLL"); |
218 |
ISTextExpert expertLL = STextExpertFactory.getExpert(testMyCommaLL, envLTR); |
178 |
lean = toUT16("ABC,#DEF,HOST,com"); |
219 |
lean = toUT16("ABC,#DEF,HOST,com"); |
179 |
full = expertLL.leanToFullText(lean); |
220 |
full = expertLL.leanToFullText(lean); |
180 |
assertEquals("TestDirection #9 full", "ABC@,#DEF@,HOST,com", toPseudo(full)); |
221 |
assertEquals("TestDirection #9 full", "ABC@,#DEF@,HOST,com", toPseudo(full)); |
Lines 185-191
Link Here
|
185 |
assertEquals("TestDirection #10 full", "ABC@,DEF@,HOST,com", toPseudo(full)); |
226 |
assertEquals("TestDirection #10 full", "ABC@,DEF@,HOST,com", toPseudo(full)); |
186 |
|
227 |
|
187 |
STextEnvironment environment = new STextEnvironment(null, true, STextEnvironment.ORIENT_LTR); |
228 |
STextEnvironment environment = new STextEnvironment(null, true, STextEnvironment.ORIENT_LTR); |
188 |
ISTextExpert expert = STextExpertFactory.getExpert("test.MyCommaRL", environment); |
229 |
ISTextExpert expert = STextExpertFactory.getExpert(testMyCommaRL, environment); |
189 |
dirA = expert.getTextDirection(toUT16("###")); |
230 |
dirA = expert.getTextDirection(toUT16("###")); |
190 |
dirH = expert.getTextDirection(toUT16("ABC")); |
231 |
dirH = expert.getTextDirection(toUT16("ABC")); |
191 |
assertTrue("TestDirection #10.5", dirA == RTL && dirH == LTR); |
232 |
assertTrue("TestDirection #10.5", dirA == RTL && dirH == LTR); |
Lines 227-233
Link Here
|
227 |
|
268 |
|
228 |
data = "ABc,|#DEF,HOST,com"; |
269 |
data = "ABc,|#DEF,HOST,com"; |
229 |
lean = toUT16(data); |
270 |
lean = toUT16(data); |
230 |
expert = STextExpertFactory.getExpert("test.MyCommaRL", envRTLMIR); |
271 |
expert = STextExpertFactory.getExpert(testMyCommaRL, envRTLMIR); |
231 |
full = expert.leanToFullText(lean); |
272 |
full = expert.leanToFullText(lean); |
232 |
model = "ABc,|#DEF,HOST,com"; |
273 |
model = "ABc,|#DEF,HOST,com"; |
233 |
assertEquals("TestDirection #17 full", model, toPseudo(full)); |
274 |
assertEquals("TestDirection #17 full", model, toPseudo(full)); |
Lines 243-257
Link Here
|
243 |
|
284 |
|
244 |
doTestOrientation(); |
285 |
doTestOrientation(); |
245 |
|
286 |
|
246 |
doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #1 ", "", "", "", ""); |
287 |
STextTypeHandler commaHandler = STextTypeHandlerFactory.getHandler(STextTypeHandlerFactory.COMMA_DELIMITED); |
247 |
doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #2 ", "abc", "abc", ">@abc@^", "abc"); |
288 |
doTestOrient(commaHandler, "Methods #1 ", "", "", "", ""); |
248 |
doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #3 ", "ABC", "ABC", ">@ABC@^", "@ABC"); |
289 |
doTestOrient(commaHandler, "Methods #2 ", "abc", "abc", ">@abc@^", "abc"); |
249 |
doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #4 ", "bcd,ef", "bcd,ef", ">@bcd,ef@^", "bcd,ef"); |
290 |
doTestOrient(commaHandler, "Methods #3 ", "ABC", "ABC", ">@ABC@^", "@ABC"); |
250 |
doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #5 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF"); |
291 |
doTestOrient(commaHandler, "Methods #4 ", "bcd,ef", "bcd,ef", ">@bcd,ef@^", "bcd,ef"); |
251 |
doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #6 ", "cde,FG", "cde,FG", ">@cde,FG@^", "cde,FG"); |
292 |
doTestOrient(commaHandler, "Methods #5 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF"); |
252 |
doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #7 ", "CDE,fg", "CDE,fg", ">@CDE,fg@^", "@CDE,fg"); |
293 |
doTestOrient(commaHandler, "Methods #6 ", "cde,FG", "cde,FG", ">@cde,FG@^", "cde,FG"); |
253 |
doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #8 ", "12..def,GH", "12..def,GH", ">@12..def,GH@^", "12..def,GH"); |
294 |
doTestOrient(commaHandler, "Methods #7 ", "CDE,fg", "CDE,fg", ">@CDE,fg@^", "@CDE,fg"); |
254 |
doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #9 ", "34..DEF,gh", "34..DEF,gh", ">@34..DEF,gh@^", "@34..DEF,gh"); |
295 |
doTestOrient(commaHandler, "Methods #8 ", "12..def,GH", "12..def,GH", ">@12..def,GH@^", "12..def,GH"); |
|
|
296 |
doTestOrient(commaHandler, "Methods #9 ", "34..DEF,gh", "34..DEF,gh", ">@34..DEF,gh@^", "@34..DEF,gh"); |
255 |
|
297 |
|
256 |
doTestSkipProcessing(); |
298 |
doTestSkipProcessing(); |
257 |
|
299 |
|