View | Details | Raw Unified | Return to bug 183164 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/bidi/internal/tests/STextExtensibilityTest.java (-4 / +5 lines)
Lines 12-19 Link Here
12
package org.eclipse.equinox.bidi.internal.tests;
12
package org.eclipse.equinox.bidi.internal.tests;
13
13
14
import org.eclipse.equinox.bidi.STextEngine;
14
import org.eclipse.equinox.bidi.STextEngine;
15
import org.eclipse.equinox.bidi.custom.STextProcessor;
15
import org.eclipse.equinox.bidi.custom.STextStringProcessor;
16
import org.eclipse.equinox.bidi.custom.STextStringProcessor;
16
import org.eclipse.equinox.bidi.custom.ISTextProcessor;
17
17
18
/**
18
/**
19
 * Tests contribution of BiDi processors.
19
 * Tests contribution of BiDi processors.
Lines 28-34 Link Here
28
		// check one of the types that we know should be there
28
		// check one of the types that we know should be there
29
		assertTrue(isTypePresent(types, "regex"));
29
		assertTrue(isTypePresent(types, "regex"));
30
30
31
		ISTextProcessor processor = STextStringProcessor.getProcessor("regex");
31
		STextProcessor processor = STextStringProcessor.getProcessor("regex");
32
		assertNotNull(processor);
32
		assertNotNull(processor);
33
	}
33
	}
34
34
Lines 40-46 Link Here
40
		// check the type added by the test bundle
40
		// check the type added by the test bundle
41
		assertTrue(isTypePresent(types, "test"));
41
		assertTrue(isTypePresent(types, "test"));
42
42
43
		ISTextProcessor processor = STextStringProcessor.getProcessor("test");
43
		STextProcessor processor = STextStringProcessor.getProcessor("test");
44
		assertNotNull(processor);
44
		assertNotNull(processor);
45
45
46
		processor = STextStringProcessor.getProcessor("badtest");
46
		processor = STextStringProcessor.getProcessor("badtest");
Lines 49-55 Link Here
49
		String data, lean, full, model;
49
		String data, lean, full, model;
50
		data = "ABC.DEF:HOST-COM=HELLO";
50
		data = "ABC.DEF:HOST-COM=HELLO";
51
		lean = toUT16(data);
51
		lean = toUT16(data);
52
		full = STextEngine.leanToFullText("test", null, null, lean, null);
52
		processor = STextStringProcessor.getProcessor("test");
53
		full = STextEngine.leanToFullText(processor, null, lean, null);
53
		model = "ABC@.DEF@:HOST@-COM@=HELLO";
54
		model = "ABC@.DEF@:HOST@-COM@=HELLO";
54
		assertEquals("Test 'test' plugin", model, toPseudo(full));
55
		assertEquals("Test 'test' plugin", model, toPseudo(full));
55
	}
56
	}
(-)src/org/eclipse/equinox/bidi/internal/tests/STextExtensionsTest.java (-32 / +74 lines)
Lines 11-19 Link Here
11
11
12
package org.eclipse.equinox.bidi.internal.tests;
12
package org.eclipse.equinox.bidi.internal.tests;
13
13
14
import java.util.Locale;
14
import org.eclipse.equinox.bidi.STextEngine;
15
import org.eclipse.equinox.bidi.STextEngine;
15
import org.eclipse.equinox.bidi.ISTextTypes;
16
import org.eclipse.equinox.bidi.custom.STextProcessor;
16
import org.eclipse.equinox.bidi.custom.*;
17
17
18
/**
18
/**
19
 * Tests all plug-in extensions
19
 * Tests all plug-in extensions
Lines 21-67 Link Here
21
21
22
public class STextExtensionsTest extends STextTestBase {
22
public class STextExtensionsTest extends STextTestBase {
23
23
24
	ISTextProcessor processor;
24
	STextProcessor processor;
25
	STextFeatures f1, f2;
26
	int[] state = new int[1];
25
	int[] state = new int[1];
27
	String type;
28
26
29
	private void doTest1(String label, String data, String result) {
27
	private void doTest1(String label, String data, String result) {
30
		String full;
28
		String full;
31
		full = STextEngine.leanToFullText(type, null, null, toUT16(data), state);
29
		full = STextEngine.leanToFullText(processor, null, toUT16(data), state);
32
		assertEquals(label + " data = " + data, result, toPseudo(full));
30
		assertEquals(label + " data = " + data, result, toPseudo(full));
33
	}
31
	}
34
32
35
	private void doTest2(String label, String data, String result) {
33
	private void doTest2(String label, String data, String result) {
36
		String full;
34
		String full;
37
		full = STextEngine.leanToFullText(type, null, null, data, state);
35
		full = STextEngine.leanToFullText(processor, null, data, state);
38
		assertEquals(label + " data = " + data, result, toPseudo(full));
36
		assertEquals(label + " data = " + data, result, toPseudo(full));
39
	}
37
	}
40
38
41
	private void doTest3(String label, String data, String result) {
39
	private void doTest3(String label, String data, String result) {
42
		String full;
40
		String full;
43
		full = STextEngine.leanToFullText(processor, f2, null, toUT16(data), state);
41
		full = STextEngine.leanToFullText(processor, null, toUT16(data), state);
44
		assertEquals(label + " data = " + data, result, toPseudo(full));
42
		assertEquals(label + " data = " + data, result, toPseudo(full));
45
	}
43
	}
46
44
47
	public void testExtensions() {
45
	public void testExtensions() {
48
46
49
		type = ISTextTypes.COMMA_DELIMITED;
47
		String data;
48
		processor = STextEngine.PROC_COMMA_DELIMITED;
50
		state[0] = STextEngine.STATE_INITIAL;
49
		state[0] = STextEngine.STATE_INITIAL;
51
		doTest1("Comma #1", "ab,cd, AB, CD, EFG", "ab,cd, AB@, CD@, EFG");
50
		doTest1("Comma #1", "ab,cd, AB, CD, EFG", "ab,cd, AB@, CD@, EFG");
52
51
53
		type = ISTextTypes.EMAIL;
52
		processor = STextEngine.PROC_EMAIL;
54
		state[0] = STextEngine.STATE_INITIAL;
53
		state[0] = STextEngine.STATE_INITIAL;
55
		doTest1("Email #1", "abc.DEF:GHI", "abc.DEF@:GHI");
54
		doTest1("Email #1", "abc.DEF:GHI", "abc.DEF@:GHI");
56
		doTest1("Email #2", "DEF.GHI \"A.B\":JK ", "DEF@.GHI @\"A.B\"@:JK ");
55
		doTest1("Email #2", "DEF.GHI \"A.B\":JK ", "DEF@.GHI @\"A.B\"@:JK ");
57
		doTest1("Email #3", "DEF,GHI (A,B);JK ", "DEF@,GHI @(A,B)@;JK ");
56
		doTest1("Email #3", "DEF,GHI (A,B);JK ", "DEF@,GHI @(A,B)@;JK ");
58
		doTest1("Email #4", "DEF.GHI (A.B :JK ", "DEF@.GHI @(A.B :JK ");
57
		doTest1("Email #4", "DEF.GHI (A.B :JK ", "DEF@.GHI @(A.B :JK ");
58
		Locale.setDefault(new Locale("ar"));
59
		doTest1("Email #5", "#EF.GHI \"A.B\":JK ", "<&#EF.GHI \"A.B\":JK &^");
60
		doTest1("Email #6", "#EF,GHI (A,B);JK ", "<&#EF,GHI (A,B);JK &^");
61
		doTest1("Email #7", "#EF.GHI (A.B :JK ", "<&#EF.GHI (A.B :JK &^");
62
		data = toUT16("peter.pan") + "@" + toUT16("#EF.GHI");
63
		doTest2("Email #8", data, "<&peter&.pan@#EF.GHI&^");
64
		Locale.setDefault(new Locale("he"));
65
		data = toUT16("peter.pan") + "@" + toUT16("DEF.GHI");
66
		doTest2("Email #9", data, "peter.pan@DEF@.GHI");
59
67
60
		type = ISTextTypes.FILE;
68
		processor = STextEngine.PROC_FILE;
61
		state[0] = STextEngine.STATE_INITIAL;
69
		state[0] = STextEngine.STATE_INITIAL;
62
		doTest1("File #1", "c:\\A\\B\\FILE.EXT", "c:\\A@\\B@\\FILE@.EXT");
70
		doTest1("File #1", "c:\\A\\B\\FILE.EXT", "c:\\A@\\B@\\FILE@.EXT");
63
71
64
		type = ISTextTypes.JAVA;
72
		processor = STextEngine.PROC_JAVA;
65
		state[0] = STextEngine.STATE_INITIAL;
73
		state[0] = STextEngine.STATE_INITIAL;
66
		doTest1("Java #1", "A = B + C;", "A@ = B@ + C;");
74
		doTest1("Java #1", "A = B + C;", "A@ = B@ + C;");
67
		doTest1("Java #2", "A   = B + C;", "A@   = B@ + C;");
75
		doTest1("Java #2", "A   = B + C;", "A@   = B@ + C;");
Lines 74-87 Link Here
74
		doTest1("Java #9", "A = //B+C* D;", "A@ = //B+C* D;");
82
		doTest1("Java #9", "A = //B+C* D;", "A@ = //B+C* D;");
75
		doTest1("Java #10", "A = //B+C`|D+E;", "A@ = //B+C`|D@+E;");
83
		doTest1("Java #10", "A = //B+C`|D+E;", "A@ = //B+C`|D@+E;");
76
84
77
		type = ISTextTypes.PROPERTY;
85
		processor = STextEngine.PROC_PROPERTY;
78
		state[0] = STextEngine.STATE_INITIAL;
86
		state[0] = STextEngine.STATE_INITIAL;
79
		doTest1("Property #0", "NAME,VAL1,VAL2", "NAME,VAL1,VAL2");
87
		doTest1("Property #0", "NAME,VAL1,VAL2", "NAME,VAL1,VAL2");
80
		doTest1("Property #1", "NAME=VAL1,VAL2", "NAME@=VAL1,VAL2");
88
		doTest1("Property #1", "NAME=VAL1,VAL2", "NAME@=VAL1,VAL2");
81
		doTest1("Property #2", "NAME=VAL1,VAL2=VAL3", "NAME@=VAL1,VAL2=VAL3");
89
		doTest1("Property #2", "NAME=VAL1,VAL2=VAL3", "NAME@=VAL1,VAL2=VAL3");
82
90
83
		String data;
91
		processor = STextEngine.PROC_REGEXP;
84
		type = ISTextTypes.REGEXP;
85
		state[0] = STextEngine.STATE_INITIAL;
92
		state[0] = STextEngine.STATE_INITIAL;
86
		data = toUT16("ABC(?") + "#" + toUT16("DEF)GHI");
93
		data = toUT16("ABC(?") + "#" + toUT16("DEF)GHI");
87
		doTest2("Regex #0.0", data, "A@B@C@(?#DEF)@G@H@I");
94
		doTest2("Regex #0.0", data, "A@B@C@(?#DEF)@G@H@I");
Lines 127-133 Link Here
127
		doTest1("Regex #17.6", "aB*123", "aB*@123");
134
		doTest1("Regex #17.6", "aB*123", "aB*@123");
128
		doTest1("Regex #17.7", "aB*567", "aB*@567");
135
		doTest1("Regex #17.7", "aB*567", "aB*@567");
129
136
130
		type = ISTextTypes.SQL;
137
		Locale.setDefault(new Locale("ar"));
138
		data = toUT16("#BC(?") + "#" + toUT16("DEF)GHI");
139
		doTest2("Regex #0.0", data, "<&#BC(?#DEF)GHI&^");
140
		data = toUT16("#BC(?") + "#" + toUT16("DEF");
141
		doTest2("Regex #0.1", data, "<&#BC(?#DEF&^");
142
		doTest1("Regex #0.2", "#HI)JKL", "<&#HI)JKL&^");
143
		data = toUT16("#BC(?") + "<" + toUT16("DEF") + ">" + toUT16("GHI");
144
		doTest2("Regex #1", data, "<&#BC(?<DEF>GHI&^");
145
		doTest1("Regex #2.0", "#BC(?'DEF'GHI", "<&#BC(?'DEF'GHI&^");
146
		doTest1("Regex #2.1", "#BC(?'DEFGHI", "<&#BC(?'DEFGHI&^");
147
		data = toUT16("#BC(?(") + "<" + toUT16("DEF") + ">" + toUT16(")GHI");
148
		doTest2("Regex #3", data, "<&#BC(?(<DEF>)GHI&^");
149
		doTest1("Regex #4", "#BC(?('DEF')GHI", "<&#BC(?('DEF')GHI&^");
150
		doTest1("Regex #5", "#BC(?(DEF)GHI", "<&#BC(?(DEF)GHI&^");
151
		data = toUT16("#BC(?") + "&" + toUT16("DEF)GHI");
152
		doTest2("Regex #6", data, "<&#BC(?&DEF)GHI&^");
153
		data = toUT16("#BC(?") + "P<" + toUT16("DEF") + ">" + toUT16("GHI");
154
		doTest2("Regex #7", data, "<&#BC(?p<DEF>GHI&^");
155
		data = toUT16("#BC\\k") + "<" + toUT16("DEF") + ">" + toUT16("GHI");
156
		doTest2("Regex #8", data, "<&#BC\\k<DEF>GHI&^");
157
		doTest1("Regex #9", "#BC\\k'DEF'GHI", "<&#BC\\k'DEF'GHI&^");
158
		doTest1("Regex #10", "#BC\\k{DEF}GHI", "<&#BC\\k{DEF}GHI&^");
159
		data = toUT16("#BC(?") + "P=" + toUT16("DEF)GHI");
160
		doTest2("Regex #11", data, "<&#BC(?p=DEF)GHI&^");
161
		doTest1("Regex #12", "#BC\\g{DEF}GHI", "<&#BC\\g{DEF}GHI&^");
162
		data = toUT16("#BC\\g") + "<" + toUT16("DEF") + ">" + toUT16("GHI");
163
		doTest2("Regex #13", data, "<&#BC\\g<DEF>GHI&^");
164
		doTest1("Regex #14", "#BC\\g'DEF'GHI", "<&#BC\\g'DEF'GHI&^");
165
		data = toUT16("#BC(?(") + "R&" + toUT16("DEF)GHI");
166
		doTest2("Regex #15", data, "<&#BC(?(r&DEF)GHI&^");
167
		data = toUT16("#BC") + "\\Q" + toUT16("DEF") + "\\E" + toUT16("GHI");
168
		doTest2("Regex #16.0", data, "<&#BC\\qDEF\\eGHI&^");
169
		data = toUT16("#BC") + "\\Q" + toUT16("DEF");
170
		doTest2("Regex #16.1", data, "<&#BC\\qDEF&^");
171
		data = toUT16("#HI") + "\\E" + toUT16("JKL");
172
		doTest2("Regex #16.2", data, "<&#HI\\eJKL&^");
173
		Locale.setDefault(new Locale("he"));
174
175
		processor = STextEngine.PROC_SQL;
131
		state[0] = STextEngine.STATE_INITIAL;
176
		state[0] = STextEngine.STATE_INITIAL;
132
		doTest1("SQL #0", "abc GHI", "abc GHI");
177
		doTest1("SQL #0", "abc GHI", "abc GHI");
133
		doTest1("SQL #1", "abc DEF   GHI", "abc DEF@   GHI");
178
		doTest1("SQL #1", "abc DEF   GHI", "abc DEF@   GHI");
Lines 146-182 Link Here
146
		doTest1("SQL #12", "ABC\"DEF \"\" G I\" JKL,MN", "ABC@\"DEF \"\" G I\"@ JKL@,MN");
191
		doTest1("SQL #12", "ABC\"DEF \"\" G I\" JKL,MN", "ABC@\"DEF \"\" G I\"@ JKL@,MN");
147
		doTest1("SQL #13", "ABC--DEF GHI`|JKL MN", "ABC@--DEF GHI`|JKL@ MN");
192
		doTest1("SQL #13", "ABC--DEF GHI`|JKL MN", "ABC@--DEF GHI`|JKL@ MN");
148
193
149
		type = ISTextTypes.SYSTEM_USER;
194
		processor = STextEngine.PROC_SYSTEM_USER;
150
		state[0] = STextEngine.STATE_INITIAL;
195
		state[0] = STextEngine.STATE_INITIAL;
151
		doTest1("System #1", "HOST(JACK)", "HOST@(JACK)");
196
		doTest1("System #1", "HOST(JACK)", "HOST@(JACK)");
152
197
153
		type = ISTextTypes.UNDERSCORE;
198
		processor = STextEngine.PROC_UNDERSCORE;
154
		state[0] = STextEngine.STATE_INITIAL;
199
		state[0] = STextEngine.STATE_INITIAL;
155
		doTest1("Underscore #1", "A_B_C_d_e_F_G", "A@_B@_C_d_e_F@_G");
200
		doTest1("Underscore #1", "A_B_C_d_e_F_G", "A@_B@_C_d_e_F@_G");
156
201
157
		type = ISTextTypes.URL;
202
		processor = STextEngine.PROC_URL;
158
		state[0] = STextEngine.STATE_INITIAL;
203
		state[0] = STextEngine.STATE_INITIAL;
159
		doTest1("URL #1", "WWW.DOMAIN.COM/DIR1/DIR2/dir3/DIR4", "WWW@.DOMAIN@.COM@/DIR1@/DIR2/dir3/DIR4");
204
		doTest1("URL #1", "WWW.DOMAIN.COM/DIR1/DIR2/dir3/DIR4", "WWW@.DOMAIN@.COM@/DIR1@/DIR2/dir3/DIR4");
160
205
161
		type = ISTextTypes.XPATH;
206
		processor = STextEngine.PROC_XPATH;
162
		state[0] = STextEngine.STATE_INITIAL;
207
		state[0] = STextEngine.STATE_INITIAL;
163
		doTest1("Xpath #1", "abc(DEF)GHI", "abc(DEF@)GHI");
208
		doTest1("Xpath #1", "abc(DEF)GHI", "abc(DEF@)GHI");
164
		doTest1("Xpath #2", "DEF.GHI \"A.B\":JK ", "DEF@.GHI@ \"A.B\"@:JK ");
209
		doTest1("Xpath #2", "DEF.GHI \"A.B\":JK ", "DEF@.GHI@ \"A.B\"@:JK ");
165
		doTest1("Xpath #3", "DEF!GHI 'A!B'=JK ", "DEF@!GHI@ 'A!B'@=JK ");
210
		doTest1("Xpath #3", "DEF!GHI 'A!B'=JK ", "DEF@!GHI@ 'A!B'@=JK ");
166
		doTest1("Xpath #4", "DEF.GHI 'A.B :JK ", "DEF@.GHI@ 'A.B :JK ");
211
		doTest1("Xpath #4", "DEF.GHI 'A.B :JK ", "DEF@.GHI@ 'A.B :JK ");
167
212
168
		type = ISTextTypes.EMAIL;
213
		processor = STextEngine.PROC_EMAIL;
169
		processor = STextStringProcessor.getProcessor(type);
170
		state[0] = STextEngine.STATE_INITIAL;
214
		state[0] = STextEngine.STATE_INITIAL;
171
		f1 = processor.getFeatures(null);
215
		assertEquals("<>.:,;@", processor.getSeparators(null, "", null));
172
		assertEquals("<>.:,;@", f1.getSeparators());
216
		doTest3("DelimsEsc #1", "abc.DEF.GHI", "abc.DEF@.GHI");
173
		f2 = new STextFeatures("+-*/", f1.getSpecialsCount(), f1.getDirArabic(), f1.getDirHebrew(), f1.getIgnoreArabic(), f1.getIgnoreHebrew());
