use of android.icu.text.UnicodeSet in project j2objc by google.
the class UnicodeMapTest method TestUnicodeMapGeneralCategory.
public void TestUnicodeMapGeneralCategory() {
logln("Setting General Category");
UnicodeMap<String> map1 = new UnicodeMap();
Map<Integer, String> map2 = new HashMap<Integer, String>();
// Map<Integer, String> map3 = new TreeMap<Integer, String>();
map1 = new UnicodeMap<String>();
map2 = new TreeMap<Integer, String>();
for (int cp = 0; cp <= SET_LIMIT; ++cp) {
int enumValue = UCharacter.getIntPropertyValue(cp, propEnum);
// if (enumValue <= 0) continue; // for smaller set
String value = UCharacter.getPropertyValueName(propEnum, enumValue, UProperty.NameChoice.LONG);
map1.put(cp, value);
map2.put(cp, value);
}
checkNext(map1, map2, Integer.MAX_VALUE);
logln("Comparing General Category");
check(map1, map2, -1);
logln("Comparing Values");
Set<String> values1 = map1.getAvailableValues(new TreeSet<String>());
Set<String> values2 = new TreeSet<String>(map2.values());
if (!TestBoilerplate.verifySetsIdentical(this, values1, values2)) {
throw new IllegalArgumentException("Halting");
}
logln("Comparing Sets");
for (Iterator<String> it = values1.iterator(); it.hasNext(); ) {
String value = it.next();
logln(value == null ? "null" : value);
UnicodeSet set1 = map1.keySet(value);
UnicodeSet set2 = TestBoilerplate.getSet(map2, value);
if (!TestBoilerplate.verifySetsIdentical(this, set1, set2)) {
throw new IllegalArgumentException("Halting");
}
}
}
use of android.icu.text.UnicodeSet in project j2objc by google.
the class TransliteratorTest method assertEquals.
void assertEquals(String message, UnicodeSet empirical, UnicodeSet actual, SetAssert setAssert) {
boolean haveError = false;
if (!actual.containsAll(empirical)) {
UnicodeSet missing = new UnicodeSet(empirical).removeAll(actual);
errln(message + " \tgetXSet < empirical (" + missing.size() + "): " + toPattern(missing));
haveError = true;
}
if (!empirical.containsAll(actual)) {
UnicodeSet extra = new UnicodeSet(actual).removeAll(empirical);
logln("WARNING: " + message + " \tgetXSet > empirical (" + extra.size() + "): " + toPattern(extra));
haveError = true;
}
if (!haveError) {
logln("OK " + message + ' ' + toPattern(empirical));
}
}
use of android.icu.text.UnicodeSet in project j2objc by google.
the class TransliteratorTest method TestCoverage.
// ======================================================================
// These tests are not mirrored (yet) in icu4c at
// source/test/intltest/transtst.cpp
// ======================================================================
/**
* Improve code coverage.
*/
@Test
public void TestCoverage() {
// NullTransliterator
Transliterator t = Transliterator.getInstance("Null", Transliterator.FORWARD);
expect(t, "a", "a");
// Source, target set
t = Transliterator.getInstance("Latin-Greek", Transliterator.FORWARD);
t.setFilter(new UnicodeSet("[A-Z]"));
logln("source = " + t.getSourceSet());
logln("target = " + t.getTargetSet());
t = Transliterator.createFromRules("x", "(.) > &Any-Hex($1);", Transliterator.FORWARD);
logln("source = " + t.getSourceSet());
logln("target = " + t.getTargetSet());
}
use of android.icu.text.UnicodeSet in project j2objc by google.
the class TransliteratorTest method TestToRules.
@Test
public void TestToRules() {
String RBT = "rbt";
String SET = "set";
String[] DATA = { RBT, "$a=\\u4E61; [$a] > A;", "[\\u4E61] > A;", RBT, "$white=[[:Zs:][:Zl:]]; $white{a} > A;", "[[:Zs:][:Zl:]]{a} > A;", SET, "[[:Zs:][:Zl:]]", "[[:Zs:][:Zl:]]", SET, "[:Ps:]", "[:Ps:]", SET, "[:L:]", "[:L:]", SET, "[[:L:]-[A]]", "[[:L:]-[A]]", SET, "[~[:Lu:][:Ll:]]", "[~[:Lu:][:Ll:]]", SET, "[~[a-z]]", "[~[a-z]]", RBT, "$white=[:Zs:]; $black=[^$white]; $black{a} > A;", "[^[:Zs:]]{a} > A;", RBT, "$a=[:Zs:]; $b=[[a-z]-$a]; $b{a} > A;", "[[a-z]-[:Zs:]]{a} > A;", RBT, "$a=[:Zs:]; $b=[$a&[a-z]]; $b{a} > A;", "[[:Zs:]&[a-z]]{a} > A;", RBT, "$a=[:Zs:]; $b=[x$a]; $b{a} > A;", "[x[:Zs:]]{a} > A;", RBT, "$accentMinus = [ [\\u0300-\\u0345] & [:M:] - [\\u0338]] ;" + "$macron = \\u0304 ;" + "$evowel = [aeiouyAEIOUY] ;" + "$iotasub = \\u0345 ;" + "($evowel $macron $accentMinus *) i > | $1 $iotasub ;", "([AEIOUYaeiouy]\\u0304[[\\u0300-\\u0345]&[:M:]-[\\u0338]]*)i > | $1 \\u0345;", RBT, "([AEIOUYaeiouy]\\u0304[[:M:]-[\\u0304\\u0345]]*)i > | $1 \\u0345;", "([AEIOUYaeiouy]\\u0304[[:M:]-[\\u0304\\u0345]]*)i > | $1 \\u0345;" };
for (int d = 0; d < DATA.length; d += 3) {
if (DATA[d] == RBT) {
// Transliterator test
Transliterator t = Transliterator.createFromRules("ID", DATA[d + 1], Transliterator.FORWARD);
if (t == null) {
errln("FAIL: createFromRules failed");
return;
}
String rules, escapedRules;
rules = t.toRules(false);
escapedRules = t.toRules(true);
String expRules = Utility.unescape(DATA[d + 2]);
String expEscapedRules = DATA[d + 2];
if (rules.equals(expRules)) {
logln("Ok: " + DATA[d + 1] + " => " + Utility.escape(rules));
} else {
errln("FAIL: " + DATA[d + 1] + " => " + Utility.escape(rules + ", exp " + expRules));
}
if (escapedRules.equals(expEscapedRules)) {
logln("Ok: " + DATA[d + 1] + " => " + escapedRules);
} else {
errln("FAIL: " + DATA[d + 1] + " => " + escapedRules + ", exp " + expEscapedRules);
}
} else {
// UnicodeSet test
String pat = DATA[d + 1];
String expToPat = DATA[d + 2];
UnicodeSet set = new UnicodeSet(pat);
// Adjust spacing etc. as necessary.
String toPat;
toPat = set.toPattern(true);
if (expToPat.equals(toPat)) {
logln("Ok: " + pat + " => " + toPat);
} else {
errln("FAIL: " + pat + " => " + Utility.escape(toPat) + ", exp " + Utility.escape(pat));
}
}
}
}
use of android.icu.text.UnicodeSet in project j2objc by google.
the class WriteCharts method printSet.
public static void printSet(String source) {
UnicodeSet s = new UnicodeSet(source);
System.out.println("Printout for '" + source + "'");
int count = s.getRangeCount();
for (int i = 0; i < count; ++i) {
int start = s.getRangeStart(i);
int end = s.getRangeEnd(i);
System.out.println(Integer.toString(start, 16) + ".." + Integer.toString(end, 16));
}
}
Aggregations