Lines 11-438
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.complexp.IComplExpProcessor; |
14 |
import org.eclipse.equinox.bidi.complexp.*; |
15 |
import org.eclipse.equinox.bidi.complexp.IBiDiProcessor; |
|
|
16 |
import org.eclipse.equinox.bidi.complexp.StringProcessor; |
17 |
import org.eclipse.equinox.bidi.complexp.ComplExpUtil; |
18 |
|
15 |
|
19 |
/** |
16 |
/** |
20 |
* Tests most public methods of ComplExpBasic |
17 |
* Tests most public methods of CxpHelper |
21 |
*/ |
18 |
*/ |
22 |
|
19 |
|
23 |
public class MethodsTest extends ComplExpTestBase { |
20 |
public class MethodsTest extends CxpTestBase { |
24 |
|
21 |
|
25 |
final static int LTR = IComplExpProcessor.DIRECTION_LTR; |
22 |
final static int LTR = CxpFeatures.DIR_LTR; |
26 |
final static int RTL = IComplExpProcessor.DIRECTION_RTL; |
23 |
final static int RTL = CxpFeatures.DIR_RTL; |
27 |
|
24 |
final static CxpEnv envLTR = new CxpEnv(null, false, CxpEnv.ORIENT_LTR); |
28 |
IComplExpProcessor processor; |
25 |
final static CxpEnv envRTL = new CxpEnv(null, false, CxpEnv.ORIENT_RTL); |
29 |
|
26 |
final static CxpEnv envRTLMIR = new CxpEnv(null, true, CxpEnv.ORIENT_RTL); |
30 |
private void doTestTools() { |
27 |
final static CxpEnv envIGN = new CxpEnv(null, false, CxpEnv.ORIENT_IGNORE); |
31 |
|
28 |
final static CxpEnv envCLR = new CxpEnv(null, false, CxpEnv.ORIENT_CONTEXTUAL_LTR); |
32 |
// This method tests utility methods used by the JUnits |
29 |
final static CxpEnv envCRL = new CxpEnv(null, false, CxpEnv.ORIENT_CONTEXTUAL_RTL); |
33 |
String data = "56789ABCDEFGHIJKLMNOPQRSTUVWXYZ~#@&><^|`"; |
30 |
final static CxpEnv envERR = new CxpEnv(null, false, 9999); |
34 |
String text = toUT16(data); |
31 |
|
35 |
String dat2 = toPseudo(text); |
32 |
CxpHelper helper; |
36 |
assertEquals(data, dat2); |
33 |
|
37 |
|
34 |
private void doTestTools() { |
38 |
text = toPseudo(data); |
35 |
|
39 |
assertEquals("56789abcdefghijklmnopqrstuvwxyz~#@&><^|`", text); |
36 |
// This method tests utility methods used by the JUnits |
40 |
|
37 |
String data = "56789ABCDEFGHIJKLMNOPQRSTUVWXYZ~#@&><^|`"; |
41 |
int[] arA = new int[] { 1, 2 }; |
38 |
String text = toUT16(data); |
42 |
int[] arB = new int[] { 3, 4, 5 }; |
39 |
String dat2 = toPseudo(text); |
43 |
assertFalse(arrays_equal(arA, arB)); |
40 |
assertEquals(data, dat2); |
44 |
|
41 |
|
45 |
assertTrue(arrays_equal(arA, arA)); |
42 |
text = toPseudo(data); |
46 |
|
43 |
assertEquals("56789abcdefghijklmnopqrstuvwxyz~#@&><^|`", text); |
47 |
arB = new int[] { 3, 4 }; |
44 |
|
48 |
assertFalse(arrays_equal(arA, arB)); |
45 |
int[] arA = new int[] { 1, 2 }; |
49 |
|
46 |
int[] arB = new int[] { 3, 4, 5 }; |
50 |
int[][] ar2A = new int[][] { { 1 }, { 1, 2 }, { 1, 2, 3 } }; |
47 |
assertFalse(arrays_equal(arA, arB)); |
51 |
int[][] ar2B = new int[][] { { 1 }, { 1, 2 } }; |
48 |
|
52 |
assertTrue(arrays2_equal(ar2A, ar2A)); |
49 |
assertTrue(arrays_equal(arA, arA)); |
53 |
|
50 |
|
54 |
assertFalse(arrays2_equal(ar2A, ar2B)); |
51 |
arB = new int[] { 3, 4 }; |
55 |
|
52 |
assertFalse(arrays_equal(arA, arB)); |
56 |
ar2B = new int[][] { { 1 }, { 1, 2 }, { 1, 2, 3, 4 } }; |
53 |
|
57 |
assertFalse(arrays2_equal(ar2A, ar2B)); |
54 |
text = array_display(null); |
58 |
|
55 |
assertEquals("null", text); |
59 |
ar2B = new int[][] { { 1 }, { 1, 2 }, { 1, 2, 4 } }; |
56 |
} |
60 |
assertFalse(arrays2_equal(ar2A, ar2B)); |
57 |
|
61 |
|
58 |
private void doTestState() { |
62 |
text = array_display(null); |
59 |
String data, lean, full, model; |
63 |
assertEquals("null", text); |
60 |
int state; |
64 |
|
61 |
|
65 |
text = array2_display(null); |
62 |
data = "A=B+C;/* D=E+F;"; |
66 |
assertEquals("null", text); |
63 |
lean = toUT16(data); |
67 |
} |
64 |
full = helper.leanToFullText(lean); |
68 |
|
65 |
model = "A@=B@+C@;/* D=E+F;"; |
69 |
private void doTestState() { |
66 |
assertEquals("full1", model, toPseudo(full)); |
70 |
String data, lean, full, model; |
67 |
state = helper.getFinalState(); |
71 |
int state; |
68 |
data = "A=B+C; D=E+F;"; |
72 |
|
69 |
lean = toUT16(data); |
73 |
data = "A=B+C;/* D=E+F;"; |
70 |
full = helper.leanToFullText(lean, state); |
74 |
lean = toUT16(data); |
71 |
model = "A=B+C; D=E+F;"; |
75 |
full = processor.leanToFullText(lean); |
72 |
assertEquals("full2", model, toPseudo(full)); |
76 |
model = "A@=B@+C@;/* D=E+F;"; |
73 |
state = helper.getFinalState(); |
77 |
assertEquals("full1", model, toPseudo(full)); |
74 |
data = "A=B+C;*/ D=E+F;"; |
78 |
state = processor.getFinalState(); |
75 |
lean = toUT16(data); |
79 |
data = "A=B+C; D=E+F;"; |
76 |
full = helper.leanToFullText(lean, state); |
80 |
lean = toUT16(data); |
77 |
model = "A=B+C;*/@ D@=E@+F;"; |
81 |
full = processor.leanToFullText(lean, state); |
78 |
assertEquals("full3", model, toPseudo(full)); |
82 |
model = "A=B+C; D=E+F;"; |
79 |
} |
83 |
assertEquals("full2", model, toPseudo(full)); |
80 |
|
84 |
state = processor.getFinalState(); |
81 |
private void doTestOrientation() { |
85 |
data = "A=B+C;*/ D=E+F;"; |
82 |
int orient; |
86 |
lean = toUT16(data); |
83 |
|
87 |
full = processor.leanToFullText(lean, state); |
84 |
helper = new CxpHelper(IProcessorTypes.COMMA_DELIMITED); |
88 |
model = "A=B+C;*/@ D@=E@+F;"; |
85 |
orient = helper.getEnvironment().orientation; |
89 |
assertEquals("full3", model, toPseudo(full)); |
86 |
assertEquals("orient #1", CxpEnv.ORIENT_LTR, orient); |
90 |
} |
87 |
|
91 |
|
88 |
helper.setEnvironment(envIGN); |
92 |
private void doTestOrientation() { |
89 |
orient = helper.getEnvironment().orientation; |
93 |
int orient; |
90 |
assertEquals("orient #2", CxpEnv.ORIENT_IGNORE, orient); |
94 |
|
91 |
|
95 |
processor = StringProcessor |
92 |
helper.setEnvironment(envCRL); |
96 |
.getProcessor(IBiDiProcessor.COMMA_DELIMITED); |
93 |
orient = helper.getEnvironment().orientation; |
97 |
orient = processor.recallOrientation(); |
94 |
helper.leanToFullText("--!**"); |
98 |
// TBD: the following test cannot succeed with the current |
95 |
assertEquals("orient #3", CxpEnv.ORIENT_CONTEXTUAL_RTL, orient); |
99 |
// implementation. |
96 |
|
100 |
// it will need allocating separate data for each processor use. |
97 |
helper.setEnvironment(envERR); |
101 |
// assertEquals("orient #1", IComplExpProcessor.ORIENT_LTR, orient); |
98 |
orient = helper.getEnvironment().orientation; |
102 |
|
99 |
helper.leanToFullText("--!**"); |
103 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_IGNORE); |
100 |
assertEquals("orient #4", CxpEnv.ORIENT_UNKNOWN, orient); |
104 |
orient = processor.recallOrientation(); |
101 |
} |
105 |
assertEquals("orient #2", IComplExpProcessor.ORIENT_IGNORE, orient); |
102 |
|
106 |
|
103 |
private void doTestOrient(CxpFeatures f, String label, String data, String resLTR, |
107 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_CONTEXTUAL_RTL); |
104 |
String resRTL, String resCon) { |
108 |
orient = processor.recallOrientation(); |
105 |
String full, lean; |
109 |
processor.leanToFullText("--!**"); |
106 |
|
110 |
assertEquals("orient #3", IComplExpProcessor.ORIENT_CONTEXTUAL_RTL, |
107 |
lean = toUT16(data); |
111 |
orient); |
108 |
helper.setEnvironment(envLTR); |
112 |
|
109 |
helper.setFeatures(f); |
113 |
processor.assumeOrientation(9999); |
110 |
full = helper.leanToFullText(lean); |
114 |
orient = processor.recallOrientation(); |
111 |
assertEquals(label + "LTR full", resLTR, toPseudo(full)); |
115 |
processor.leanToFullText("--!**"); |
112 |
helper.setEnvironment(envRTL); |
116 |
assertEquals("orient #4", IComplExpProcessor.ORIENT_UNKNOWN, orient); |
113 |
helper.setFeatures(f); |
117 |
} |
114 |
full = helper.leanToFullText(lean); |
118 |
|
115 |
assertEquals("label + RTL full", resRTL, toPseudo(full)); |
119 |
private void doTestOrient(String label, String data, String resLTR, |
116 |
helper.setEnvironment(envCRL); |
120 |
String resRTL, String resCon) { |
117 |
helper.setFeatures(f); |
121 |
String full, lean; |
118 |
full = helper.leanToFullText(lean); |
122 |
|
119 |
assertEquals(label + "CON full", resCon, toPseudo(full)); |
123 |
lean = toUT16(data); |
120 |
} |
124 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_LTR); |
121 |
|
125 |
full = processor.leanToFullText(lean); |
122 |
private void doTestScripts() { |
126 |
assertEquals(label + "LTR full", resLTR, toPseudo(full)); |
123 |
CxpFeatures f2, f1 = helper.getFeatures(); |
127 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_RTL); |
124 |
boolean flag; |
128 |
full = processor.leanToFullText(lean); |
125 |
flag = f1.ignoreArabic; |
129 |
assertEquals("label + RTL full", resRTL, toPseudo(full)); |
126 |
assertFalse("Ignores Arabic 1", flag); |
130 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_CONTEXTUAL_RTL); |
127 |
flag = f1.ignoreHebrew; |
131 |
full = processor.leanToFullText(lean); |
128 |
assertFalse("Ignores Hebrew 1", flag); |
132 |
assertEquals(label + "CON full", resCon, toPseudo(full)); |
129 |
|
133 |
} |
130 |
f2 = new CxpFeatures(f1.operators, 0, -1, -1, true, true); |
134 |
|
131 |
flag = f2.ignoreArabic; |
135 |
private void doTestScripts() { |
132 |
assertTrue("Ignores Arabic 2", flag); |
136 |
boolean flag; |
133 |
flag = f2.ignoreHebrew; |
137 |
flag = processor.handlesArabicScript(); |
134 |
assertTrue("Ignores Hebrew 2", flag); |
138 |
assertTrue("Handles Arabic 1", flag); |
135 |
doTestOrient(f2, "Scripts #1 ", "BCD,EF", "BCD,EF", ">@BCD,EF@^", "@BCD,EF"); |
139 |
flag = processor.handlesHebrewScript(); |
136 |
f2 = new CxpFeatures(f1.operators, 0, -1, -1, false, true); |
140 |
assertTrue("Handles Hebrew 1", flag); |
137 |
flag = f2.ignoreArabic; |
141 |
|
138 |
assertFalse("Ignores Arabic 3", flag); |
142 |
processor.selectBidiScript(false, false); |
139 |
flag = f2.ignoreHebrew; |
143 |
flag = processor.handlesArabicScript(); |
140 |
assertTrue("Ignores Hebrew 3", flag); |
144 |
assertFalse("Handles Arabic 2", flag); |
141 |
doTestOrient(f2, "Scripts #2 ", "d,EF", "d,EF", ">@d,EF@^", "d,EF"); |
145 |
flag = processor.handlesHebrewScript(); |
142 |
doTestOrient(f2, "Scripts #3 ", "#,eF", "#,eF", ">@#,eF@^", "@#,eF"); |
146 |
assertFalse("Handles Hebrew 2", flag); |
143 |
doTestOrient(f2, "Scripts #4 ", "#,12", "#@,12", ">@#@,12@^", "@#@,12"); |
147 |
doTestOrient("Scripts #1 ", "BCD,EF", "BCD,EF", ">@BCD,EF@^", "@BCD,EF"); |
144 |
doTestOrient(f2, "Scripts #5 ", "#,##", "#@,##", ">@#@,##@^", "@#@,##"); |
148 |
processor.selectBidiScript(true, false); |
145 |
doTestOrient(f2, "Scripts #6 ", "#,89", "#@,89", ">@#@,89@^", "@#@,89"); |
149 |
flag = processor.handlesArabicScript(); |
146 |
doTestOrient(f2, "Scripts #7 ", "#,ef", "#,ef", ">@#,ef@^", "@#,ef"); |
150 |
assertTrue("Handles Arabic 3", flag); |
147 |
doTestOrient(f2, "Scripts #8 ", "#,", "#,", ">@#,@^", "@#,"); |
151 |
flag = processor.handlesHebrewScript(); |
148 |
doTestOrient(f2, "Scripts #9 ", "9,ef", "9,ef", ">@9,ef@^", "9,ef"); |
152 |
assertFalse("Handles Hebrew 3", flag); |
149 |
doTestOrient(f2, "Scripts #10 ", "9,##", "9@,##", ">@9@,##@^", "9@,##"); |
153 |
doTestOrient("Scripts #2 ", "d,EF", "d,EF", ">@d,EF@^", "d,EF"); |
150 |
doTestOrient(f2, "Scripts #11 ", "7,89", "7@,89", ">@7@,89@^", "7@,89"); |
154 |
doTestOrient("Scripts #3 ", "#,eF", "#,eF", ">@#,eF@^", "@#,eF"); |
151 |
doTestOrient(f2, "Scripts #12 ", "7,EF", "7,EF", ">@7,EF@^", "@7,EF"); |
155 |
doTestOrient("Scripts #4 ", "#,12", "#@,12", ">@#@,12@^", "@#@,12"); |
152 |
doTestOrient(f2, "Scripts #13 ", "BCD,EF", "BCD,EF", ">@BCD,EF@^", |
156 |
doTestOrient("Scripts #5 ", "#,##", "#@,##", ">@#@,##@^", "@#@,##"); |
153 |
"@BCD,EF"); |
157 |
doTestOrient("Scripts #6 ", "#,89", "#@,89", ">@#@,89@^", "@#@,89"); |
154 |
|
158 |
doTestOrient("Scripts #7 ", "#,ef", "#,ef", ">@#,ef@^", "@#,ef"); |
155 |
f2 = new CxpFeatures(f1.operators, 0, -1, -1, true, false); |
159 |
doTestOrient("Scripts #8 ", "#,", "#,", ">@#,@^", "@#,"); |
156 |
flag = f2.ignoreArabic; |
160 |
doTestOrient("Scripts #9 ", "9,ef", "9,ef", ">@9,ef@^", "9,ef"); |
157 |
assertTrue("Ignores Arabic 4", flag); |
161 |
doTestOrient("Scripts #10 ", "9,##", "9@,##", ">@9@,##@^", "9@,##"); |
158 |
flag = f2.ignoreHebrew; |
162 |
doTestOrient("Scripts #11 ", "7,89", "7@,89", ">@7@,89@^", "7@,89"); |
159 |
assertFalse("Ignores Hebrew 4", flag); |
163 |
doTestOrient("Scripts #12 ", "7,EF", "7,EF", ">@7,EF@^", "@7,EF"); |
160 |
doTestOrient(f2, "Scripts #14 ", "BCd,EF", "BCd,EF", ">@BCd,EF@^", |
164 |
doTestOrient("Scripts #13 ", "BCD,EF", "BCD,EF", ">@BCD,EF@^", |
161 |
"@BCd,EF"); |
165 |
"@BCD,EF"); |
162 |
doTestOrient(f2, "Scripts #15 ", "BCD,eF", "BCD,eF", ">@BCD,eF@^", |
166 |
|
163 |
"@BCD,eF"); |
167 |
processor.selectBidiScript(false, true); |
164 |
doTestOrient(f2, "Scripts #16 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", |
168 |
flag = processor.handlesArabicScript(); |
165 |
"@BCD@,EF"); |
169 |
assertFalse("Handles Arabic 4", flag); |
166 |
doTestOrient(f2, "Scripts #17 ", "BCD,12", "BCD@,12", ">@BCD@,12@^", |
170 |
flag = processor.handlesHebrewScript(); |
167 |
"@BCD@,12"); |
171 |
assertTrue("Handles Hebrew 4", flag); |
168 |
doTestOrient(f2, "Scripts #18 ", "BCD,", "BCD,", ">@BCD,@^", "@BCD,"); |
172 |
doTestOrient("Scripts #14 ", "BCd,EF", "BCd,EF", ">@BCd,EF@^", |
169 |
|
173 |
"@BCd,EF"); |
170 |
f2 = new CxpFeatures(f1.operators, 0, -1, -1, false, false); |
174 |
doTestOrient("Scripts #15 ", "BCD,eF", "BCD,eF", ">@BCD,eF@^", |
171 |
doTestOrient(f2, "Scripts #19 ", "123,45|67", "123,45|67", ">@123,45|67@^", |
175 |
"@BCD,eF"); |
172 |
"@123,45|67"); |
176 |
doTestOrient("Scripts #16 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", |
173 |
doTestOrient(f2, "Scripts #20 ", "5,e", "5,e", ">@5,e@^", "5,e"); |
177 |
"@BCD@,EF"); |
174 |
doTestOrient(f2, "Scripts #21 ", "5,#", "5@,#", ">@5@,#@^", "5@,#"); |
178 |
doTestOrient("Scripts #17 ", "BCD,12", "BCD@,12", ">@BCD@,12@^", |
175 |
doTestOrient(f2, "Scripts #22 ", "5,6", "5@,6", ">@5@,6@^", "5@,6"); |
179 |
"@BCD@,12"); |
176 |
doTestOrient(f2, "Scripts #23 ", "5,D", "5@,D", ">@5@,D@^", "5@,D"); |
180 |
doTestOrient("Scripts #18 ", "BCD,", "BCD,", ">@BCD,@^", "@BCD,"); |
177 |
doTestOrient(f2, "Scripts #24 ", "5,--", "5,--", ">@5,--@^", "@5,--"); |
181 |
|
178 |
} |
182 |
processor.selectBidiScript(true, true); |
179 |
|
183 |
doTestOrient("Scripts #19 ", "123,45|67", "123,45|67", ">@123,45|67@^", |
180 |
private void doTestLeanOffsets() { |
184 |
"@123,45|67"); |
181 |
String lean, data, label; |
185 |
doTestOrient("Scripts #20 ", "5,e", "5,e", ">@5,e@^", "5,e"); |
182 |
int state; |
186 |
doTestOrient("Scripts #21 ", "5,#", "5@,#", ">@5@,#@^", "5@,#"); |
183 |
int[] offsets; |
187 |
doTestOrient("Scripts #22 ", "5,6", "5@,6", ">@5@,6@^", "5@,6"); |
184 |
int[] model; |
188 |
doTestOrient("Scripts #23 ", "5,D", "5@,D", ">@5@,D@^", "5@,D"); |
185 |
|
189 |
doTestOrient("Scripts #24 ", "5,--", "5,--", ">@5,--@^", "@5,--"); |
186 |
data = "A=B+C;/* D=E+F;"; |
190 |
} |
187 |
lean = toUT16(data); |
191 |
|
188 |
helper.leanToFullText(lean); |
192 |
private void doTestLeanOffsets() { |
189 |
offsets = helper.leanBidiCharOffsets(); |
193 |
String lean, data, label; |
190 |
model = new int[] { 1, 3, 5 }; |
194 |
int state; |
191 |
label = "leanBidiCharOffsets() #1 expected=" + array_display(model) |
195 |
int[] offsets; |
192 |
+ " result=" + array_display(offsets); |
196 |
int[] model; |
193 |
assertTrue(label, arrays_equal(model, offsets)); |
197 |
|
194 |
state = helper.getFinalState(); |
198 |
data = "A=B+C;/* D=E+F;"; |
195 |
data = "A=B+C;*/ D=E+F;"; |
199 |
lean = toUT16(data); |
196 |
lean = toUT16(data); |
200 |
offsets = processor.leanBidiCharOffsets(lean); |
197 |
helper.leanToFullText(lean, state); |
201 |
model = new int[] { 1, 3, 5 }; |
198 |
offsets = helper.leanBidiCharOffsets(); |
202 |
label = "leanBidiCharOffsets() #1 expected=" + array_display(model) |
199 |
model = new int[] { 8, 10, 12 }; |
203 |
+ " result=" + array_display(offsets); |
200 |
label = "leanBidiCharOffsets() #2 expected=" + array_display(model) |
204 |
assertTrue(label, arrays_equal(model, offsets)); |
201 |
+ " result=" + array_display(offsets); |
205 |
state = processor.getFinalState(); |
202 |
assertTrue(label, arrays_equal(model, offsets)); |
206 |
data = "A=B+C;*/ D=E+F;"; |
203 |
offsets = helper.leanBidiCharOffsets(); |
207 |
lean = toUT16(data); |
204 |
model = new int[] { 8, 10, 12 }; |
208 |
offsets = processor.leanBidiCharOffsets(lean, state); |
205 |
label = "leanBidiCharOffsets() #3 expected=" + array_display(model) |
209 |
model = new int[] { 8, 10, 12 }; |
206 |
+ " result=" + array_display(offsets); |
210 |
label = "leanBidiCharOffsets() #2 expected=" + array_display(model) |
207 |
assertTrue(label, arrays_equal(model, offsets)); |
211 |
+ " result=" + array_display(offsets); |
208 |
} |
212 |
assertTrue(label, arrays_equal(model, offsets)); |
209 |
|
213 |
offsets = processor.leanBidiCharOffsets(); |
210 |
private void doTestFullOffsets(String label, String data, int[] resLTR, |
214 |
model = new int[] { 8, 10, 12 }; |
211 |
int[] resRTL, int[] resCon) { |
215 |
label = "leanBidiCharOffsets() #3 expected=" + array_display(model) |
212 |
String full, lean, msg; |
216 |
+ " result=" + array_display(offsets); |
213 |
int[] offsets; |
217 |
assertTrue(label, arrays_equal(model, offsets)); |
214 |
|
218 |
} |
215 |
lean = toUT16(data); |
219 |
|
216 |
helper.setEnvironment(envLTR); |
220 |
private void doTestFullOffsets(String label, String data, int[] resLTR, |
217 |
full = helper.leanToFullText(lean); |
221 |
int[] resRTL, int[] resCon) { |
218 |
// the following line avoids a compiler warning about full never being |
222 |
String full, lean, msg; |
219 |
// read |
223 |
int[] offsets; |
220 |
full += ""; |
224 |
|
221 |
offsets = helper.fullBidiCharOffsets(); |
225 |
lean = toUT16(data); |
222 |
msg = label + "LTR expected=" + array_display(resLTR) + " result=" |
226 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_LTR); |
223 |
+ array_display(offsets); |
227 |
full = processor.leanToFullText(lean); |
224 |
assertTrue(msg, arrays_equal(resLTR, offsets)); |
228 |
// the following line avoids a compiler warning about full never being |
225 |
helper.setEnvironment(envRTL); |
229 |
// read |
226 |
full = helper.leanToFullText(lean); |
230 |
full += ""; |
227 |
offsets = helper.fullBidiCharOffsets(); |
231 |
offsets = processor.fullBidiCharOffsets(); |
228 |
msg = label + "RTL expected=" + array_display(resRTL) + " result=" |
232 |
msg = label + "LTR expected=" + array_display(resLTR) + " result=" |
229 |
+ array_display(offsets); |
233 |
+ array_display(offsets); |
230 |
assertTrue(msg, arrays_equal(resRTL, offsets)); |
234 |
assertTrue(msg, arrays_equal(resLTR, offsets)); |
231 |
helper.setEnvironment(envCLR); |
235 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_RTL); |
232 |
full = helper.leanToFullText(lean); |
236 |
full = processor.leanToFullText(lean); |
233 |
offsets = helper.fullBidiCharOffsets(); |
237 |
offsets = processor.fullBidiCharOffsets(); |
234 |
msg = label + "CON expected=" + array_display(resCon) + " result=" |
238 |
msg = label + "RTL expected=" + array_display(resRTL) + " result=" |
235 |
+ array_display(offsets); |
239 |
+ array_display(offsets); |
236 |
assertTrue(msg, arrays_equal(resCon, offsets)); |
240 |
assertTrue(msg, arrays_equal(resRTL, offsets)); |
237 |
} |
241 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_CONTEXTUAL_LTR); |
238 |
|
242 |
full = processor.leanToFullText(lean); |
239 |
private void doTestMirrored() { |
243 |
offsets = processor.fullBidiCharOffsets(); |
240 |
boolean mirrored; |
244 |
msg = label + "CON expected=" + array_display(resCon) + " result=" |
241 |
|
245 |
+ array_display(offsets); |
242 |
helper = new CxpHelper(IProcessorTypes.COMMA_DELIMITED); |
246 |
assertTrue(msg, arrays_equal(resCon, offsets)); |
243 |
mirrored = helper.getEnvironment().mirrored; |
247 |
} |
244 |
assertFalse("mirrored #1", mirrored); |
248 |
|
245 |
CxpEnv env = new CxpEnv(null, true, CxpEnv.ORIENT_LTR); |
249 |
private void doTestMirrored() { |
246 |
helper = new CxpHelper(IProcessorTypes.COMMA_DELIMITED, env); |
250 |
boolean mirrored; |
247 |
mirrored = helper.getEnvironment().mirrored; |
251 |
|
248 |
assertTrue("mirrored #2", mirrored); |
252 |
mirrored = ComplExpUtil.isMirroredDefault(); |
249 |
} |
253 |
assertFalse("mirrored #1", mirrored); |
250 |
|
254 |
processor = StringProcessor |
251 |
private void doTestDirection() { |
255 |
.getProcessor(IBiDiProcessor.COMMA_DELIMITED); |
252 |
String data, lean, full, model, msg; |
256 |
mirrored = processor.isMirrored(); |
253 |
|
257 |
assertFalse("mirrored #2", mirrored); |
254 |
helper = new CxpHelper(IProcessorTypes.COMMA_DELIMITED); |
258 |
ComplExpUtil.assumeMirroredDefault(true); |
255 |
CxpFeatures f1 = helper.getFeatures(); |
259 |
mirrored = ComplExpUtil.isMirroredDefault(); |
256 |
msg = "TestDirection #1"; |
260 |
assertTrue("mirrored #3", mirrored); |
257 |
assertTrue(msg, f1.dirArabic == LTR && f1.dirHebrew == LTR); |
261 |
processor = StringProcessor |
258 |
|
262 |
.getProcessor(IBiDiProcessor.COMMA_DELIMITED); |
259 |
CxpFeatures f2 = new CxpFeatures(f1.operators, 0, RTL, RTL, false, false); |
263 |
mirrored = processor.isMirrored(); |
260 |
helper.setFeatures(f2); |
264 |
// TBD: the following test cannot succeed with the current |
261 |
f1 = helper.getFeatures(); |
265 |
// implementation. |
262 |
msg = "TestDirection #2"; |
266 |
// it will need allocating separate data for each processor use. |
263 |
assertTrue(msg, f1.dirArabic == RTL && f1.dirHebrew == RTL); |
267 |
// assertTrue("mirrored #4", mirrored); |
264 |
|
268 |
processor.assumeMirrored(false); |
265 |
CxpEnv env = new CxpEnv(null, false, CxpEnv.ORIENT_LTR); |
269 |
mirrored = processor.isMirrored(); |
266 |
helper = new CxpHelper(IProcessorTypes.EMAIL, env); |
270 |
assertFalse("mirrored #5", mirrored); |
267 |
f1 = helper.getFeatures(); |
271 |
} |
268 |
msg = "TestDirection #3"; |
272 |
|
269 |
assertTrue(msg, f1.dirArabic == LTR && f1.dirHebrew == LTR); |
273 |
private void doTestDirection() { |
270 |
data = "#ABC.#DEF:HOST.com"; |
274 |
int[][] dir; |
271 |
lean = toUT16(data); |
275 |
int[][] modir; |
272 |
full = helper.leanToFullText(lean); |
276 |
String data, lean, full, model, msg; |
273 |
model = "#ABC@.#DEF@:HOST.com"; |
277 |
|
274 |
assertEquals("TestDirection #9 full", model, toPseudo(full)); |
278 |
processor = StringProcessor |
275 |
|
279 |
.getProcessor(IBiDiProcessor.COMMA_DELIMITED); |
276 |
data = "ABC.DEF:HOST.com"; |
280 |
dir = processor.getDirection(); |
277 |
lean = toUT16(data); |
281 |
modir = new int[][] { { LTR, LTR }, { LTR, LTR } }; |
278 |
full = helper.leanToFullText(lean); |
282 |
msg = "TestDirection #1 expected=" + array2_display(modir) + " result=" |
279 |
model = "ABC@.DEF@:HOST.com"; |
283 |
+ array2_display(dir); |
280 |
assertEquals("TestDirection #10 full", model, toPseudo(full)); |
284 |
assertTrue(msg, arrays2_equal(modir, dir)); |
281 |
|
285 |
|
282 |
env = new CxpEnv(null, true, CxpEnv.ORIENT_LTR); |
286 |
processor.setDirection(RTL); |
283 |
helper.setEnvironment(env); |
287 |
dir = processor.getDirection(); |
284 |
f1 = helper.getFeatures(); |
288 |
modir = new int[][] { { RTL, RTL }, { RTL, RTL } }; |
285 |
msg = "TestDirection #10.5"; |
289 |
msg = "TestDirection #2 expected=" + array2_display(modir) + " result=" |
286 |
assertTrue(msg, f1.dirArabic == RTL && f1.dirHebrew == LTR); |
290 |
+ array2_display(dir); |
287 |
data = "#ABC.#DEF:HOST.com"; |
291 |
assertTrue(msg, arrays2_equal(modir, dir)); |
288 |
lean = toUT16(data); |
292 |
|
289 |
full = helper.leanToFullText(lean); |
293 |
processor.setDirection(LTR, RTL); |
290 |
model = "<&#ABC.#DEF:HOST.com&^"; |
294 |
dir = processor.getDirection(); |
291 |
assertEquals("TestDirection #11 full", model, toPseudo(full)); |
295 |
modir = new int[][] { { LTR, RTL }, { LTR, RTL } }; |
292 |
|
296 |
msg = "TestDirection #3 expected=" + array2_display(modir) + " result=" |
293 |
data = "#ABc.#DEF:HOSt.COM"; |
297 |
+ array2_display(dir); |
294 |
lean = toUT16(data); |
298 |
assertTrue(msg, arrays2_equal(modir, dir)); |
295 |
full = helper.leanToFullText(lean); |
299 |
|
296 |
model = "<&#ABc.#DEF:HOSt.COM&^"; |
300 |
processor.setArabicDirection(RTL); |
297 |
assertEquals("TestDirection #12 full", model, toPseudo(full)); |
301 |
dir = processor.getDirection(); |
298 |
|
302 |
modir = new int[][] { { RTL, RTL }, { LTR, RTL } }; |
299 |
data = "#ABc.#DEF:HOSt."; |
303 |
msg = "TestDirection #4 expected=" + array2_display(modir) + " result=" |
300 |
lean = toUT16(data); |
304 |
+ array2_display(dir); |
301 |
full = helper.leanToFullText(lean); |
305 |
assertTrue(msg, arrays2_equal(modir, dir)); |
302 |
model = "<&#ABc.#DEF:HOSt.&^"; |
306 |
|
303 |
assertEquals("TestDirection #13 full", model, toPseudo(full)); |
307 |
processor.setArabicDirection(RTL, LTR); |
304 |
|
308 |
dir = processor.getDirection(); |
305 |
data = "ABC.DEF:HOST.com"; |
309 |
modir = new int[][] { { RTL, LTR }, { LTR, RTL } }; |
306 |
lean = toUT16(data); |
310 |
msg = "TestDirection #5 expected=" + array2_display(modir) + " result=" |
307 |
full = helper.leanToFullText(lean); |
311 |
+ array2_display(dir); |
308 |
model = "ABC@.DEF@:HOST.com"; |
312 |
assertTrue(msg, arrays2_equal(modir, dir)); |
309 |
assertEquals("TestDirection #14 full", model, toPseudo(full)); |
313 |
|
310 |
|
314 |
processor.setHebrewDirection(RTL); |
311 |
data = "--.---:----"; |
315 |
dir = processor.getDirection(); |
312 |
lean = toUT16(data); |
316 |
modir = new int[][] { { RTL, LTR }, { RTL, RTL } }; |
313 |
full = helper.leanToFullText(lean); |
317 |
msg = "TestDirection #6 expected=" + array2_display(modir) + " result=" |
314 |
model = "--.---:----"; |
318 |
+ array2_display(dir); |
315 |
assertEquals("TestDirection #15 full", model, toPseudo(full)); |
319 |
assertTrue(msg, arrays2_equal(modir, dir)); |
316 |
|
320 |
|
317 |
data = "ABC.|DEF:HOST.com"; |
321 |
processor.setHebrewDirection(RTL, LTR); |
318 |
lean = toUT16(data); |
322 |
dir = processor.getDirection(); |
319 |
full = helper.leanToFullText(lean); |
323 |
modir = new int[][] { { RTL, LTR }, { RTL, LTR } }; |
320 |
model = "ABC.|DEF@:HOST.com"; |
324 |
msg = "TestDirection #7 expected=" + array2_display(modir) + " result=" |
321 |
assertEquals("TestDirection #16 full", model, toPseudo(full)); |
325 |
+ array2_display(dir); |
322 |
|
326 |
assertTrue(msg, arrays2_equal(modir, dir)); |
323 |
helper.setEnvironment(envRTLMIR); |
327 |
|
324 |
data = "#ABc.|#DEF:HOST.com"; |
328 |
processor = StringProcessor.getProcessor(IBiDiProcessor.EMAIL); |
325 |
lean = toUT16(data); |
329 |
processor.assumeMirrored(false); |
326 |
full = helper.leanToFullText(lean); |
330 |
processor.setArabicDirection(LTR, RTL); |
327 |
model = "#ABc.|#DEF:HOST.com"; |
331 |
processor.setHebrewDirection(LTR, LTR); |
328 |
assertEquals("TestDirection #17 full", model, toPseudo(full)); |
332 |
data = "#ABC.#DEF:HOST.com"; |
329 |
assertEquals("Test curDirection", RTL, helper.getCurDirection()); |
333 |
lean = toUT16(data); |
330 |
} |
334 |
full = processor.leanToFullText(lean); |
331 |
|
335 |
model = "#ABC@.#DEF@:HOST.com"; |
332 |
public void testMethods() { |
336 |
assertEquals("TestDirection #9 full", model, toPseudo(full)); |
333 |
|
337 |
|
334 |
doTestTools(); |
338 |
data = "ABC.DEF:HOST.com"; |
335 |
|
339 |
lean = toUT16(data); |
336 |
helper = new CxpHelper(IProcessorTypes.JAVA); |
340 |
full = processor.leanToFullText(lean); |
337 |
doTestState(); |
341 |
model = "ABC@.DEF@:HOST.com"; |
338 |
|
342 |
assertEquals("TestDirection #10 full", model, toPseudo(full)); |
339 |
doTestOrientation(); |
343 |
|
340 |
|
344 |
processor.assumeMirrored(true); |
341 |
helper = new CxpHelper(IProcessorTypes.COMMA_DELIMITED); |
345 |
data = "#ABC.#DEF:HOST.com"; |
342 |
CxpFeatures f2 = helper.getFeatures(); |
346 |
lean = toUT16(data); |
343 |
doTestOrient(f2, "Methods #1 ", "", "", "", ""); |
347 |
full = processor.leanToFullText(lean); |
344 |
doTestOrient(f2, "Methods #2 ", "abc", "abc", ">@abc@^", "abc"); |
348 |
model = "<&#ABC.#DEF:HOST.com&^"; |
345 |
doTestOrient(f2, "Methods #3 ", "ABC", "ABC", ">@ABC@^", "@ABC"); |
349 |
assertEquals("TestDirection #11 full", model, toPseudo(full)); |
346 |
doTestOrient(f2, "Methods #4 ", "bcd,ef", "bcd,ef", ">@bcd,ef@^", "bcd,ef"); |
350 |
|
347 |
doTestOrient(f2, "Methods #5 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", |
351 |
data = "#ABc.#DEF:HOSt.COM"; |
348 |
"@BCD@,EF"); |
352 |
lean = toUT16(data); |
349 |
doTestOrient(f2, "Methods #6 ", "cde,FG", "cde,FG", ">@cde,FG@^", "cde,FG"); |
353 |
full = processor.leanToFullText(lean); |
350 |
doTestOrient(f2, "Methods #7 ", "CDE,fg", "CDE,fg", ">@CDE,fg@^", "@CDE,fg"); |
354 |
model = "<&#ABc.#DEF:HOSt.COM&^"; |
351 |
doTestOrient(f2, "Methods #8 ", "12..def,GH", "12..def,GH", |
355 |
assertEquals("TestDirection #12 full", model, toPseudo(full)); |
352 |
">@12..def,GH@^", "12..def,GH"); |
356 |
|
353 |
doTestOrient(f2, "Methods #9 ", "34..DEF,gh", "34..DEF,gh", |
357 |
data = "#ABc.#DEF:HOSt."; |
354 |
">@34..DEF,gh@^", "@34..DEF,gh"); |
358 |
lean = toUT16(data); |
355 |
|
359 |
full = processor.leanToFullText(lean); |
356 |
doTestScripts(); |
360 |
model = "<&#ABc.#DEF:HOSt.&^"; |
357 |
|
361 |
assertEquals("TestDirection #13 full", model, toPseudo(full)); |
358 |
helper = new CxpHelper(IProcessorTypes.JAVA); |
362 |
|
359 |
doTestLeanOffsets(); |
363 |
data = "ABC.DEF:HOST.com"; |
360 |
|
364 |
lean = toUT16(data); |
361 |
helper = new CxpHelper(IProcessorTypes.COMMA_DELIMITED); |
365 |
full = processor.leanToFullText(lean); |
362 |
doTestFullOffsets("TestFullOffsets ", "BCD,EF,G", new int[] { 3, 7 }, |
366 |
model = "ABC@.DEF@:HOST.com"; |
363 |
new int[] { 0, 1, 5, 9, 12, 13 }, new int[] { 0, 4, 8 }); |
367 |
assertEquals("TestDirection #14 full", model, toPseudo(full)); |
364 |
|
368 |
|
365 |
doTestMirrored(); |
369 |
data = "--.---:----"; |
366 |
|
370 |
lean = toUT16(data); |
367 |
doTestDirection(); |
371 |
full = processor.leanToFullText(lean); |
368 |
|
372 |
model = "--.---:----"; |
369 |
helper = new CxpHelper(IProcessorTypes.COMMA_DELIMITED); |
373 |
assertEquals("TestDirection #15 full", model, toPseudo(full)); |
370 |
String data = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"; |
374 |
|
371 |
String lean = toUT16(data); |
375 |
data = "ABC.|DEF:HOST.com"; |
372 |
String full = helper.leanToFullText(lean); |
376 |
lean = toUT16(data); |
373 |
String model = "A@,B@,C@,D@,E@,F@,G@,H@,I@,J@,K@,L@,M@,N@,O@,P@,Q@,R@,S@,T@,U@,V@,W@,X@,Y@,Z"; |
377 |
full = processor.leanToFullText(lean); |
374 |
assertEquals("many inserts", model, toPseudo(full)); |
378 |
model = "ABC.|DEF@:HOST.com"; |
375 |
} |
379 |
assertEquals("TestDirection #16 full", model, toPseudo(full)); |
|
|
380 |
|
381 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_RTL); |
382 |
data = "#ABc.|#DEF:HOST.com"; |
383 |
lean = toUT16(data); |
384 |
full = processor.leanToFullText(lean); |
385 |
model = "#ABc.|#DEF:HOST.com"; |
386 |
assertEquals("TestDirection #17 full", model, toPseudo(full)); |
387 |
} |
388 |
|
389 |
public void testMethods() { |
390 |
|
391 |
doTestTools(); |
392 |
|
393 |
processor = StringProcessor.getProcessor(IBiDiProcessor.JAVA); |
394 |
doTestState(); |
395 |
|
396 |
doTestOrientation(); |
397 |
|
398 |
processor = StringProcessor |
399 |
.getProcessor(IBiDiProcessor.COMMA_DELIMITED); |
400 |
doTestOrient("Methods #1 ", "", "", "", ""); |
401 |
doTestOrient("Methods #2 ", "abc", "abc", ">@abc@^", "abc"); |
402 |
doTestOrient("Methods #3 ", "ABC", "ABC", ">@ABC@^", "@ABC"); |
403 |
doTestOrient("Methods #4 ", "bcd,ef", "bcd,ef", ">@bcd,ef@^", "bcd,ef"); |
404 |
doTestOrient("Methods #5 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", |
405 |
"@BCD@,EF"); |
406 |
doTestOrient("Methods #6 ", "cde,FG", "cde,FG", ">@cde,FG@^", "cde,FG"); |
407 |
doTestOrient("Methods #7 ", "CDE,fg", "CDE,fg", ">@CDE,fg@^", "@CDE,fg"); |
408 |
doTestOrient("Methods #8 ", "12..def,GH", "12..def,GH", |
409 |
">@12..def,GH@^", "12..def,GH"); |
410 |
doTestOrient("Methods #9 ", "34..DEF,gh", "34..DEF,gh", |
411 |
">@34..DEF,gh@^", "@34..DEF,gh"); |
412 |
|
413 |
doTestScripts(); |
414 |
|
415 |
processor = StringProcessor.getProcessor(IBiDiProcessor.JAVA); |
416 |
doTestLeanOffsets(); |
417 |
|
418 |
processor = StringProcessor |
419 |
.getProcessor(IBiDiProcessor.COMMA_DELIMITED); |
420 |
doTestFullOffsets("TestFullOffsets ", "BCD,EF,G", new int[] { 3, 7 }, |
421 |
new int[] { 0, 1, 5, 9, 12, 13 }, new int[] { 0, 4, 8 }); |
422 |
|
423 |
doTestMirrored(); |
424 |
|
425 |
doTestDirection(); |
426 |
|
427 |
processor = StringProcessor |
428 |
.getProcessor(IBiDiProcessor.COMMA_DELIMITED); |
429 |
processor.assumeOrientation(IComplExpProcessor.ORIENT_LTR); |
430 |
processor.setDirection(LTR); |
431 |
String data = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"; |
432 |
String lean = toUT16(data); |
433 |
String full = processor.leanToFullText(lean); |
434 |
String model = "A@,B@,C@,D@,E@,F@,G@,H@,I@,J@,K@,L@,M@,N@,O@,P@,Q@,R@,S@,T@,U@,V@,W@,X@,Y@,Z"; |
435 |
assertEquals("many inserts", model, toPseudo(full)); |
436 |
|
437 |
} |
438 |
} |
376 |
} |