217
		doTest3("DelimsEsc #2", "DEF.GHI (A:B);JK ", "DEF@.GHI @(A:B)@;JK ");
174
		doTest3("DelimsEsc #1", "abc+DEF-GHI", "abc+DEF@-GHI");
218
		doTest3("DelimsEsc #3", "DEF.GHI (A:B);JK ", "DEF@.GHI @(A:B)@;JK ");
175
		doTest3("DelimsEsc #2", "DEF-GHI (A*B)/JK ", "DEF@-GHI @(A*B)@/JK ");
219
		doTest3("DelimsEsc #4", "DEF.GHI (A:B\\):C) ;JK ", "DEF@.GHI @(A:B\\):C) @;JK ");
176
		doTest3("DelimsEsc #3", "DEF-GHI (A*B)/JK ", "DEF@-GHI @(A*B)@/JK ");
220
		doTest3("DelimsEsc #5", "DEF.GHI (A\\\\\\):C) ;JK ", "DEF@.GHI @(A\\\\\\):C) @;JK ");
177
		doTest3("DelimsEsc #4", "DEF-GHI (A*B\\)*C) /JK ", "DEF@-GHI @(A*B\\)*C) @/JK ");
221
		doTest3("DelimsEsc #6", "DEF.GHI (A\\\\):C ;JK ", "DEF@.GHI @(A\\\\)@:C @;JK ");
178
		doTest3("DelimsEsc #5", "DEF-GHI (A\\\\\\)*C) /JK ", "DEF@-GHI @(A\\\\\\)*C) @/JK ");
222
		doTest3("DelimsEsc #7", "DEF.GHI (A\\):C ;JK ", "DEF@.GHI @(A\\):C ;JK ");
179
		doTest3("DelimsEsc #6", "DEF-GHI (A\\\\)*C /JK ", "DEF@-GHI @(A\\\\)@*C @/JK ");
180
		doTest3("DelimsEsc #7", "DEF-GHI (A\\)*C /JK ", "DEF@-GHI @(A\\)*C /JK ");
181
	}
223
	}
