use of android.icu.text.UnicodeSet in project j2objc by google.
the class UnicodeSetTest method TestFrozen.
/**
* Test that frozen classes disallow changes. For 4217
*/
@Test
public void TestFrozen() {
UnicodeSet test = new UnicodeSet("[[:whitespace:]A]");
test.freeze();
checkModification(test, true);
checkModification(test, false);
}
use of android.icu.text.UnicodeSet in project j2objc by google.
the class UnicodeSetTest method TestRangeConstructor.
@Test
public void TestRangeConstructor() {
UnicodeSet w = new UnicodeSet().addAll(3, 5);
UnicodeSet s = new UnicodeSet(3, 5);
assertEquals("new constructor", w, s);
w = new UnicodeSet().addAll(3, 5).addAll(7, 7);
UnicodeSet t = new UnicodeSet(3, 5, 7, 7);
assertEquals("new constructor", w, t);
// check to make sure right exceptions are thrown
Class expected = IllegalArgumentException.class;
Class actual;
try {
actual = null;
@SuppressWarnings("unused") UnicodeSet u = new UnicodeSet(5);
} catch (IllegalArgumentException e) {
actual = e.getClass();
}
assertEquals("exception if odd", expected, actual);
try {
actual = null;
@SuppressWarnings("unused") UnicodeSet u = new UnicodeSet(3, 2, 7, 9);
} catch (IllegalArgumentException e) {
actual = e.getClass();
}
assertEquals("exception for start/end problem", expected, actual);
try {
actual = null;
@SuppressWarnings("unused") UnicodeSet u = new UnicodeSet(3, 5, 6, 9);
} catch (IllegalArgumentException e) {
actual = e.getClass();
}
assertEquals("exception for end/start problem", expected, actual);
CheckRangeSpeed(10000, new UnicodeSet("[:whitespace:]"));
CheckRangeSpeed(1000, new UnicodeSet("[:letter:]"));
}
use of android.icu.text.UnicodeSet in project j2objc by google.
the class UnicodeSetTest method TestPatterns.
@Test
public void TestPatterns() {
UnicodeSet set = new UnicodeSet();
expectPattern(set, "[[a-m]&[d-z]&[k-y]]", "km");
expectPattern(set, "[[a-z]-[m-y]-[d-r]]", "aczz");
expectPattern(set, "[a\\-z]", "--aazz");
expectPattern(set, "[-az]", "--aazz");
expectPattern(set, "[az-]", "--aazz");
expectPattern(set, "[[[a-z]-[aeiou]i]]", "bdfnptvz");
// Throw in a test of complement
set.complement();
String exp = '\u0000' + "aeeoouu" + (char) ('z' + 1) + '\uFFFF';
expectPairs(set, exp);
}
use of android.icu.text.UnicodeSet in project j2objc by google.
the class UnicodeSetTest method TestEscapePattern.
@Test
public void TestEscapePattern() {
// The following pattern must contain at least one range "c-d"
// where c or d is a Pattern_White_Space.
String pattern = "[\\uFEFF \\u200E-\\u20FF \\uFFF9-\\uFFFC \\U0001D173-\\U0001D17A \\U000F0000-\\U000FFFFD ]";
String exp = "[\\u200E-\\u20FF\\uFEFF\\uFFF9-\\uFFFC\\U0001D173-\\U0001D17A\\U000F0000-\\U000FFFFD]";
// this fails -- which is what we expect.
for (int pass = 1; pass <= 2; ++pass) {
String pat = pattern;
if (pass == 2) {
pat = Utility.unescape(pat);
}
// Pattern is only good for pass 1
boolean isPatternValid = (pass == 1);
UnicodeSet set = null;
try {
set = new UnicodeSet(pat);
} catch (IllegalArgumentException e) {
set = null;
}
if ((set != null) != isPatternValid) {
errln("FAIL: applyPattern(" + Utility.escape(pat) + ") => " + set);
continue;
}
if (set == null) {
continue;
}
if (set.contains((char) 0x0644)) {
errln("FAIL: " + Utility.escape(pat) + " contains(U+0664)");
}
String newpat = set.toPattern(true);
if (newpat.equals(exp)) {
logln(Utility.escape(pat) + " => " + newpat);
} else {
errln("FAIL: " + Utility.escape(pat) + " => " + newpat);
}
for (int i = 0; i < set.getRangeCount(); ++i) {
StringBuffer str = new StringBuffer("Range ");
str.append((char) (0x30 + i)).append(": ");
UTF16.append(str, set.getRangeStart(i));
str.append(" - ");
UTF16.append(str, set.getRangeEnd(i));
String s = Utility.escape(str.toString() + " (" + set.getRangeStart(i) + " - " + set.getRangeEnd(i) + ")");
if (set.getRangeStart(i) < 0) {
errln("FAIL: " + s);
} else {
logln(s);
}
}
}
}
use of android.icu.text.UnicodeSet in project j2objc by google.
the class UnicodeSetTest method TestCharSequenceArgs.
@Test
public void TestCharSequenceArgs() {
// statics
assertEquals("CharSequence from", new UnicodeSet("[{abc}]"), UnicodeSet.from(new StringBuilder("abc")));
assertEquals("CharSequence fromAll", new UnicodeSet("[a-c]"), UnicodeSet.fromAll(new StringBuilder("abc")));
assertEquals("CharSequence compare", 1.0f, Math.signum(UnicodeSet.compare(new StringBuilder("abc"), 0x61)));
assertEquals("CharSequence compare", -1.0f, Math.signum(UnicodeSet.compare(0x61, new StringBuilder("abc"))));
assertEquals("CharSequence compare", 0.0f, Math.signum(UnicodeSet.compare(new StringBuilder("a"), 0x61)));
assertEquals("CharSequence compare", 0.0f, Math.signum(UnicodeSet.compare(0x61, new StringBuilder("a"))));
assertEquals("CharSequence getSingleCodePoint", 0x1F466, UnicodeSet.getSingleCodePoint(new StringBuilder("👦")));
// iterables/arrays
Iterable<StringBuilder> iterable = Arrays.asList(new StringBuilder("A"), new StringBuilder("B"));
assertEquals("CharSequence containsAll", true, new UnicodeSet("[AB]").containsAll(iterable));
assertEquals("CharSequence containsAll", false, new UnicodeSet("[a-cA]").containsAll(iterable));
assertEquals("CharSequence containsNone", true, new UnicodeSet("[a-c]").containsNone(iterable));
assertEquals("CharSequence containsNone", false, new UnicodeSet("[a-cA]").containsNone(iterable));
assertEquals("CharSequence containsSome", true, new UnicodeSet("[a-cA]").containsSome(iterable));
assertEquals("CharSequence containsSome", false, new UnicodeSet("[a-c]").containsSome(iterable));
assertEquals("CharSequence addAll", new UnicodeSet("[a-cAB]"), new UnicodeSet("[a-cA]").addAll(new StringBuilder("A"), new StringBuilder("B")));
assertEquals("CharSequence removeAll", new UnicodeSet("[a-c]"), new UnicodeSet("[a-cA]").removeAll(iterable));
assertEquals("CharSequence retainAll", new UnicodeSet("[A]"), new UnicodeSet("[a-cA]").retainAll(iterable));
// UnicodeSet results
assertEquals("CharSequence add", new UnicodeSet("[Aa-c{abc}{qr}]"), new UnicodeSet("[a-cA{qr}]").add(new StringBuilder("abc")));
assertEquals("CharSequence retain", new UnicodeSet("[{abc}]"), new UnicodeSet("[a-cA{abc}{qr}]").retain(new StringBuilder("abc")));
assertEquals("CharSequence remove", new UnicodeSet("[Aa-c{qr}]"), new UnicodeSet("[a-cA{abc}{qr}]").remove(new StringBuilder("abc")));
assertEquals("CharSequence complement", new UnicodeSet("[Aa-c{qr}]"), new UnicodeSet("[a-cA{abc}{qr}]").complement(new StringBuilder("abc")));
assertEquals("CharSequence complement", new UnicodeSet("[Aa-c{abc}{qr}]"), new UnicodeSet("[a-cA{qr}]").complement(new StringBuilder("abc")));
assertEquals("CharSequence addAll", new UnicodeSet("[a-cABC]"), new UnicodeSet("[a-cA]").addAll(new StringBuilder("ABC")));
assertEquals("CharSequence retainAll", new UnicodeSet("[a-c]"), new UnicodeSet("[a-cA]").retainAll(new StringBuilder("abcB")));
assertEquals("CharSequence removeAll", new UnicodeSet("[Aab]"), new UnicodeSet("[a-cA]").removeAll(new StringBuilder("cC")));
assertEquals("CharSequence complementAll", new UnicodeSet("[ABbc]"), new UnicodeSet("[a-cA]").complementAll(new StringBuilder("aB")));
// containment
assertEquals("CharSequence contains", true, new UnicodeSet("[a-cA{ab}]").contains(new StringBuilder("ab")));
assertEquals("CharSequence containsNone", false, new UnicodeSet("[a-cA]").containsNone(new StringBuilder("ab")));
assertEquals("CharSequence containsSome", true, new UnicodeSet("[a-cA{ab}]").containsSome(new StringBuilder("ab")));
// spanning
assertEquals("CharSequence span", 3, new UnicodeSet("[a-cA]").span(new StringBuilder("abc"), SpanCondition.SIMPLE));
assertEquals("CharSequence span", 3, new UnicodeSet("[a-cA]").span(new StringBuilder("abc"), 1, SpanCondition.SIMPLE));
assertEquals("CharSequence spanBack", 0, new UnicodeSet("[a-cA]").spanBack(new StringBuilder("abc"), SpanCondition.SIMPLE));
assertEquals("CharSequence spanBack", 0, new UnicodeSet("[a-cA]").spanBack(new StringBuilder("abc"), 1, SpanCondition.SIMPLE));
// internal
OutputInt outCount = new OutputInt();
assertEquals("CharSequence matchesAt", 2, new UnicodeSet("[a-cA]").matchesAt(new StringBuilder("abc"), 1));
assertEquals("CharSequence spanAndCount", 3, new UnicodeSet("[a-cA]").spanAndCount(new StringBuilder("abc"), 1, SpanCondition.SIMPLE, outCount));
assertEquals("CharSequence findIn", 3, new UnicodeSet("[a-cA]").findIn(new StringBuilder("abc"), 1, true));
assertEquals("CharSequence findLastIn", -1, new UnicodeSet("[a-cA]").findLastIn(new StringBuilder("abc"), 1, true));
assertEquals("CharSequence add", "c", new UnicodeSet("[abA]").stripFrom(new StringBuilder("abc"), true));
}
Aggregations