Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4eb07262a1674d7249d30e94733ba44db9ab4eba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*******************************************************************************
 * Copyright (c) 2010, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************/

package org.eclipse.equinox.bidi.internal.tests;

import java.util.Locale;
import org.eclipse.equinox.bidi.STextProcessorFactory;
import org.eclipse.equinox.bidi.STextUtil;

/**
 * Tests methods in BidiComplexUtil
 */

public class STextUtilTest extends STextTestBase {

	private static final String HEBREW = "iw";

	private static final String HEBREW2 = "he";

	private static final String ARABIC = "ar";

	private static final String FARSI = "fa";

	private static final String URDU = "ur";

	private Locale locale;

	protected void setUp() throws Exception {
		super.setUp();
		locale = Locale.getDefault();
	}

	protected void tearDown() {
		Locale.setDefault(locale);
	}

	private void doTest1(String data, String result) {
		Locale.setDefault(Locale.ENGLISH);
		String full = STextUtil.process(toUT16(data));
		assertEquals("Util #1 full EN - ", data, toPseudo(full));
		Locale.setDefault(new Locale(HEBREW2));
		full = STextUtil.process(toUT16(data));
		assertEquals("Util #1 full HE - ", result, toPseudo(full));
		Locale.setDefault(new Locale(ARABIC));
		full = STextUtil.process(toUT16(data));
		assertEquals("Util #1 full AR - ", result, toPseudo(full));
		Locale.setDefault(new Locale(FARSI));
		full = STextUtil.process(toUT16(data));
		assertEquals("Util #1 full FA - ", result, toPseudo(full));
		Locale.setDefault(new Locale(URDU));
		full = STextUtil.process(toUT16(data));
		assertEquals("Util #1 full UR - ", result, toPseudo(full));
		Locale.setDefault(new Locale(HEBREW));
		full = STextUtil.process(toUT16(data));
		String ful2 = STextUtil.process(toUT16(data), (String) null);
		assertEquals("Util #1 full - ", result, toPseudo(full));
		assertEquals("Util #1 ful2 - ", result, toPseudo(ful2));
		String lean = STextUtil.deprocess(full);
		assertEquals("Util #1 lean - ", data, toPseudo(lean));
	}

	private void doTest2(String msg, String data, String result) {
		doTest2(msg, data, result, data);
	}

	private void doTest2(String msg, String data, String result, String resLean) {
		String full = STextUtil.process(toUT16(data), "*");
		assertEquals(msg + "full", result, toPseudo(full));
		String lean = STextUtil.deprocess(full);
		assertEquals(msg + "lean", resLean, toPseudo(lean));
	}

	private void doTest3(String msg, String data, String result) {
		doTest3(msg, data, result, data);
	}

	private void doTest3(String msg, String data, String result, String resLean) {
		String full = STextUtil.process(toUT16(data), STextProcessorFactory.PROC_COMMA_DELIMITED);
		assertEquals(msg + "full", result, toPseudo(full));
		String lean = STextUtil.deprocess(full, STextProcessorFactory.PROC_COMMA_DELIMITED);
		assertEquals(msg + "lean", resLean, toPseudo(lean));
	}

	private void doTest4(String msg, String data, int[] offsets, int direction, boolean affix, String result) {
		String txt = msg + "text=" + data + "\n    offsets=" + array_display(offsets) + "\n    direction=" + direction + "\n    affix=" + affix;
		String lean = toUT16(data);
		String full = STextUtil.insertMarks(lean, offsets, direction, affix);
		assertEquals(txt, result, toPseudo(full));
	}

	public void testBidiComplexUtil() {

		// Test process() and deprocess() with default delimiters
		doTest1("ABC/DEF/G", ">@ABC@/DEF@/G@^");
		// Test process() and deprocess() with specified delimiters
		doTest2("Util #2.1 - ", "", "");
		doTest2("Util #2.2 - ", ">@ABC@^", ">@ABC@^", "ABC");
		doTest2("Util #2.3 - ", "abc", "abc");
		doTest2("Util #2.4 - ", "!abc", ">@!abc@^");
		doTest2("Util #2.5 - ", "abc!", ">@abc!@^");
		doTest2("Util #2.6 - ", "ABC*DEF*G", ">@ABC@*DEF@*G@^");
		// Test process() and deprocess() with specified expression type
		doTest3("Util #3.1 - ", "ABC,DEF,G", ">@ABC@,DEF@,G@^");
		doTest3("Util #3.2 - ", "", "");
		doTest3("Util #3.3 - ", ">@DEF@^", ">@DEF@^", "DEF");
		// Test insertMarks()
		doTest4("Util #4.1 - ", "ABCDEFG", new int[] {3, 6}, 0, false, "ABC@DEF@G");
		doTest4("Util #4.2 - ", "ABCDEFG", new int[] {3, 6}, 0, true, ">@ABC@DEF@G@^");
		doTest4("Util #4.3 - ", "ABCDEFG", new int[] {3, 6}, 1, false, "ABC&DEF&G");
		doTest4("Util #4.4 - ", "ABCDEFG", new int[] {3, 6}, 1, true, "<&ABC&DEF&G&^");
		doTest4("Util #4.5 - ", "", new int[] {3, 6}, 0, false, "");
		doTest4("Util #4.6 - ", "", new int[] {3, 6}, 0, true, "");
		doTest4("Util #4.7 - ", "ABCDEFG", null, 1, false, "ABCDEFG");
		doTest4("Util #4.8 - ", "ABCDEFG", null, 1, true, "<&ABCDEFG&^");
	}
}

Back to the top