182
}
224
}
(-)src/org/eclipse/equinox/bidi/internal/tests/STextFullToLeanTest.java (-18 / +20 lines)
Lines 11-17 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.*;
14
import org.eclipse.equinox.bidi.STextEngine;
15
import org.eclipse.equinox.bidi.STextEnvironment;
16
import org.eclipse.equinox.bidi.custom.STextProcessor;
15
17
16
/**
18
/**
17
 * Tests fullToLean method
19
 * Tests fullToLean method
Lines 22-53 Link Here
22
	static final STextEnvironment envLTR = new STextEnvironment(null, false, STextEnvironment.ORIENT_LTR);
24
	static final STextEnvironment envLTR = new STextEnvironment(null, false, STextEnvironment.ORIENT_LTR);
23
	static final STextEnvironment envRTL = new STextEnvironment(null, false, STextEnvironment.ORIENT_RTL);
25
	static final STextEnvironment envRTL = new STextEnvironment(null, false, STextEnvironment.ORIENT_RTL);
24
26
25
	String type;
27
	STextProcessor processor;
26
28
27
	private void doTest1(String msg, String data, String leanLTR, String fullLTR, int[] l2fMapLTR, int[] f2lMapLTR, String leanRTL, String fullRTL, int[] l2fMapRTL, int[] f2lMapRTL) {
29
	private void doTest1(String msg, String data, String leanLTR, String fullLTR, int[] l2fMapLTR, int[] f2lMapLTR, String leanRTL, String fullRTL, int[] l2fMapRTL, int[] f2lMapRTL) {
28
		String text, full, lean, label;
30
		String text, full, lean, label;
29
		int[] map;
31
		int[] map;
30
32
31
		text = toUT16(data);
33
		text = toUT16(data);
32
		lean = STextEngine.fullToLeanText(type, null, envLTR, text, null);
34
		lean = STextEngine.fullToLeanText(processor, envLTR, text, null);
33
		assertEquals(msg + "LTR lean", leanLTR, toPseudo(lean));
35
		assertEquals(msg + "LTR lean", leanLTR, toPseudo(lean));
34
		full = STextEngine.leanToFullText(type, null, envLTR, lean, null);
36
		full = STextEngine.leanToFullText(processor, envLTR, lean, null);
35
		assertEquals(msg + "LTR full", fullLTR, toPseudo(full));
37
		assertEquals(msg + "LTR full", fullLTR, toPseudo(full));
36
		map = STextEngine.leanToFullMap(type, null, envLTR, lean, null);
38
		map = STextEngine.leanToFullMap(processor, envLTR, lean, null);
37
		label = msg + "leanToFullMap() LTR";
39
		label = msg + "leanToFullMap() LTR";
38
		assertEquals(label, array_display(l2fMapLTR), array_display(map));
40
		assertEquals(label, array_display(l2fMapLTR), array_display(map));
39
		map = STextEngine.fullToLeanMap(type, null, envLTR, text, null);
41
		map = STextEngine.fullToLeanMap(processor, envLTR, text, null);
40
		label = msg + "fullToLeanMap() LTR";
42
		label = msg + "fullToLeanMap() LTR";
41
		assertEquals(label, array_display(f2lMapLTR), array_display(map));
43
		assertEquals(label, array_display(f2lMapLTR), array_display(map));
42
44
43
		lean = STextEngine.fullToLeanText(type, null, envRTL, text, null);
45
		lean = STextEngine.fullToLeanText(processor, envRTL, text, null);
44
		assertEquals(msg + "RTL lean", leanRTL, toPseudo(lean));
46
		assertEquals(msg + "RTL lean", leanRTL, toPseudo(lean));
45
		full = STextEngine.leanToFullText(type, null, envRTL, lean, null);
47
		full = STextEngine.leanToFullText(processor, envRTL, lean, null);
46
		assertEquals(msg + "RTL full", fullRTL, toPseudo(full));
48
		assertEquals(msg + "RTL full", fullRTL, toPseudo(full));
47
		map = STextEngine.leanToFullMap(type, null, envRTL, lean, null);
49
		map = STextEngine.leanToFullMap(processor, envRTL, lean, null);
48
		label = msg + "leanToFullMap() RTL";
50
		label = msg + "leanToFullMap() RTL";
49
		assertEquals(label, array_display(l2fMapRTL), array_display(map));
51
		assertEquals(label, array_display(l2fMapRTL), array_display(map));
50
		map = STextEngine.fullToLeanMap(type, null, envRTL, text, null);
52
		map = STextEngine.fullToLeanMap(processor, envRTL, text, null);
51
		label = msg + "fullToLeanMap() RTL";
53
		label = msg + "fullToLeanMap() RTL";
52
		assertEquals(label, array_display(f2lMapRTL), array_display(map));
54
		assertEquals(label, array_display(f2lMapRTL), array_display(map));
53
	}
55
	}
Lines 60-100 Link Here
60
		data = "update \"AB_CDE\" set \"COL1\"@='01', \"COL2\"@='02' /* GH IJK";
62
		data = "update \"AB_CDE\" set \"COL1\"@='01', \"COL2\"@='02' /* GH IJK";
61
		text = toUT16(data);
63
		text = toUT16(data);
62
		state[0] = -1;
64
		state[0] = -1;
63
		lean = STextEngine.fullToLeanText(type, null, envLTR, text, state);
65
		lean = STextEngine.fullToLeanText(processor, envLTR, text, state);
64
		state1 = state[0];
66
		state1 = state[0];
65
		model = "update \"AB_CDE\" set \"COL1\"='01', \"COL2\"='02' /* GH IJK";
67
		model = "update \"AB_CDE\" set \"COL1\"='01', \"COL2\"='02' /* GH IJK";
66
		assertEquals(msg + "LTR lean", model, toPseudo(lean));
68
		assertEquals(msg + "LTR lean", model, toPseudo(lean));
67
		state[0] = -1;
69
		state[0] = -1;
68
		full = STextEngine.leanToFullText(type, null, envLTR, lean, state);
70
		full = STextEngine.leanToFullText(processor, envLTR, lean, state);
69
		assertEquals(msg + "LTR full", data, toPseudo(full));
71
		assertEquals(msg + "LTR full", data, toPseudo(full));
70
		assertEquals(msg + "state from leanToFullText", state1, state[0]);
72
		assertEquals(msg + "state from leanToFullText", state1, state[0]);
71
		data = "THIS IS A COMMENT LINE";
73
		data = "THIS IS A COMMENT LINE";
72
		text = toUT16(data);
74
		text = toUT16(data);
73
		state[0] = state1;
75
		state[0] = state1;
74
		lean = STextEngine.fullToLeanText(type, null, envLTR, text, state);
76
		lean = STextEngine.fullToLeanText(processor, envLTR, text, state);
75
		state2 = state[0];
77
		state2 = state[0];
76
		model = "THIS IS A COMMENT LINE";
78
		model = "THIS IS A COMMENT LINE";
77
		assertEquals(msg + "LTR lean2", model, toPseudo(lean));
79
		assertEquals(msg + "LTR lean2", model, toPseudo(lean));
78
		state[0] = state1;
80
		state[0] = state1;
79
		full = STextEngine.leanToFullText(type, null, envLTR, lean, state);
81
		full = STextEngine.leanToFullText(processor, envLTR, lean, state);
80
		assertEquals(msg + "LTR full2", data, toPseudo(full));
82
		assertEquals(msg + "LTR full2", data, toPseudo(full));
81
		assertEquals(msg + "state from leanToFullText2", state2, state[0]);
83
		assertEquals(msg + "state from leanToFullText2", state2, state[0]);
82
		data = "SOME MORE */ where \"COL3\"@=123";
84
		data = "SOME MORE */ where \"COL3\"@=123";
83
		text = toUT16(data);
85
		text = toUT16(data);
84
		state[0] = state2;
86
		state[0] = state2;
85
		lean = STextEngine.fullToLeanText(type, null, envLTR, text, state);
87
		lean = STextEngine.fullToLeanText(processor, envLTR, text, state);
86
		state3 = state[0];
88
		state3 = state[0];
87
		model = "SOME MORE */ where \"COL3\"=123";
89
		model = "SOME MORE */ where \"COL3\"=123";
88
		assertEquals(msg + "LTR lean3", model, toPseudo(lean));
90
		assertEquals(msg + "LTR lean3", model, toPseudo(lean));
89
		state[0] = state2;
91
		state[0] = state2;
90
		full = STextEngine.leanToFullText(type, null, envLTR, lean, state);
92
		full = STextEngine.leanToFullText(processor, envLTR, lean, state);
91
		assertEquals(msg + "LTR full3", data, toPseudo(full));
93
		assertEquals(msg + "LTR full3", data, toPseudo(full));
92
		assertEquals(msg + "state from leanToFullText3", state3, state[0]);
94
		assertEquals(msg + "state from leanToFullText3", state3, state[0]);
93
	}
95
	}
94
96
95
	public void testFullToLean() {
97
	public void testFullToLean() {
96
98
97
		type = ISTextTypes.COMMA_DELIMITED;
99
		processor = STextEngine.PROC_COMMA_DELIMITED;
98
		doTest1("testFullToLean #1 - ", "", "", "", new int[0], new int[0], "", "", new int[0], new int[0]);
100
		doTest1("testFullToLean #1 - ", "", "", "", new int[0], new int[0], "", "", new int[0], new int[0]);
99
		int[] map1 = new int[] {0, 1, 2, 3, 4};
101
		int[] map1 = new int[] {0, 1, 2, 3, 4};
100
		int[] map2 = new int[] {2, 3, 4, 5, 6};
102
		int[] map2 = new int[] {2, 3, 4, 5, 6};
Lines 241-247 Link Here
241
		doTest1("testFullToLean #37 - ", ">>>@@@@@^^^", "", "", map1, map2, "", "", map1, map2);
243
		doTest1("testFullToLean #37 - ", ">>>@@@@@^^^", "", "", map1, map2, "", "", map1, map2);
242
244
243
		// test fullToLeanText with initial state
245
		// test fullToLeanText with initial state
244
		type = ISTextTypes.SQL;
246
		processor = STextEngine.PROC_SQL;
245
		doTest2("testFullToLean #38 - ");
247
		doTest2("testFullToLean #38 - ");
246
	}
248
	}
