use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class CollationMiscTest method TestCase.
@Test
public void TestCase() {
String gRules = "\u0026\u0030\u003C\u0031\u002C\u2460\u003C\u0061\u002C\u0041";
String[] testCase = { "1a", "1A", "\u2460a", "\u2460A" };
int[][] caseTestResults = { { -1, -1, -1, 0, -1, -1, 0, 0, -1 }, { 1, -1, -1, 0, -1, -1, 0, 0, 1 }, { -1, -1, -1, 0, 1, -1, 0, 0, -1 }, { 1, -1, 1, 0, -1, -1, 0, 0, 1 } };
boolean[][] caseTestAttributes = { { false, false }, { true, false }, { false, true }, { true, true } };
int i, j, k;
Collator myCollation;
try {
myCollation = Collator.getInstance(new Locale("en", "US"));
} catch (Exception e) {
warnln("ERROR: in creation of rule based collator ");
return;
}
// logln("Testing different case settings");
myCollation.setStrength(Collator.TERTIARY);
for (k = 0; k < 4; k++) {
if (caseTestAttributes[k][0] == true) {
// upper case first
((RuleBasedCollator) myCollation).setUpperCaseFirst(true);
} else {
// upper case first
((RuleBasedCollator) myCollation).setLowerCaseFirst(true);
}
((RuleBasedCollator) myCollation).setCaseLevel(caseTestAttributes[k][1]);
// logln("Case first = " + caseTestAttributes[k][0] + ", Case level = " + caseTestAttributes[k][1]);
for (i = 0; i < 3; i++) {
for (j = i + 1; j < 4; j++) {
CollationTest.doTest(this, (RuleBasedCollator) myCollation, testCase[i], testCase[j], caseTestResults[k][3 * i + j - 1]);
}
}
}
try {
myCollation = new RuleBasedCollator(gRules);
} catch (Exception e) {
warnln("ERROR: in creation of rule based collator");
return;
}
// logln("Testing different case settings with custom rules");
myCollation.setStrength(Collator.TERTIARY);
for (k = 0; k < 4; k++) {
if (caseTestAttributes[k][0] == true) {
((RuleBasedCollator) myCollation).setUpperCaseFirst(true);
} else {
((RuleBasedCollator) myCollation).setUpperCaseFirst(false);
}
((RuleBasedCollator) myCollation).setCaseLevel(caseTestAttributes[k][1]);
for (i = 0; i < 3; i++) {
for (j = i + 1; j < 4; j++) {
CollationTest.doTest(this, (RuleBasedCollator) myCollation, testCase[i], testCase[j], caseTestResults[k][3 * i + j - 1]);
}
}
}
{
String[] lowerFirst = { "h", "H", "ch", "Ch", "CH", "cha", "chA", "Cha", "ChA", "CHa", "CHA", "i", "I" };
String[] upperFirst = { "H", "h", "CH", "Ch", "ch", "CHA", "CHa", "ChA", "Cha", "chA", "cha", "I", "i" };
// logln("mixed case test");
// logln("lower first, case level off");
genericRulesStarter("[caseFirst lower]&H<ch<<<Ch<<<CH", lowerFirst);
// logln("upper first, case level off");
genericRulesStarter("[caseFirst upper]&H<ch<<<Ch<<<CH", upperFirst);
// logln("lower first, case level on");
genericRulesStarter("[caseFirst lower][caseLevel on]&H<ch<<<Ch<<<CH", lowerFirst);
// logln("upper first, case level on");
genericRulesStarter("[caseFirst upper][caseLevel on]&H<ch<<<Ch<<<CH", upperFirst);
}
}
use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class CollationMiscTest method genericRulesStarterWithOptionsAndResult.
void genericRulesStarterWithOptionsAndResult(String rules, String[] s, String[] atts, Object[] attVals, int result) {
RuleBasedCollator coll = null;
try {
coll = new RuleBasedCollator(rules);
genericOptionsSetter(coll, atts, attVals);
genericOrderingTestWithResult(coll, s, result);
} catch (Exception e) {
warnln("Unable to open collator with rules " + rules);
}
}
use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class CollationMiscTest method TestJ3087.
@Test
public void TestJ3087() {
String[] rule = { "&h<H&CH=\u0427", /*
* The ICU 53 builder adheres to the principle that
* a rule is affected by previous rules but not following ones.
* Therefore, setting CH=\u0427 and then re-tailoring H makes CH != \u0427.
"&CH=\u0427&h<H", */
"&CH=\u0427" };
RuleBasedCollator rbc = null;
CollationElementIterator iter1;
CollationElementIterator iter2;
for (int i = 0; i < rule.length; i++) {
try {
rbc = new RuleBasedCollator(rule[i]);
} catch (Exception e) {
warnln(e.getMessage());
continue;
}
iter1 = rbc.getCollationElementIterator("CH");
iter2 = rbc.getCollationElementIterator("\u0427");
int ce1 = CollationElementIterator.IGNORABLE;
int ce2 = CollationElementIterator.IGNORABLE;
// The ICU 53 builder code sets the uppercase flag only on the first CE.
int mask = ~0;
while (ce1 != CollationElementIterator.NULLORDER && ce2 != CollationElementIterator.NULLORDER) {
ce1 = iter1.next();
ce2 = iter2.next();
if ((ce1 & mask) != (ce2 & mask)) {
errln("Error generating RuleBasedCollator with the rule " + rule[i]);
errln("CH != \\u0427");
}
// mask off case/continuation bits
mask = ~0xc0;
}
}
}
use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class CollationMiscTest method TestLocaleRuleBasedCollators.
@Test
public void TestLocaleRuleBasedCollators() {
if (TestFmwk.getExhaustiveness() < 5) {
// not serious enough to run this
return;
}
Locale[] locale = Collator.getAvailableLocales();
String prevrule = null;
for (int i = 0; i < locale.length; i++) {
Locale l = locale[i];
try {
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_COLLATION_BASE_NAME, l);
String collkey = rb.getStringWithFallback("collations/default");
ICUResourceBundle elements = rb.getWithFallback("collations/" + collkey);
if (elements == null) {
continue;
}
String rule = null;
/*
Object[][] colldata = (Object[][])elements;
// %%CollationBin
if (colldata[0][1] instanceof byte[]){
rule = (String)colldata[1][1];
}
else {
rule = (String)colldata[0][1];
}
*/
rule = elements.getString("Sequence");
RuleBasedCollator col1 = (RuleBasedCollator) Collator.getInstance(l);
if (!rule.equals(col1.getRules())) {
errln("Rules should be the same in the RuleBasedCollator and Locale");
}
if (rule != null && rule.length() > 0 && !rule.equals(prevrule)) {
RuleBasedCollator col2 = new RuleBasedCollator(rule);
if (!col1.equals(col2)) {
errln("Error creating RuleBasedCollator from " + "locale rules for " + l.toString());
}
}
prevrule = rule;
} catch (Exception e) {
warnln("Error retrieving resource bundle for testing: " + e.toString());
}
}
}
use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class CollationMiscTest method TestComposeDecompose.
@Test
public void TestComposeDecompose() {
Tester[] t = new Tester[0x30000];
t[0] = new Tester();
logln("Testing UCA extensively\n");
RuleBasedCollator coll;
try {
coll = (RuleBasedCollator) Collator.getInstance(Locale.ENGLISH);
} catch (Exception e) {
warnln("Error opening collator\n");
return;
}
int noCases = 0;
for (int u = 0; u < 0x30000; u++) {
String comp = UTF16.valueOf(u);
int len = comp.length();
t[noCases].NFC = Normalizer.normalize(u, Normalizer.NFC);
t[noCases].NFD = Normalizer.normalize(u, Normalizer.NFD);
if (t[noCases].NFC.length() != t[noCases].NFD.length() || (t[noCases].NFC.compareTo(t[noCases].NFD) != 0) || (len != t[noCases].NFD.length()) || (comp.compareTo(t[noCases].NFD) != 0)) {
t[noCases].u = u;
if (len != t[noCases].NFD.length() || (comp.compareTo(t[noCases].NFD) != 0)) {
t[noCases].NFC = comp;
}
noCases++;
t[noCases] = new Tester();
}
}
for (int u = 0; u < noCases; u++) {
if (!coll.equals(t[u].NFC, t[u].NFD)) {
errln("Failure: codePoint \\u" + Integer.toHexString(t[u].u) + " fails TestComposeDecompose in the UCA");
CollationTest.doTest(this, coll, t[u].NFC, t[u].NFD, 0);
}
}
logln("Testing locales, number of cases = " + noCases);
Locale[] loc = Collator.getAvailableLocales();
for (int i = 0; i < loc.length; i++) {
if (hasCollationElements(loc[i])) {
logln("Testing locale " + loc[i].getDisplayName());
coll = (RuleBasedCollator) Collator.getInstance(loc[i]);
coll.setStrength(Collator.IDENTICAL);
for (int u = 0; u < noCases; u++) {
if (!coll.equals(t[u].NFC, t[u].NFD)) {
errln("Failure: codePoint \\u" + Integer.toHexString(t[u].u) + " fails TestComposeDecompose for locale " + loc[i].getDisplayName());
// this tests for the iterators too
CollationTest.doTest(this, coll, t[u].NFC, t[u].NFD, 0);
}
}
}
}
}
Aggregations