|
1
|
|
package abbot.editor.widgets;
|
|
2
|
|
|
|
3
|
|
import junit.framework.*;
|
|
4
|
|
import junit.extensions.abbot.*;
|
|
5
|
|
|
|
6
|
|
public class TextFormatTest extends TestCase {
|
|
7
|
|
|
|
8
|
1
|
public void testWordBreak() {
|
|
9
|
1
|
String[][] words = {
|
|
10
|
|
{ "Some", "Some" },
|
|
11
|
|
{ "SomeMore", "Some More" },
|
|
12
|
|
{ "andAnother", "and Another" },
|
|
13
|
|
{ "AAAMotorClub", "AAA Motor Club" },
|
|
14
|
|
};
|
|
15
|
1
|
for (int i=0;i < words.length;i++) {
|
|
16
|
4
|
assertEquals("Didn't break up '" + words[i][0] + "'",
|
|
17
|
|
words[i][1], TextFormat.wordBreak(words[i][0]));
|
|
18
|
|
}
|
|
19
|
|
}
|
|
20
|
|
|
|
21
|
1
|
public void testLongLine() {
|
|
22
|
1
|
String original = "onenonwrap twononwrap";
|
|
23
|
1
|
String expected = "onenonwrap<br>twononwrap";
|
|
24
|
1
|
assertEquals("Improper long-line wrapping",
|
|
25
|
|
expected, TextFormat.wordWrap(original, 5, "<br>"));
|
|
26
|
|
}
|
|
27
|
|
|
|
28
|
1
|
public void testTrimLeadingWhitespace() {
|
|
29
|
1
|
String original = " line 1 and line 2";
|
|
30
|
1
|
String expected = "line 1 and<br>line 2";
|
|
31
|
1
|
assertEquals("Should strip whitespace from BOL",
|
|
32
|
|
expected, TextFormat.wordWrap(original, 10, "<br>"));
|
|
33
|
|
}
|
|
34
|
|
|
|
35
|
1
|
public void testWordWrap() {
|
|
36
|
1
|
String original = "The current JVM release incorrectly generates events for mouse buttons 2 and 3. There is no workaround. Please file a bug with Apple at http://www.bugreporter.apple.com.";
|
|
37
|
1
|
String expected = "The current JVM release incorrectly generates events for<br>mouse buttons 2 and 3. There is no workaround. Please file<br>a bug with Apple at http://www.bugreporter.apple.com.";
|
|
38
|
1
|
assertEquals("Bad word wrapping", expected,
|
|
39
|
|
TextFormat.wordWrap(original,
|
|
40
|
|
TextFormat.DIALOG_WRAP,
|
|
41
|
|
"<br>"));
|
|
42
|
|
}
|
|
43
|
|
|
|
44
|
|
|
|
45
|
4
|
public TextFormatTest(String name) { super(name); }
|
|
46
|
|
|
|
47
|
|
|
|
48
|
0
|
public static void main(String[] args) {
|
|
49
|
0
|
TestHelper.runTests(args, TextFormatTest.class);
|
|
50
|
|
}
|
|
51
|
|
}
|
|
52
|
|
|