247
}
249
}
(-)src/org/eclipse/equinox/bidi/internal/tests/STextMathTest.java (-13 / +19 lines)
Lines 11-17 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.*;
14
import java.util.Locale;
15
import org.eclipse.equinox.bidi.STextEngine;
16
import org.eclipse.equinox.bidi.STextEnvironment;
17
import org.eclipse.equinox.bidi.custom.STextProcessor;
15
18
16
/**
19
/**
17
 * Tests RTL arithmetic
20
 * Tests RTL arithmetic
Lines 21-46 Link Here
21
	static final STextEnvironment envLTR = new STextEnvironment(null, false, STextEnvironment.ORIENT_LTR);
24
	static final STextEnvironment envLTR = new STextEnvironment(null, false, STextEnvironment.ORIENT_LTR);
22
	static final STextEnvironment envRTL = new STextEnvironment(null, false, STextEnvironment.ORIENT_RTL);
25
	static final STextEnvironment envRTL = new STextEnvironment(null, false, STextEnvironment.ORIENT_RTL);
23
26
24
	String type = ISTextTypes.RTL_ARITHMETIC;
27
	STextProcessor processor = STextEngine.PROC_RTL_ARITHMETIC;
25
28
26
	private void verifyOneLine(String msg, String data, String resLTR, String resRTL) {
29
	private void verifyOneLine(String msg, String data, String resLTR, String resRTL) {
27
		String lean = toUT16(data);
30
		String lean = toUT16(data);
28
		String fullLTR = STextEngine.leanToFullText(type, null, envLTR, lean, null);
31
		String fullLTR = STextEngine.leanToFullText(processor, envLTR, lean, null);
29
		assertEquals(msg + " LTR - ", resLTR, toPseudo(fullLTR));
32
		assertEquals(msg + " LTR - ", resLTR, toPseudo(fullLTR));
30
		String fullRTL = STextEngine.leanToFullText(type, null, envRTL, lean, null);
33
		String fullRTL = STextEngine.leanToFullText(processor, envRTL, lean, null);
31
		assertEquals(msg + " RTL - ", resRTL, toPseudo(fullRTL));
34
		assertEquals(msg + " RTL - ", resRTL, toPseudo(fullRTL));
32
	}
35
	}
33
36
34
	public void testRTLarithmetic() {
37
	public void testRTLarithmetic() {
35
		verifyOneLine("Math #0", "", "", "");
38
		verifyOneLine("Math #0", "", "", "");
36
		verifyOneLine("Math #1", "1+abc", "<&1+abc&^", "1+abc");
39
		verifyOneLine("Math #1", "1+ABC", "1+ABC", ">@1+ABC@^");
37
		verifyOneLine("Math #2", "2+abc-def", "<&2+abc&-def&^", "2+abc&-def");
40
		verifyOneLine("Math #2", "2+ABC-DEF", "2+ABC@-DEF", ">@2+ABC@-DEF@^");
38
		verifyOneLine("Math #3", "a+3*bc/def", "<&a&+3*bc&/def&^", "a&+3*bc&/def");
41
		verifyOneLine("Math #3", "A+3*BC/DEF", "A@+3*BC@/DEF", ">@A@+3*BC@/DEF@^");
39
		verifyOneLine("Math #4", "4+abc/def", "<&4+abc&/def&^", "4+abc&/def");
42
		verifyOneLine("Math #4", "4+ABC/DEF", "4+ABC@/DEF", ">@4+ABC@/DEF@^");
40
		verifyOneLine("Math #5", "13ABC", "<&13ABC&^", "13ABC");
43
		Locale.setDefault(new Locale("ar"));
41
		verifyOneLine("Math #6", "14ABC-DE", "<&14ABC-DE&^", "14ABC-DE");
44
		verifyOneLine("Math #5", "5#BC", "<&5#BC&^", "5#BC");
42
		verifyOneLine("Math #7", "15ABC+DE", "<&15ABC+DE&^", "15ABC+DE");
45
		verifyOneLine("Math #6", "6#BC-DE", "<&6#BC-DE&^", "6#BC-DE");
43
		verifyOneLine("Math #8", "16ABC*DE", "<&16ABC*DE&^", "16ABC*DE");
46
		verifyOneLine("Math #7", "7#BC+DE", "<&7#BC+DE&^", "7#BC+DE");
44
		verifyOneLine("Math #9", "17ABC/DE", "<&17ABC/DE&^", "17ABC/DE");
47
		verifyOneLine("Math #8", "8#BC*DE", "<&8#BC*DE&^", "8#BC*DE");
48
		verifyOneLine("Math #9", "9#BC/DE", "<&9#BC/DE&^", "9#BC/DE");
49
		verifyOneLine("Math #10", "10ab+cd-ef", "10ab+cd-ef", ">@10ab+cd-ef@^");
50
		Locale.setDefault(new Locale("he"));
45
	}
51
	}
46
}
52
}
(-)src/org/eclipse/equinox/bidi/internal/tests/STextMethodsTest.java (-128 / +113 lines)
Lines 11-18 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.*;
14
import org.eclipse.equinox.bidi.STextEngine;
15
import org.eclipse.equinox.bidi.custom.*;
15
import org.eclipse.equinox.bidi.STextEnvironment;
16
import org.eclipse.equinox.bidi.custom.STextProcessor;
16
17
17
/**
18
/**
18
 * Tests most public methods of BidiComplexEngine
19
 * Tests most public methods of BidiComplexEngine
Lines 20-27 Link Here
20
21
21
public class STextMethodsTest extends STextTestBase {
22
public class STextMethodsTest extends STextTestBase {
22
23
23
	final static int LTR = STextFeatures.DIR_LTR;
24
	final static int LTR = STextEngine.DIR_LTR;
24
	final static int RTL = STextFeatures.DIR_RTL;
25
	final static int RTL = STextEngine.DIR_RTL;
25
	final static STextEnvironment envLTR = new STextEnvironment(null, false, STextEnvironment.ORIENT_LTR);
26
	final static STextEnvironment envLTR = new STextEnvironment(null, false, STextEnvironment.ORIENT_LTR);
26
	final static STextEnvironment envRTL = new STextEnvironment(null, false, STextEnvironment.ORIENT_RTL);
27
	final static STextEnvironment envRTL = new STextEnvironment(null, false, STextEnvironment.ORIENT_RTL);
27
	final static STextEnvironment envRTLMIR = new STextEnvironment(null, true, STextEnvironment.ORIENT_RTL);
28
	final static STextEnvironment envRTLMIR = new STextEnvironment(null, true, STextEnvironment.ORIENT_RTL);
Lines 29-34 Link Here
29
	final static STextEnvironment envCLR = new STextEnvironment(null, false, STextEnvironment.ORIENT_CONTEXTUAL_LTR);
30
	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
	final static STextEnvironment envCRL = new STextEnvironment(null, false, STextEnvironment.ORIENT_CONTEXTUAL_RTL);
31
	final static STextEnvironment envERR = new STextEnvironment(null, false, 9999);
32
	final static STextEnvironment envERR = new STextEnvironment(null, false, 9999);
33
	final static byte AL = Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC;
34
	int dirArabic, dirHebrew;
35
36
	class MyComma extends STextProcessor {
37
38
		public String getSeparators(STextEnvironment environment, String text, byte[] dirProps) {
39
			return ","; //$NON-NLS-1$
40
		}
41
42
		public boolean skipProcessing(STextEnvironment environment, String text, byte[] dirProps) {
43
			byte dirProp = getDirProp(text, dirProps, 0);
44
			if (dirProp == AL)
45
				return true;
46
			return false;
47
		}
48
49
		public int getDirection(STextEnvironment environment, String text, byte[] dirProps) {
50
			for (int i = 0; i < text.length(); i++) {
51
				byte dirProp = getDirProp(text, dirProps, i);
52
				if (dirProp == AL)
53
					return dirArabic;
54
			}
55
			return dirHebrew;
56
		}
57
	}
58
59
	STextProcessor processor;
32
60
33
	private void doTestTools() {
61
	private void doTestTools() {
34
62
Lines 49-68 Link Here
49
		String data, lean, full, model;
77
		String data, lean, full, model;
50
		int[] state = new int[1];
78
		int[] state = new int[1];
51
		state[0] = -1;
79
		state[0] = -1;
52
		String type = ISTextTypes.JAVA;
80
		processor = STextEngine.PROC_JAVA;
53
		data = "A=B+C;/* D=E+F;";
81
		data = "A=B+C;/* D=E+F;";
54
		lean = toUT16(data);
82
		lean = toUT16(data);
55
		full = STextEngine.leanToFullText(type, null, null, lean, state);
83
		full = STextEngine.leanToFullText(processor, null, lean, state);
56
		model = "A@=B@+C@;/* D=E+F;";
84
		model = "A@=B@+C@;/* D=E+F;";
57
		assertEquals("full1", model, toPseudo(full));
85
		assertEquals("full1", model, toPseudo(full));
58
		data = "A=B+C; D=E+F;";
86
		data = "A=B+C; D=E+F;";
59
		lean = toUT16(data);
87
		lean = toUT16(data);
60
		full = STextEngine.leanToFullText(type, null, null, lean, state);
88
		full = STextEngine.leanToFullText(processor, null, lean, state);
61
		model = "A=B+C; D=E+F;";
89
		model = "A=B+C; D=E+F;";
62
		assertEquals("full2", model, toPseudo(full));
90
		assertEquals("full2", model, toPseudo(full));
63
		data = "A=B+C;*/ D=E+F;";
91
		data = "A=B+C;*/ D=E+F;";
64
		lean = toUT16(data);
92
		lean = toUT16(data);
65
		full = STextEngine.leanToFullText(type, null, null, lean, state);
93
		full = STextEngine.leanToFullText(processor, null, lean, state);
66
		model = "A=B+C;@*/ D@=E@+F;";
94
		model = "A=B+C;@*/ D@=E@+F;";
67
		assertEquals("full3", model, toPseudo(full));
95
		assertEquals("full3", model, toPseudo(full));
68
	}
96
	}
Lines 82-169 Link Here
82
		assertEquals("orient #4", STextEnvironment.ORIENT_UNKNOWN, orient);
110
		assertEquals("orient #4", STextEnvironment.ORIENT_UNKNOWN, orient);
83
	}
111
	}
84
112
85
	private void doTestOrient(STextFeatures f, String label, String data, String resLTR, String resRTL, String resCon) {
113
	private void doTestOrient(String label, String data, String resLTR, String resRTL, String resCon) {
86
		String full, lean;
114
		String full, lean;
87
		String type = ISTextTypes.COMMA_DELIMITED;
88
115
89
		lean = toUT16(data);
116
		lean = toUT16(data);
90
		full = STextEngine.leanToFullText(type, f, envLTR, lean, null);
117
		full = STextEngine.leanToFullText(processor, envLTR, lean, null);
91
		assertEquals(label + "LTR full", resLTR, toPseudo(full));
118
		assertEquals(label + "LTR full", resLTR, toPseudo(full));
92
		full = STextEngine.leanToFullText(type, f, envRTL, lean, null);
119
		full = STextEngine.leanToFullText(processor, envRTL, lean, null);
93
		assertEquals("label + RTL full", resRTL, toPseudo(full));
120
		assertEquals("label + RTL full", resRTL, toPseudo(full));
94
		full = STextEngine.leanToFullText(type, f, envCRL, lean, null);
121
		full = STextEngine.leanToFullText(processor, envCRL, lean, null);
95
		assertEquals(label + "CON full", resCon, toPseudo(full));
122
		assertEquals(label + "CON full", resCon, toPseudo(full));
96
	}
123
	}
