ICU-1575 more tests for incremental
X-SVN-Rev: 7265
This commit is contained in:
parent
1cbf209ff2
commit
96173a5d60
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/translit/TransliteratorTest.java,v $
|
||||
* $Date: 2001/12/01 00:05:55 $
|
||||
* $Revision: 1.89 $
|
||||
* $Date: 2001/12/03 18:26:52 $
|
||||
* $Revision: 1.90 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -2198,9 +2198,13 @@ public class TransliteratorTest extends TestFmwk {
|
||||
static final String DESERET_dee = UTF16.valueOf(0x1043C);
|
||||
|
||||
static final String[][] testCases = {
|
||||
// NORMALIZATION, not in C
|
||||
{"NFC", "a\u0300", "\u00E0"},
|
||||
{"NFD", "\u00E0", "a\u0300"},
|
||||
|
||||
// NORMALIZATION, needs porting to C
|
||||
// should add more test cases
|
||||
{"NFD" , "a\u0300 \u00E0 \u1100\u1161 \uFF76\uFF9E\u03D3"},
|
||||
{"NFC" , "a\u0300 \u00E0 \u1100\u1161 \uFF76\uFF9E\u03D3"},
|
||||
{"NFKD", "a\u0300 \u00E0 \u1100\u1161 \uFF76\uFF9E\u03D3"},
|
||||
{"NFKC", "a\u0300 \u00E0 \u1100\u1161 \uFF76\uFF9E\u03D3"},
|
||||
|
||||
// mp -> b BUG
|
||||
{"Greek-Latin/UNGEGN", "(\u03BC\u03C0)", "(b)"},
|
||||
@ -2215,11 +2219,15 @@ public class TransliteratorTest extends TestFmwk {
|
||||
//TODO: enable this test once Titlecase works right
|
||||
//{"Title", "\uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE,
|
||||
// "Ffi\u0131ii \u01C8\u01C9\u01C9 " + DESERET_DEE + DESERET_dee},
|
||||
|
||||
{"Upper", "ab'cD \uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE,
|
||||
"AB'CD FFIII\u0130 \u01C7\u01C7\u01C7 " + DESERET_DEE + DESERET_DEE},
|
||||
{"Lower", "ab'cD \uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE,
|
||||
"ab'cd \uFB00i\u0131ii \u01C9\u01C9\u01C9 " + DESERET_dee + DESERET_dee},
|
||||
|
||||
{"Upper", "ab'cD \uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE},
|
||||
{"Lower", "ab'cD \uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE},
|
||||
|
||||
// FORMS OF S
|
||||
{"Greek-Latin/UNGEGN", "\u03C3 \u03C3\u03C2 \u03C2\u03C3", "s ss s\u0331s\u0331"},
|
||||
{"Latin-Greek/UNGEGN", "s ss s\u0331s\u0331", "\u03C3 \u03C3\u03C2 \u03C2\u03C3"},
|
||||
@ -2228,14 +2236,30 @@ public class TransliteratorTest extends TestFmwk {
|
||||
};
|
||||
|
||||
public void TestSpecialCases() {
|
||||
|
||||
for (int i = 0; i < registerRules.length; ++i) {
|
||||
Transliterator t = Transliterator.createFromRules(registerRules[i][0],
|
||||
registerRules[i][1], Transliterator.FORWARD);
|
||||
DummyFactory.add(registerRules[i][0], t);
|
||||
}
|
||||
for (int i = 0; i < testCases.length; ++i) {
|
||||
Transliterator t = Transliterator.getInstance(testCases[i][0]);
|
||||
expect(t, testCases[i][1], testCases[i][2]);
|
||||
String name = testCases[i][0];
|
||||
Transliterator t = Transliterator.getInstance(name);
|
||||
String id = t.getID();
|
||||
String source = testCases[i][1];
|
||||
String target = null;
|
||||
|
||||
// Automatic generation of targets, to make it simpler to add test cases (and more fail-safe)
|
||||
|
||||
if (testCases[i].length > 2) target = testCases[i][2];
|
||||
else if (id.equalsIgnoreCase("NFD")) target = com.ibm.text.Normalizer.normalize(source, com.ibm.text.Normalizer.DECOMP,0);
|
||||
else if (id.equalsIgnoreCase("NFC")) target = com.ibm.text.Normalizer.normalize(source, com.ibm.text.Normalizer.COMPOSE,0);
|
||||
else if (id.equalsIgnoreCase("NFKD")) target = com.ibm.text.Normalizer.normalize(source, com.ibm.text.Normalizer.DECOMP_COMPAT,0);
|
||||
else if (id.equalsIgnoreCase("NFKC")) target = com.ibm.text.Normalizer.normalize(source, com.ibm.text.Normalizer.COMPOSE_COMPAT,0);
|
||||
else if (id.equalsIgnoreCase("Lower")) target = UCharacter.toLowerCase(Locale.US, source);
|
||||
else if (id.equalsIgnoreCase("Upper")) target = UCharacter.toUpperCase(Locale.US, source);
|
||||
|
||||
expect(t, source, target);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2277,12 +2301,25 @@ public class TransliteratorTest extends TestFmwk {
|
||||
// Check to see that incremental gets at least part way through a reasonable string.
|
||||
|
||||
public void TestIncrementalProgress() {
|
||||
String test = "The Quick Brown Fox Jumped Over The Lazy Dog.";
|
||||
String latinTest = "The Quick Brown Fox.";
|
||||
String devaTest = Transliterator.getInstance("Latin-Devanagari").transliterate(latinTest);
|
||||
String kataTest = Transliterator.getInstance("Latin-Katakana").transliterate(latinTest);
|
||||
String[][] tests = {
|
||||
{"Any", latinTest},
|
||||
{"Latin", latinTest},
|
||||
{"Halfwidth", latinTest},
|
||||
{"Devanagari", devaTest},
|
||||
{"Katakana", kataTest},
|
||||
};
|
||||
|
||||
Enumeration sources = Transliterator.getAvailableSources();
|
||||
while(sources.hasMoreElements()) {
|
||||
String source = (String) sources.nextElement();
|
||||
if (!source.equals("Latin")) continue;
|
||||
String test = findMatch(source, tests);
|
||||
if (test == null) {
|
||||
logln("Skipping " + source + "-X");
|
||||
continue;
|
||||
}
|
||||
Enumeration targets = Transliterator.getAvailableTargets(source);
|
||||
while(targets.hasMoreElements()) {
|
||||
String target = (String) targets.nextElement();
|
||||
@ -2291,22 +2328,37 @@ public class TransliteratorTest extends TestFmwk {
|
||||
String variant = (String) variants.nextElement();
|
||||
String id = source + "-" + target + "/" + variant;
|
||||
|
||||
String filter = getFilter();
|
||||
if (filter != null && id.indexOf(filter) < 0) continue;
|
||||
|
||||
Transliterator t = Transliterator.getInstance(id);
|
||||
String result = CheckIncrementalAux(t, test);
|
||||
CheckIncrementalAux(t, test);
|
||||
|
||||
String rev = t.transliterate(test);
|
||||
Transliterator inv = t.getInverse();
|
||||
CheckIncrementalAux(inv, result);
|
||||
CheckIncrementalAux(inv, rev);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String CheckIncrementalAux(Transliterator t, String input) {
|
||||
public String findMatch (String source, String[][] pairs) {
|
||||
for (int i = 0; i < pairs.length; ++i) {
|
||||
if (source.equalsIgnoreCase(pairs[i][0])) return pairs[i][1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void CheckIncrementalAux(Transliterator t, String input) {
|
||||
|
||||
Replaceable test = new ReplaceableString(input);
|
||||
Transliterator.Position pos = new Transliterator.Position(0, test.length(), 0, test.length());
|
||||
t.transliterate(test, pos);
|
||||
boolean gotError = false;
|
||||
if (pos.start == 0) {
|
||||
|
||||
// we have a few special cases. Any-Remove (pos.start = 0, but also = limit) and U+XXXXX?X?
|
||||
|
||||
if (pos.start == 0 && pos.limit != 0 && !t.getID().equals("Hex-Any/Unicode")) {
|
||||
errln("No Progress, " + t.getID() + ": " + Utility.formatInput(test, pos));
|
||||
gotError = true;
|
||||
} else {
|
||||
@ -2317,7 +2369,6 @@ public class TransliteratorTest extends TestFmwk {
|
||||
errln("Incomplete, " + t.getID() + ": " + Utility.formatInput(test, pos));
|
||||
gotError = true;
|
||||
}
|
||||
return test.toString();
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/test/translit/Attic/TransliteratorTest.java,v $
|
||||
* $Date: 2001/12/01 00:05:55 $
|
||||
* $Revision: 1.89 $
|
||||
* $Date: 2001/12/03 18:26:52 $
|
||||
* $Revision: 1.90 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -2198,9 +2198,13 @@ public class TransliteratorTest extends TestFmwk {
|
||||
static final String DESERET_dee = UTF16.valueOf(0x1043C);
|
||||
|
||||
static final String[][] testCases = {
|
||||
// NORMALIZATION, not in C
|
||||
{"NFC", "a\u0300", "\u00E0"},
|
||||
{"NFD", "\u00E0", "a\u0300"},
|
||||
|
||||
// NORMALIZATION, needs porting to C
|
||||
// should add more test cases
|
||||
{"NFD" , "a\u0300 \u00E0 \u1100\u1161 \uFF76\uFF9E\u03D3"},
|
||||
{"NFC" , "a\u0300 \u00E0 \u1100\u1161 \uFF76\uFF9E\u03D3"},
|
||||
{"NFKD", "a\u0300 \u00E0 \u1100\u1161 \uFF76\uFF9E\u03D3"},
|
||||
{"NFKC", "a\u0300 \u00E0 \u1100\u1161 \uFF76\uFF9E\u03D3"},
|
||||
|
||||
// mp -> b BUG
|
||||
{"Greek-Latin/UNGEGN", "(\u03BC\u03C0)", "(b)"},
|
||||
@ -2215,11 +2219,15 @@ public class TransliteratorTest extends TestFmwk {
|
||||
//TODO: enable this test once Titlecase works right
|
||||
//{"Title", "\uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE,
|
||||
// "Ffi\u0131ii \u01C8\u01C9\u01C9 " + DESERET_DEE + DESERET_dee},
|
||||
|
||||
{"Upper", "ab'cD \uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE,
|
||||
"AB'CD FFIII\u0130 \u01C7\u01C7\u01C7 " + DESERET_DEE + DESERET_DEE},
|
||||
{"Lower", "ab'cD \uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE,
|
||||
"ab'cd \uFB00i\u0131ii \u01C9\u01C9\u01C9 " + DESERET_dee + DESERET_dee},
|
||||
|
||||
{"Upper", "ab'cD \uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE},
|
||||
{"Lower", "ab'cD \uFB00i\u0131I\u0130 \u01C7\u01C8\u01C9 " + DESERET_dee + DESERET_DEE},
|
||||
|
||||
// FORMS OF S
|
||||
{"Greek-Latin/UNGEGN", "\u03C3 \u03C3\u03C2 \u03C2\u03C3", "s ss s\u0331s\u0331"},
|
||||
{"Latin-Greek/UNGEGN", "s ss s\u0331s\u0331", "\u03C3 \u03C3\u03C2 \u03C2\u03C3"},
|
||||
@ -2228,14 +2236,30 @@ public class TransliteratorTest extends TestFmwk {
|
||||
};
|
||||
|
||||
public void TestSpecialCases() {
|
||||
|
||||
for (int i = 0; i < registerRules.length; ++i) {
|
||||
Transliterator t = Transliterator.createFromRules(registerRules[i][0],
|
||||
registerRules[i][1], Transliterator.FORWARD);
|
||||
DummyFactory.add(registerRules[i][0], t);
|
||||
}
|
||||
for (int i = 0; i < testCases.length; ++i) {
|
||||
Transliterator t = Transliterator.getInstance(testCases[i][0]);
|
||||
expect(t, testCases[i][1], testCases[i][2]);
|
||||
String name = testCases[i][0];
|
||||
Transliterator t = Transliterator.getInstance(name);
|
||||
String id = t.getID();
|
||||
String source = testCases[i][1];
|
||||
String target = null;
|
||||
|
||||
// Automatic generation of targets, to make it simpler to add test cases (and more fail-safe)
|
||||
|
||||
if (testCases[i].length > 2) target = testCases[i][2];
|
||||
else if (id.equalsIgnoreCase("NFD")) target = com.ibm.text.Normalizer.normalize(source, com.ibm.text.Normalizer.DECOMP,0);
|
||||
else if (id.equalsIgnoreCase("NFC")) target = com.ibm.text.Normalizer.normalize(source, com.ibm.text.Normalizer.COMPOSE,0);
|
||||
else if (id.equalsIgnoreCase("NFKD")) target = com.ibm.text.Normalizer.normalize(source, com.ibm.text.Normalizer.DECOMP_COMPAT,0);
|
||||
else if (id.equalsIgnoreCase("NFKC")) target = com.ibm.text.Normalizer.normalize(source, com.ibm.text.Normalizer.COMPOSE_COMPAT,0);
|
||||
else if (id.equalsIgnoreCase("Lower")) target = UCharacter.toLowerCase(Locale.US, source);
|
||||
else if (id.equalsIgnoreCase("Upper")) target = UCharacter.toUpperCase(Locale.US, source);
|
||||
|
||||
expect(t, source, target);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2277,12 +2301,25 @@ public class TransliteratorTest extends TestFmwk {
|
||||
// Check to see that incremental gets at least part way through a reasonable string.
|
||||
|
||||
public void TestIncrementalProgress() {
|
||||
String test = "The Quick Brown Fox Jumped Over The Lazy Dog.";
|
||||
String latinTest = "The Quick Brown Fox.";
|
||||
String devaTest = Transliterator.getInstance("Latin-Devanagari").transliterate(latinTest);
|
||||
String kataTest = Transliterator.getInstance("Latin-Katakana").transliterate(latinTest);
|
||||
String[][] tests = {
|
||||
{"Any", latinTest},
|
||||
{"Latin", latinTest},
|
||||
{"Halfwidth", latinTest},
|
||||
{"Devanagari", devaTest},
|
||||
{"Katakana", kataTest},
|
||||
};
|
||||
|
||||
Enumeration sources = Transliterator.getAvailableSources();
|
||||
while(sources.hasMoreElements()) {
|
||||
String source = (String) sources.nextElement();
|
||||
if (!source.equals("Latin")) continue;
|
||||
String test = findMatch(source, tests);
|
||||
if (test == null) {
|
||||
logln("Skipping " + source + "-X");
|
||||
continue;
|
||||
}
|
||||
Enumeration targets = Transliterator.getAvailableTargets(source);
|
||||
while(targets.hasMoreElements()) {
|
||||
String target = (String) targets.nextElement();
|
||||
@ -2291,22 +2328,37 @@ public class TransliteratorTest extends TestFmwk {
|
||||
String variant = (String) variants.nextElement();
|
||||
String id = source + "-" + target + "/" + variant;
|
||||
|
||||
String filter = getFilter();
|
||||
if (filter != null && id.indexOf(filter) < 0) continue;
|
||||
|
||||
Transliterator t = Transliterator.getInstance(id);
|
||||
String result = CheckIncrementalAux(t, test);
|
||||
CheckIncrementalAux(t, test);
|
||||
|
||||
String rev = t.transliterate(test);
|
||||
Transliterator inv = t.getInverse();
|
||||
CheckIncrementalAux(inv, result);
|
||||
CheckIncrementalAux(inv, rev);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String CheckIncrementalAux(Transliterator t, String input) {
|
||||
public String findMatch (String source, String[][] pairs) {
|
||||
for (int i = 0; i < pairs.length; ++i) {
|
||||
if (source.equalsIgnoreCase(pairs[i][0])) return pairs[i][1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void CheckIncrementalAux(Transliterator t, String input) {
|
||||
|
||||
Replaceable test = new ReplaceableString(input);
|
||||
Transliterator.Position pos = new Transliterator.Position(0, test.length(), 0, test.length());
|
||||
t.transliterate(test, pos);
|
||||
boolean gotError = false;
|
||||
if (pos.start == 0) {
|
||||
|
||||
// we have a few special cases. Any-Remove (pos.start = 0, but also = limit) and U+XXXXX?X?
|
||||
|
||||
if (pos.start == 0 && pos.limit != 0 && !t.getID().equals("Hex-Any/Unicode")) {
|
||||
errln("No Progress, " + t.getID() + ": " + Utility.formatInput(test, pos));
|
||||
gotError = true;
|
||||
} else {
|
||||
@ -2317,7 +2369,6 @@ public class TransliteratorTest extends TestFmwk {
|
||||
errln("Incomplete, " + t.getID() + ": " + Utility.formatInput(test, pos));
|
||||
gotError = true;
|
||||
}
|
||||
return test.toString();
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
Loading…
Reference in New Issue
Block a user