97
124
98
	private void doTestScripts(STextFeatures f1) {
125
	private void doTestSkipProcessing() {
99
		STextFeatures f2;
126
		processor = new MyComma();
100
		boolean flag;
127
		doTestOrient("Skip #1 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF");
101
		flag = f1.getIgnoreArabic();
128
		doTestOrient("Skip #2 ", "#CD,EF", "#CD,EF", ">@#CD,EF@^", "@#CD,EF");
102
		assertFalse("Ignores Arabic 1", flag);
103
		flag = f1.getIgnoreHebrew();
104
		assertFalse("Ignores Hebrew 1", flag);
105
106
		f2 = new STextFeatures(f1.getSeparators(), 0, -1, -1, true, true);
107
		flag = f2.getIgnoreArabic();
108
		assertTrue("Ignores Arabic 2", flag);
109
		flag = f2.getIgnoreHebrew();
110
		assertTrue("Ignores Hebrew 2", flag);
111
		doTestOrient(f2, "Scripts #1 ", "BCD,EF", "BCD,EF", ">@BCD,EF@^", "@BCD,EF");
112
		f2 = new STextFeatures(f1.getSeparators(), 0, -1, -1, false, true);
113
		flag = f2.getIgnoreArabic();
114
		assertFalse("Ignores Arabic 3", flag);
115
		flag = f2.getIgnoreHebrew();
116
		assertTrue("Ignores Hebrew 3", flag);
117
		doTestOrient(f2, "Scripts #2 ", "d,EF", "d,EF", ">@d,EF@^", "d,EF");
118
		doTestOrient(f2, "Scripts #3 ", "#,eF", "#,eF", ">@#,eF@^", "@#,eF");
119
		doTestOrient(f2, "Scripts #4 ", "#,12", "#@,12", ">@#@,12@^", "@#@,12");
120
		doTestOrient(f2, "Scripts #5 ", "#,##", "#@,##", ">@#@,##@^", "@#@,##");
121
		doTestOrient(f2, "Scripts #6 ", "#,89", "#@,89", ">@#@,89@^", "@#@,89");
122
		doTestOrient(f2, "Scripts #7 ", "#,ef", "#,ef", ">@#,ef@^", "@#,ef");
123
		doTestOrient(f2, "Scripts #8 ", "#,", "#,", ">@#,@^", "@#,");
124
		doTestOrient(f2, "Scripts #9 ", "9,ef", "9,ef", ">@9,ef@^", "9,ef");
125
		doTestOrient(f2, "Scripts #10 ", "9,##", "9@,##", ">@9@,##@^", "9@,##");
126
		doTestOrient(f2, "Scripts #11 ", "7,89", "7@,89", ">@7@,89@^", "7@,89");
127
		doTestOrient(f2, "Scripts #12 ", "7,EF", "7,EF", ">@7,EF@^", "@7,EF");
128
		doTestOrient(f2, "Scripts #13 ", "BCD,EF", "BCD,EF", ">@BCD,EF@^", "@BCD,EF");
129
130
		f2 = new STextFeatures(f1.getSeparators(), 0, -1, -1, true, false);
131
		flag = f2.getIgnoreArabic();
132
		assertTrue("Ignores Arabic 4", flag);
133
		flag = f2.getIgnoreHebrew();
134
		assertFalse("Ignores Hebrew 4", flag);
135
		doTestOrient(f2, "Scripts #14 ", "BCd,EF", "BCd,EF", ">@BCd,EF@^", "@BCd,EF");
136
		doTestOrient(f2, "Scripts #15 ", "BCD,eF", "BCD,eF", ">@BCD,eF@^", "@BCD,eF");
137
		doTestOrient(f2, "Scripts #16 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF");
138
		doTestOrient(f2, "Scripts #17 ", "BCD,12", "BCD@,12", ">@BCD@,12@^", "@BCD@,12");
139
		doTestOrient(f2, "Scripts #18 ", "BCD,", "BCD,", ">@BCD,@^", "@BCD,");
140
141
		f2 = new STextFeatures(f1.getSeparators(), 0, -1, -1, false, false);
142
		doTestOrient(f2, "Scripts #19 ", "123,45|67", "123,45|67", ">@123,45|67@^", "@123,45|67");
143
		doTestOrient(f2, "Scripts #20 ", "5,e", "5,e", ">@5,e@^", "5,e");
144
		doTestOrient(f2, "Scripts #21 ", "5,#", "5@,#", ">@5@,#@^", "5@,#");
145
		doTestOrient(f2, "Scripts #22 ", "5,6", "5@,6", ">@5@,6@^", "5@,6");
146
		doTestOrient(f2, "Scripts #23 ", "5,D", "5@,D", ">@5@,D@^", "5@,D");
147
		doTestOrient(f2, "Scripts #24 ", "5,--", "5,--", ">@5,--@^", "@5,--");
148
	}
129
	}
149
130
150
	private void doTestLeanOffsets() {
131
	private void doTestLeanOffsets() {
151
		String lean, data, label;
132
		String lean, data, label;
152
		int[] state = new int[1];
133
		int[] state = new int[1];
153
		String type = ISTextTypes.JAVA;
134
		processor = STextEngine.PROC_JAVA;
154
		int[] offsets;
135
		int[] offsets;
155
		int[] model;
136
		int[] model;
156
137
157
		data = "A=B+C;/* D=E+F;";
138
		data = "A=B+C;/* D=E+F;";
158
		lean = toUT16(data);
139
		lean = toUT16(data);
159
		state[0] = -1;
140
		state[0] = -1;
160
		offsets = STextEngine.leanBidiCharOffsets(type, null, null, lean, state);
141
		offsets = STextEngine.leanBidiCharOffsets(processor, null, lean, state);
161
		model = new int[] {1, 3, 5};
142
		model = new int[] {1, 3, 5};
162
		label = "leanBidiCharOffsets() #1 ";
143
		label = "leanBidiCharOffsets() #1 ";
163
		assertEquals(label, array_display(model), array_display(offsets));
144
		assertEquals(label, array_display(model), array_display(offsets));
164
		data = "A=B+C;*/ D=E+F;";
145
		data = "A=B+C;*/ D=E+F;";
165
		lean = toUT16(data);
146
		lean = toUT16(data);
166
		offsets = STextEngine.leanBidiCharOffsets(type, null, null, lean, state);
147
		offsets = STextEngine.leanBidiCharOffsets(processor, null, lean, state);
167
		model = new int[] {6, 10, 12};
148
		model = new int[] {6, 10, 12};
168
		label = "leanBidiCharOffsets() #2 ";
149
		label = "leanBidiCharOffsets() #2 ";
169
		assertEquals(label, array_display(model), array_display(offsets));
150
		assertEquals(label, array_display(model), array_display(offsets));
Lines 172-190 Link Here
172
	private void doTestFullOffsets(String label, String data, int[] resLTR, int[] resRTL, int[] resCon) {
153
	private void doTestFullOffsets(String label, String data, int[] resLTR, int[] resRTL, int[] resCon) {
173
		String full, lean, msg;
154
		String full, lean, msg;
174
		int[] offsets;
155
		int[] offsets;
175
		String type = ISTextTypes.COMMA_DELIMITED;
156
		processor = STextEngine.PROC_COMMA_DELIMITED;
176
157
177
		lean = toUT16(data);
158
		lean = toUT16(data);
178
		full = STextEngine.leanToFullText(type, null, envLTR, lean, null);
159
		full = STextEngine.leanToFullText(processor, envLTR, lean, null);
179
		offsets = STextEngine.fullBidiCharOffsets(type, null, envLTR, full, null);
160
		offsets = STextEngine.fullBidiCharOffsets(processor, envLTR, full, null);
180
		msg = label + "LTR ";
161
		msg = label + "LTR ";
181
		assertEquals(msg, array_display(resLTR), array_display(offsets));
162
		assertEquals(msg, array_display(resLTR), array_display(offsets));
182
		full = STextEngine.leanToFullText(type, null, envRTL, lean, null);
163
		full = STextEngine.leanToFullText(processor, envRTL, lean, null);
183
		offsets = STextEngine.fullBidiCharOffsets(type, null, envRTL, full, null);
164
		offsets = STextEngine.fullBidiCharOffsets(processor, envRTL, full, null);
184
		msg = label + "RTL ";
165
		msg = label + "RTL ";
185
		assertEquals(msg, array_display(resRTL), array_display(offsets));
166
		assertEquals(msg, array_display(resRTL), array_display(offsets));
186
		full = STextEngine.leanToFullText(type, null, envCLR, lean, null);
167
		full = STextEngine.leanToFullText(processor, envCLR, lean, null);
187
		offsets = STextEngine.fullBidiCharOffsets(type, null, envCLR, full, null);
168
		offsets = STextEngine.fullBidiCharOffsets(processor, envCLR, full, null);
188
		msg = label + "CON ";
169
		msg = label + "CON ";
189
		assertEquals(msg, array_display(resCon), array_display(offsets));
170
		assertEquals(msg, array_display(resCon), array_display(offsets));
190
	}
171
	}
Lines 200-278 Link Here
200
181
201
	private void doTestDirection() {
182
	private void doTestDirection() {
202
		String data, lean, full, model, msg;
183
		String data, lean, full, model, msg;
203
		ISTextProcessor processor = STextStringProcessor.getProcessor(ISTextTypes.COMMA_DELIMITED);
184
		int dirA, dirH;
204
		STextFeatures f1 = processor.getFeatures(null);
185
		processor = new MyComma();
186
		dirArabic = RTL;
187
		dirHebrew = LTR;
205
		msg = "TestDirection #1";
188
		msg = "TestDirection #1";
206
		assertTrue(msg, f1.getDirArabic() == LTR && f1.getDirHebrew() == LTR);
189
		dirA = processor.getDirection(null, toUT16("###"), null);
190
		dirH = processor.getDirection(null, toUT16("ABC"), null);
191
		assertTrue(msg, dirA == RTL && dirH == LTR);
207
192
208
		STextFeatures f2 = new STextFeatures(f1.getSeparators(), 0, RTL, RTL, false, false);
193
		dirArabic = RTL;
209
		f1 = f2;
194
		dirHebrew = RTL;
210
		msg = "TestDirection #2";
195
		msg = "TestDirection #2";
211
		assertTrue(msg, f1.getDirArabic() == RTL && f1.getDirHebrew() == RTL);
196
		dirA = processor.getDirection(null, toUT16("###"), null);
197
		dirH = processor.getDirection(null, toUT16("ABC"), null);
198
		assertTrue(msg, dirA == RTL && dirH == RTL);
212
199
213
		STextEnvironment environment = new STextEnvironment(null, false, STextEnvironment.ORIENT_LTR);
200
		dirArabic = dirHebrew = LTR;
214
		processor = STextStringProcessor.getProcessor(ISTextTypes.EMAIL);
215
		f1 = processor.getFeatures(environment);
216
		msg = "TestDirection #3";
201
		msg = "TestDirection #3";
217
		assertTrue(msg, f1.getDirArabic() == LTR && f1.getDirHebrew() == LTR);
202
		data = "ABC,#DEF,HOST,com";
218
		data = "#ABC.#DEF:HOST.com";
219
		lean = toUT16(data);
203
		lean = toUT16(data);
220
		full = STextEngine.leanToFullText(processor, null, environment, lean, null);
204
		full = STextEngine.leanToFullText(processor, null, lean, null);
221
		model = "#ABC@.#DEF@:HOST.com";
205
		model = "ABC@,#DEF@,HOST,com";
222
		assertEquals("TestDirection #9 full", model, toPseudo(full));
206
		assertEquals("TestDirection #9 full", model, toPseudo(full));
223
207
224
		data = "ABC.DEF:HOST.com";
208
		data = "ABC,DEF,HOST,com";
225
		lean = toUT16(data);
209
		lean = toUT16(data);
226
		full = STextEngine.leanToFullText(processor, null, environment, lean, null);
210
		full = STextEngine.leanToFullText(processor, null, lean, null);
227
		model = "ABC@.DEF@:HOST.com";
211
		model = "ABC@,DEF@,HOST,com";
228
		assertEquals("TestDirection #10 full", model, toPseudo(full));
212
		assertEquals("TestDirection #10 full", model, toPseudo(full));
229
213
230
		environment = new STextEnvironment(null, true, STextEnvironment.ORIENT_LTR);
214
		dirArabic = RTL;
231
		f1 = processor.getFeatures(environment);
232
		msg = "TestDirection #10.5";
215
		msg = "TestDirection #10.5";
233
		assertTrue(msg, f1.getDirArabic() == RTL && f1.getDirHebrew() == LTR);
216
		dirA = processor.getDirection(null, toUT16("###"), null);
234
		data = "#ABC.#DEF:HOST.com";
217
		dirH = processor.getDirection(null, toUT16("ABC"), null);
218
		assertTrue(msg, dirA == RTL && dirH == LTR);
219
		STextEnvironment environment = new STextEnvironment(null, true, STextEnvironment.ORIENT_LTR);
220
		data = "ABC,#DEF,HOST,com";
235
		lean = toUT16(data);
221
		lean = toUT16(data);
236
		full = STextEngine.leanToFullText(processor, null, environment, lean, null);
222
		full = STextEngine.leanToFullText(processor, environment, lean, null);
237
		model = "<&#ABC.#DEF:HOST.com&^";
223
		model = "<&ABC,#DEF,HOST,com&^";
238
		assertEquals("TestDirection #11 full", model, toPseudo(full));
224
		assertEquals("TestDirection #11 full", model, toPseudo(full));
239
225
240
		data = "#ABc.#DEF:HOSt.COM";
226
		data = "ABc,#DEF,HOSt,COM";
241
		lean = toUT16(data);
227
		lean = toUT16(data);
242
		full = STextEngine.leanToFullText(processor, null, environment, lean, null);
228
		full = STextEngine.leanToFullText(processor, environment, lean, null);
243
		model = "<&#ABc.#DEF:HOSt.COM&^";
229
		model = "<&ABc,#DEF,HOSt,COM&^";
244
		assertEquals("TestDirection #12 full", model, toPseudo(full));
230
		assertEquals("TestDirection #12 full", model, toPseudo(full));
245
231
246
		data = "#ABc.#DEF:HOSt.";
232
		data = "ABc,#DEF,HOSt,";
247
		lean = toUT16(data);
233
		lean = toUT16(data);
248
		full = STextEngine.leanToFullText(processor, null, environment, lean, null);
234
		full = STextEngine.leanToFullText(processor, environment, lean, null);
249
		model = "<&#ABc.#DEF:HOSt.&^";
235
		model = "<&ABc,#DEF,HOSt,&^";
250
		assertEquals("TestDirection #13 full", model, toPseudo(full));
236
		assertEquals("TestDirection #13 full", model, toPseudo(full));
251
237
252
		data = "ABC.DEF:HOST.com";
238
		data = "ABC,DEF,HOST,com";
253
		lean = toUT16(data);
239
		lean = toUT16(data);
254
		full = STextEngine.leanToFullText(processor, null, environment, lean, null);
240
		full = STextEngine.leanToFullText(processor, environment, lean, null);
255
		model = "ABC@.DEF@:HOST.com";
241
		model = "ABC@,DEF@,HOST,com";
256
		assertEquals("TestDirection #14 full", model, toPseudo(full));
242
		assertEquals("TestDirection #14 full", model, toPseudo(full));
257
243
258
		data = "--.---:----";
244
		data = "--,---,----";
259
		lean = toUT16(data);
245
		lean = toUT16(data);
260
		full = STextEngine.leanToFullText(processor, null, environment, lean, null);
246
		full = STextEngine.leanToFullText(processor, environment, lean, null);
261
		model = "--.---:----";
247
		model = "--,---,----";
262
		assertEquals("TestDirection #15 full", model, toPseudo(full));
248
		assertEquals("TestDirection #15 full", model, toPseudo(full));
263
249
264
		data = "ABC.|DEF:HOST.com";
250
		data = "ABC,|DEF,HOST,com";
265
		lean = toUT16(data);
251
		lean = toUT16(data);
266
		full = STextEngine.leanToFullText(processor, null, environment, lean, null);
252
		full = STextEngine.leanToFullText(processor, environment, lean, null);
267
		model = "ABC.|DEF@:HOST.com";
253
		model = "ABC,|DEF@,HOST,com";
268
		assertEquals("TestDirection #16 full", model, toPseudo(full));
254
		assertEquals("TestDirection #16 full", model, toPseudo(full));
269
255
270
		data = "#ABc.|#DEF:HOST.com";
256
		data = "ABc,|#DEF,HOST,com";
271
		lean = toUT16(data);
257
		lean = toUT16(data);
272
		full = STextEngine.leanToFullText(processor, null, envRTLMIR, lean, null);
258
		full = STextEngine.leanToFullText(processor, envRTLMIR, lean, null);
273
		model = "#ABc.|#DEF:HOST.com";
259
		model = "ABc,|#DEF,HOST,com";
274
		assertEquals("TestDirection #17 full", model, toPseudo(full));
260
		assertEquals("TestDirection #17 full", model, toPseudo(full));
275
		assertEquals("Test curDirection", RTL, STextEngine.getCurDirection(processor, null, envRTLMIR, lean));
261
		assertEquals("Test curDirection", RTL, STextEngine.getCurDirection(processor, envRTLMIR, lean));
276
	}
262
	}
277
263
278
	public void testMethods() {
264
	public void testMethods() {
Lines 283-301 Link Here
283
269
284
		doTestOrientation();
270
		doTestOrientation();
285
271
286
		ISTextProcessor processor = STextStringProcessor.getProcessor(ISTextTypes.COMMA_DELIMITED);
272
		processor = STextEngine.PROC_COMMA_DELIMITED;
287
		STextFeatures f = processor.getFeatures(null);
273
		doTestOrient("Methods #1 ", "", "", "", "");
288
		doTestOrient(f, "Methods #1 ", "", "", "", "");
274
		doTestOrient("Methods #2 ", "abc", "abc", ">@abc@^", "abc");
289
		doTestOrient(f, "Methods #2 ", "abc", "abc", ">@abc@^", "abc");
275
		doTestOrient("Methods #3 ", "ABC", "ABC", ">@ABC@^", "@ABC");
290
		doTestOrient(f, "Methods #3 ", "ABC", "ABC", ">@ABC@^", "@ABC");
276
		doTestOrient("Methods #4 ", "bcd,ef", "bcd,ef", ">@bcd,ef@^", "bcd,ef");
291
		doTestOrient(f, "Methods #4 ", "bcd,ef", "bcd,ef", ">@bcd,ef@^", "bcd,ef");
277
		doTestOrient("Methods #5 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF");
292
		doTestOrient(f, "Methods #5 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF");
278
		doTestOrient("Methods #6 ", "cde,FG", "cde,FG", ">@cde,FG@^", "cde,FG");
293
		doTestOrient(f, "Methods #6 ", "cde,FG", "cde,FG", ">@cde,FG@^", "cde,FG");
279
		doTestOrient("Methods #7 ", "CDE,fg", "CDE,fg", ">@CDE,fg@^", "@CDE,fg");
294
		doTestOrient(f, "Methods #7 ", "CDE,fg", "CDE,fg", ">@CDE,fg@^", "@CDE,fg");
280
		doTestOrient("Methods #8 ", "12..def,GH", "12..def,GH", ">@12..def,GH@^", "12..def,GH");
295
		doTestOrient(f, "Methods #8 ", "12..def,GH", "12..def,GH", ">@12..def,GH@^", "12..def,GH");
281
		doTestOrient("Methods #9 ", "34..DEF,gh", "34..DEF,gh", ">@34..DEF,gh@^", "@34..DEF,gh");
296
		doTestOrient(f, "Methods #9 ", "34..DEF,gh", "34..DEF,gh", ">@34..DEF,gh@^", "@34..DEF,gh");
297
282
298
		doTestScripts(f);
283
		doTestSkipProcessing();
299
284
300
		doTestLeanOffsets();
285
		doTestLeanOffsets();
301
286
Lines 305-314 Link Here
305
290
306
		doTestDirection();
291
		doTestDirection();
307
292
308
		String type = ISTextTypes.COMMA_DELIMITED;
293
		processor = STextEngine.PROC_COMMA_DELIMITED;
309
		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";
294
		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";
310
		String lean = toUT16(data);
295
		String lean = toUT16(data);
311
		String full = STextEngine.leanToFullText(type, null, null, lean, null);
296
		String full = STextEngine.leanToFullText(processor, null, lean, null);
312
		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";
297
		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";
313
		assertEquals("many inserts", model, toPseudo(full));
298
		assertEquals("many inserts", model, toPseudo(full));
314
	}
299
	}
(-)src/org/eclipse/equinox/bidi/internal/tests/STextNullProcessorTest.java (-11 / +10 lines)
Lines 12-18 Link Here
12
package org.eclipse.equinox.bidi.internal.tests;
12
package org.eclipse.equinox.bidi.internal.tests;
13
13
14
import org.eclipse.equinox.bidi.STextEngine;
14
import org.eclipse.equinox.bidi.STextEngine;
15
import org.eclipse.equinox.bidi.custom.STextFeatures;
16
15
17
/**
16
/**
18
 * Tests RTL arithmetic
17
 * Tests RTL arithmetic
Lines 22-47 Link Here
22
	static final int[] EMPTY_INT_ARRAY = new int[0];
21
	static final int[] EMPTY_INT_ARRAY = new int[0];
23
22
24
	public void testNullProcessor() {
23
	public void testNullProcessor() {
25
		String full = STextEngine.leanToFullText(null, null, null, "abc", null);
24
		String full = STextEngine.leanToFullText(null, null, "abc", null);
26
		assertEquals("leanToFullText", "abc", full);
25
		assertEquals("leanToFullText", "abc", full);
27
		int[] state = new int[1];
26
		int[] state = new int[1];
28
		state[0] = 3;
27
		state[0] = 3;
29
		full = STextEngine.leanToFullText(null, null, null, "abc", state);
28
		full = STextEngine.leanToFullText(null, null, "abc", state);
30
		assertEquals("leanToFullText with state", "abc", full);
29
		assertEquals("leanToFullText with state", "abc", full);
31
		int[] offsets = STextEngine.leanBidiCharOffsets(null, null, null, "abc", null);
30
		int[] offsets = STextEngine.leanBidiCharOffsets(null, null, "abc", null);
32
		assertEquals("leanBidiCharOffsets", 0, offsets.length);
31
		assertEquals("leanBidiCharOffsets", 0, offsets.length);
33
		offsets = STextEngine.fullBidiCharOffsets(null, null, null, "abc", null);
32
		offsets = STextEngine.fullBidiCharOffsets(null, null, "abc", null);
34
		assertEquals("fullBidiCharOffsets", 0, offsets.length);
33
		assertEquals("fullBidiCharOffsets", 0, offsets.length);
35
		String lean = STextEngine.fullToLeanText(null, null, null, "abc", null);
34
		String lean = STextEngine.fullToLeanText(null, null, "abc", null);
36
		assertEquals("fullToLeanText", "abc", lean);
35
		assertEquals("fullToLeanText", "abc", lean);
37
		lean = STextEngine.fullToLeanText(null, null, null, "abc", state);
36
		lean = STextEngine.fullToLeanText(null, null, "abc", state);
38
		assertEquals("fullToLeanText with state", "abc", lean);
37
		assertEquals("fullToLeanText with state", "abc", lean);
39
		int[] map = STextEngine.leanToFullMap(null, null, null, "abc", null);
38
		int[] map = STextEngine.leanToFullMap(null, null, "abc", null);
40
		int[] model = {0, 1, 2};
39
		int[] model = {0, 1, 2};
41
		assertEquals("leanToFullMap", array_display(model), array_display(map));
40
		assertEquals("leanToFullMap", array_display(model), array_display(map));
42
		map = STextEngine.fullToLeanMap(null, null, null, "abc", null);
41
		map = STextEngine.fullToLeanMap(null, null, "abc", null);
43
		assertEquals("fullToLeanMap", array_display(model), array_display(map));
42
		assertEquals("fullToLeanMap", array_display(model), array_display(map));
44
		int direction = STextEngine.getCurDirection(null, null, null, "abc");
43
		int direction = STextEngine.getCurDirection(null, null, "abc");
45
		assertEquals("getCurDirection", STextFeatures.DIR_LTR, direction);
44
		assertEquals("getCurDirection", STextEngine.DIR_LTR, direction);
46
	}
45
	}
47
}
46
}
(-)src/org/eclipse/equinox/bidi/internal/tests/STextSomeMoreTest.java (-16 / +16 lines)
Lines 13-19 Link Here
13
13
14
import org.eclipse.equinox.bidi.STextEngine;
14
import org.eclipse.equinox.bidi.STextEngine;
15
import org.eclipse.equinox.bidi.STextEnvironment;
15
import org.eclipse.equinox.bidi.STextEnvironment;
16
import org.eclipse.equinox.bidi.custom.*;
16
import org.eclipse.equinox.bidi.custom.STextProcessor;
17
17
18
/**
18
/**
19
 * Tests some weird cases
19
 * Tests some weird cases
Lines 23-41 Link Here
23
23
24
	final static STextEnvironment env1 = new STextEnvironment("en_US", false, STextEnvironment.ORIENT_LTR);
24
	final static STextEnvironment env1 = new STextEnvironment("en_US", false, STextEnvironment.ORIENT_LTR);
25
	final static STextEnvironment env2 = new STextEnvironment("he", false, STextEnvironment.ORIENT_LTR);
25
	final static STextEnvironment env2 = new STextEnvironment("he", false, STextEnvironment.ORIENT_LTR);
26
	final static STextFeatures myFeatures = new STextFeatures(null, 1, -1, -1, false, false);
27
26
28
	class Processor1 extends STextProcessor {
27
	class Processor1 extends STextProcessor {
29
28
30
		public STextFeatures getFeatures(STextEnvironment env) {
29
		public int getSpecialsCount(STextEnvironment env, String text, byte[] dirProps) {
31
			return myFeatures;
30
			return 1;
32
		}
31
		}
33
32
34
		public int indexOfSpecial(STextFeatures features, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
33
		public int indexOfSpecial(STextEnvironment env, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
35
			return fromIndex;
34
			return fromIndex;
36
		}
35
		}
37
36
38
		public int processSpecial(STextFeatures features, String text, byte[] dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
37
		public int processSpecial(STextEnvironment env, String text, byte[] dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
39
			int len = text.length();
38
			int len = text.length();
40
			for (int i = len - 1; i >= 0; i--) {
39
			for (int i = len - 1; i >= 0; i--) {
41
				STextProcessor.insertMark(text, dirProps, offsets, i);
40
				STextProcessor.insertMark(text, dirProps, offsets, i);
Lines 47-65 Link Here
47
46
48
	class Processor2 extends STextProcessor {
47
	class Processor2 extends STextProcessor {
49
48
50
		public STextFeatures getFeatures(STextEnvironment env) {
49
		public int getSpecialsCount(STextEnvironment env, String text, byte[] dirProps) {
51
			return myFeatures;
50
			return 1;
52
		}
51
		}
52
53
	}
53
	}
54
54
55
	class Processor3 extends STextProcessor {
55
	class Processor3 extends STextProcessor {
56
56
57
		public STextFeatures getFeatures(STextEnvironment env) {
57
		public int getSpecialsCount(STextEnvironment env, String text, byte[] dirProps) {
58
			return myFeatures;
58
			return 1;
59
		}
59
		}
60
60
61
		public int indexOfSpecial(STextFeatures features, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
61
		public int indexOfSpecial(STextEnvironment env, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
62
			return 0;
62
			return fromIndex;
63
		}
63
		}
64
	}
64
	}
65
65
Lines 67-80 Link Here
67
		assertFalse(env1.isBidi());
67
		assertFalse(env1.isBidi());
68
		assertTrue(env2.isBidi());
68
		assertTrue(env2.isBidi());
69
69
70
		ISTextProcessor processor = new Processor1();
70
		STextProcessor processor = new Processor1();
71
		String full = STextEngine.leanToFullText(processor, null, env1, "abcd", null);
71
		String full = STextEngine.leanToFullText(processor, env1, "abcd", null);
72
		assertEquals("@a@b@c@d", toPseudo(full));
72
		assertEquals("@a@b@c@d", toPseudo(full));
73
73
74
		processor = new Processor2();
74
		processor = new Processor2();
75
		boolean catchFlag = false;
75
		boolean catchFlag = false;
76
		try {
76
		try {
77
			full = STextEngine.leanToFullText(processor, null, env1, "abcd", null);
77
			full = STextEngine.leanToFullText(processor, env1, "abcd", null);
78
		} catch (IllegalStateException e) {
78
		} catch (IllegalStateException e) {
79
			catchFlag = true;
79
			catchFlag = true;
80
		}
80
		}
Lines 83-89 Link Here
83
		processor = new Processor3();
83
		processor = new Processor3();
84
		catchFlag = false;
84
		catchFlag = false;
85
		try {
85
		try {
86
			full = STextEngine.leanToFullText(processor, null, env1, "abcd", null);
86
			full = STextEngine.leanToFullText(processor, env1, "abcd", null);
87
		} catch (IllegalStateException e) {
87
		} catch (IllegalStateException e) {
88
			catchFlag = true;
88
			catchFlag = true;
89
		}
89
		}
(-)src/org/eclipse/equinox/bidi/internal/tests/STextStringRecordTest.java (-47 / +71 lines)
Lines 11-18 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.STextEngine;
14
import org.eclipse.equinox.bidi.STextStringRecord;
15
import org.eclipse.equinox.bidi.STextStringRecord;
15
import org.eclipse.equinox.bidi.custom.STextStringProcessor;
16
16
17
/**
17
/**
18
 *	Tests the StringRecord class	
18
 *	Tests the StringRecord class	
Lines 21-119 Link Here
21
	public void testStringRecord() {
21
	public void testStringRecord() {
22
		STextStringRecord sr;
22
		STextStringRecord sr;
23
		boolean catchFlag;
23
		boolean catchFlag;
24
		short[] badTriplet1 = new short[] {0, 0};
25
		short[] badTriplet2 = new short[] {0, 0, -1};
26
		short[] badTriplet3 = new short[] {0, 0, 999};
27
		short[] goodTriplet = new short[] {0, 3, 2};
28
		short[] triplets;
29
		short type;
30
		String strType;
31
		// check handling of invalid arguments
24
		// check handling of invalid arguments
32
		catchFlag = false;
25
		catchFlag = false;
33
		try {
26
		try {
34
			sr = new STextStringRecord(null, badTriplet1);
27
			sr = STextStringRecord.addRecord(null, 1, STextEngine.PROC_EMAIL, 0, 1);
35
		} catch (IllegalArgumentException e) {
28
		} catch (IllegalArgumentException e) {
36
			catchFlag = true;
29
			catchFlag = true;
37
		}
30
		}
38
		assertTrue("Catch null string argument", catchFlag);
31
		assertTrue("Catch null string argument", catchFlag);
39
		catchFlag = false;
32
		catchFlag = false;
40
		try {
33
		try {
41
			sr = new STextStringRecord("xxx", null);
34
			sr = STextStringRecord.addRecord("abc", 1, null, 0, 1);
42
		} catch (IllegalArgumentException e) {
35
		} catch (IllegalArgumentException e) {
43
			catchFlag = true;
36
			catchFlag = true;
44
		}
37
		}
45
		assertTrue("Catch null triplets argument", catchFlag);
38
		assertTrue("Catch null processor argument", catchFlag);
46
		catchFlag = false;
39
		catchFlag = false;
47
		try {
40
		try {
48
			sr = new STextStringRecord("xxx", badTriplet1);
41
			sr = STextStringRecord.addRecord("abc", 0, STextEngine.PROC_EMAIL, 0, 1);
49
		} catch (IllegalArgumentException e) {
42
		} catch (IllegalArgumentException e) {
50
			catchFlag = true;
43
			catchFlag = true;
51
		}
44
		}
52
		assertTrue("Catch bad triplet #1 argument", catchFlag);
45
		assertTrue("Catch invalid segment count argument", catchFlag);
53
		catchFlag = false;
46
		catchFlag = false;
54
		try {
47
		try {
55
			sr = new STextStringRecord("xxx", badTriplet2);
48
			sr = STextStringRecord.addRecord("abc", 1, STextEngine.PROC_EMAIL, -1, 1);
56
		} catch (IllegalArgumentException e) {
49
		} catch (IllegalArgumentException e) {
57
			catchFlag = true;
50
			catchFlag = true;
58
		}
51
		}
59
		assertTrue("Catch bad triplet #2 argument", catchFlag);
52
		assertTrue("Catch invalid start argument", catchFlag);
60
		catchFlag = false;
53
		catchFlag = false;
61
		try {
54
		try {
62
			sr = new STextStringRecord("xxx", badTriplet3);
55
			sr = STextStringRecord.addRecord("abc", 1, STextEngine.PROC_EMAIL, 4, 1);
63
		} catch (IllegalArgumentException e) {
56
		} catch (IllegalArgumentException e) {
64
			catchFlag = true;
57
			catchFlag = true;
65
		}
58
		}
66
		assertTrue("Catch bad triplet #3 argument", catchFlag);
59
		assertTrue("Catch invalid start argument", catchFlag);
60
		catchFlag = false;
61
		try {
62
			sr = STextStringRecord.addRecord("abc", 1, STextEngine.PROC_EMAIL, 0, 0);
63
		} catch (IllegalArgumentException e) {
64
			catchFlag = true;
65
		}
66
		assertTrue("Catch invalid limit argument", catchFlag);
67
		catchFlag = false;
68
		try {
69
			sr = STextStringRecord.addRecord("abc", 1, STextEngine.PROC_EMAIL, 0, 5);
70
		} catch (IllegalArgumentException e) {
71
			catchFlag = true;
72
		}
73
		assertTrue("Catch invalid limit argument", catchFlag);
67
74
68
		String[] types = STextStringProcessor.getKnownTypes();
69
		for (int i = 0; i < types.length; i++) {
70
			type = STextStringRecord.typeStringToShort(types[i]);
71
			assertFalse(type == -1);
72
			strType = STextStringRecord.typeShortToString(type);
73
			assertEquals(types[i], strType);
74
		}
75
		type = STextStringRecord.typeStringToShort("dummy");
76
		assertEquals(-1, type);
77
		strType = STextStringRecord.typeShortToString((short) 999);
78
		assertEquals(null, strType);
79
		int poolSize = STextStringRecord.POOLSIZE;
75
		int poolSize = STextStringRecord.POOLSIZE;
80
		int lim = poolSize / 2;
76
		int lim = poolSize / 2;
81
		triplets = STextStringRecord.getTriplets("xxx");
77
		sr = STextStringRecord.getRecord("XXX");
82
		assertEquals(null, triplets);
78
		assertEquals(null, sr);
83
		for (int i = 0; i < lim; i++) {
79
		for (int i = 0; i < lim; i++) {
84
			String str = Integer.toString(i);
80
			String str = Integer.toString(i);
85
			sr = new STextStringRecord(str, goodTriplet);
81
			sr = STextStringRecord.addRecord(str, 1, STextEngine.PROC_EMAIL, 0, 1);
86
			STextStringRecord.add(sr);
87
		}
82
		}
88
		triplets = STextStringRecord.getTriplets(null);
83
		sr = STextStringRecord.getRecord(null);
89
		assertEquals(null, triplets);
84
		assertEquals(null, sr);
90
		triplets = STextStringRecord.getTriplets("");
85
		sr = STextStringRecord.getRecord("");
91
		assertEquals(null, triplets);
86
		assertEquals(null, sr);
87
92
		for (int i = 0; i < poolSize; i++) {
88
		for (int i = 0; i < poolSize; i++) {
93
			String str = Integer.toString(i);
89
			String str = Integer.toString(i);
94
			triplets = STextStringRecord.getTriplets(str);
90
			sr = STextStringRecord.getRecord(str);
95
			if (i < lim)
91
			if (i < lim)
96
				assertFalse(null == triplets);
92
				assertFalse(null == sr);
97
			else
93
			else
98
				assertTrue(null == triplets);
94
				assertTrue(null == sr);
99
		}
95
		}
96
100
		for (int i = lim; i <= poolSize; i++) {
97
		for (int i = lim; i <= poolSize; i++) {
101
			String str = Integer.toString(i);
98
			String str = Integer.toString(i);
102
			sr = new STextStringRecord(str, goodTriplet);
99
			sr = STextStringRecord.addRecord(str, 1, STextEngine.PROC_EMAIL, 0, 1);
103
			STextStringRecord.add(sr);
104
		}
100
		}
105
		for (int i = 1; i <= poolSize; i++) {
101
		for (int i = 1; i <= poolSize; i++) {
106
			String str = Integer.toString(i);
102
			String str = Integer.toString(i);
107
			triplets = STextStringRecord.getTriplets(str);
103
			sr = STextStringRecord.getRecord(str);
108
			assertFalse(null == triplets);
104
			assertFalse(null == sr);
105
		}
106
		sr = STextStringRecord.getRecord("0");
107
		assertEquals(null, sr);
108
		sr = STextStringRecord.addRecord("thisisalongstring", 3, STextEngine.PROC_EMAIL, 0, 2);
109
		sr.addSegment(STextEngine.PROC_JAVA, 4, 5);
110
		sr.addSegment(STextEngine.PROC_FILE, 6, 7);
111
		catchFlag = false;
112
		try {
113
			sr.addSegment(STextEngine.PROC_EMAIL, 10, 13);
114
		} catch (IllegalStateException e) {
115
			catchFlag = true;
109
		}
116
		}
110
		triplets = STextStringRecord.getTriplets("0");
117
		assertTrue("Catch too many segments", catchFlag);
111
		assertEquals(null, triplets);
118
		assertEquals(3, sr.getSegmentCount());
119
		assertEquals(STextEngine.PROC_EMAIL, sr.getProcessor(0));
120
		assertEquals(STextEngine.PROC_JAVA, sr.getProcessor(1));
121
		assertEquals(STextEngine.PROC_FILE, sr.getProcessor(2));
122
		assertEquals(0, sr.getStart(0));
123
		assertEquals(4, sr.getStart(1));
124
		assertEquals(6, sr.getStart(2));
125
		assertEquals(2, sr.getLimit(0));
126
		assertEquals(5, sr.getLimit(1));
127
		assertEquals(7, sr.getLimit(2));
128
		catchFlag = false;
129
		try {
130
			sr.getLimit(3);
131
		} catch (IllegalArgumentException e) {
132
			catchFlag = true;
133
		}
134
		assertTrue("Catch segment number too large", catchFlag);
135
112
		STextStringRecord.clear();
136
		STextStringRecord.clear();
113
		for (int i = 0; i <= poolSize; i++) {
137
		for (int i = 0; i <= poolSize; i++) {
114
			String str = Integer.toString(i);
138
			String str = Integer.toString(i);
115
			triplets = STextStringRecord.getTriplets(str);
139
			sr = STextStringRecord.getRecord(str);
116
			assertEquals(null, triplets);
140
			assertEquals(null, sr);
117
		}
141
		}
118
	}
142
	}
119
}
143
}
(-)src/org/eclipse/equinox/bidi/internal/tests/STextTest.java (-15 / +4 lines)
Lines 11-33 Link Here
11
package org.eclipse.equinox.bidi.internal.tests;
11
package org.eclipse.equinox.bidi.internal.tests;
12
12
13
import org.eclipse.equinox.bidi.STextEnvironment;
13
import org.eclipse.equinox.bidi.STextEnvironment;
14
import org.eclipse.equinox.bidi.custom.STextFeatures;
14
import org.eclipse.equinox.bidi.custom.STextProcessor;
15
import org.eclipse.equinox.bidi.custom.ISTextProcessor;
16
15
17
public class STextTest implements ISTextProcessor {
16
public class STextTest extends STextProcessor {
18
17
19
	static final STextFeatures FEATURES = new STextFeatures("-=.:", 0, -1, -1, false, false);
18
	public String getSeparators(STextEnvironment env, String text, byte[] dirProps) {
20
19
		return "-=.:";
21
	public STextFeatures getFeatures(STextEnvironment env) {
22
		return FEATURES;
23
	}
24
25
	public int indexOfSpecial(STextFeatures features, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
26
		throw new IllegalStateException();
27
	}
28
29
	public int processSpecial(STextFeatures features, String text, byte[] dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
30
		throw new IllegalStateException();
31
	}
20
	}
32
21
33
}
22
}
(-)src/org/eclipse/equinox/bidi/internal/tests/STextUtilTest.java (-17 / +3 lines)
Lines 12-19 Link Here
12
package org.eclipse.equinox.bidi.internal.tests;
12
package org.eclipse.equinox.bidi.internal.tests;
13
13
14
import java.util.Locale;
14
import java.util.Locale;
15
import org.eclipse.equinox.bidi.STextEngine;
15
import org.eclipse.equinox.bidi.STextUtil;
16
import org.eclipse.equinox.bidi.STextUtil;
16
import org.eclipse.equinox.bidi.ISTextTypes;
17
17
18
/**
18
/**
19
 * Tests methods in BidiComplexUtil
19
 * Tests methods in BidiComplexUtil
Lines 83-91 Link Here
83
	}
83
	}
84
84
85
	private void doTest3(String msg, String data, String result, String resLean) {
85
	private void doTest3(String msg, String data, String result, String resLean) {
86
		String full = STextUtil.processTyped(toUT16(data), ISTextTypes.COMMA_DELIMITED);
86
		String full = STextUtil.processTyped(toUT16(data), STextEngine.PROC_COMMA_DELIMITED);
87
		assertEquals(msg + "full", result, toPseudo(full));
87
		assertEquals(msg + "full", result, toPseudo(full));
88
		String lean = STextUtil.deprocess(full, ISTextTypes.COMMA_DELIMITED);
88
		String lean = STextUtil.deprocess(full, STextEngine.PROC_COMMA_DELIMITED);
89
		assertEquals(msg + "lean", resLean, toPseudo(lean));
89
		assertEquals(msg + "lean", resLean, toPseudo(lean));
90
	}
90
	}
91
91
Lines 111-130 Link Here
111
		doTest3("Util #3.1 - ", "ABC,DEF,G", ">@ABC@,DEF@,G@^");
111
		doTest3("Util #3.1 - ", "ABC,DEF,G", ">@ABC@,DEF@,G@^");
112
		doTest3("Util #3.2 - ", "", "");
112
		doTest3("Util #3.2 - ", "", "");
113
		doTest3("Util #3.3 - ", ">@DEF@^", ">@DEF@^", "DEF");
113
		doTest3("Util #3.3 - ", ">@DEF@^", ">@DEF@^", "DEF");
114
		boolean catchFlag = false;
115
		try {
116
			STextUtil.deprocess(toUT16("ABC,DE"), "wrong_type");
117
		} catch (IllegalArgumentException e) {
118
			catchFlag = true;
119
		}
120
		assertTrue("Catch invalid type on deprocess", catchFlag);
121
		catchFlag = false;
122
		try {
123
			STextUtil.processTyped("abc", "wrong_type");
124
		} catch (IllegalArgumentException e) {
125
			catchFlag = true;
126
		}
127
		assertTrue("Catch invalid type on process", catchFlag);
128
		// Test insertMarks()
114
		// Test insertMarks()
129
		doTest4("Util #4.1 - ", "ABCDEFG", new int[] {3, 6}, 0, false, "ABC@DEF@G");
115
		doTest4("Util #4.1 - ", "ABCDEFG", new int[] {3, 6}, 0, false, "ABC@DEF@G");
130
		doTest4("Util #4.2 - ", "ABCDEFG", new int[] {3, 6}, 0, true, ">@ABC@DEF@G@^");
116
		doTest4("Util #4.2 - ", "ABCDEFG", new int[] {3, 6}, 0, true, ">@ABC@DEF@G@^");

Return to bug 183164