use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class SearchTest method TestIgnorable.
@Test
public void TestIgnorable() {
String rules = IGNORABLERULE;
int count = 0;
RuleBasedCollator collator = null;
try {
collator = new RuleBasedCollator(rules);
collator.setStrength(IGNORABLE[count].strength);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
} catch (Exception e) {
errln("Error opening collator ");
return;
}
String pattern = "pattern";
String text = "text";
StringSearch strsrch = null;
try {
strsrch = new StringSearch(pattern, new StringCharacterIterator(text), collator, null);
} catch (Exception e) {
errln("Error opening string search ");
return;
}
for (; count < IGNORABLE.length; count++) {
text = IGNORABLE[count].text;
pattern = IGNORABLE[count].pattern;
strsrch.setTarget(new StringCharacterIterator(text));
strsrch.setPattern(pattern);
if (!assertEqualWithStringSearch(strsrch, IGNORABLE[count])) {
errln("Error at test number " + count);
}
}
}
use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class SearchTest method TestOverlap.
@Test
public void TestOverlap() {
int count;
for (count = 0; count < OVERLAP.length; count++) {
if (!assertEqualWithAttribute(OVERLAP[count], false, true)) {
errln("Error at overlap test number " + count);
}
}
for (count = 0; count < NONOVERLAP.length; count++) {
if (!assertEqual(NONOVERLAP[count])) {
errln("Error at non overlap test number " + count);
}
}
for (count = 0; count < OVERLAP.length && count < NONOVERLAP.length; count++) {
SearchData search = (OVERLAP[count]);
String text = search.text;
String pattern = search.pattern;
RuleBasedCollator collator = getCollator(search.collator);
StringSearch strsrch = null;
try {
strsrch = new StringSearch(pattern, new StringCharacterIterator(text), collator, null);
} catch (Exception e) {
errln("error open StringSearch");
return;
}
strsrch.setOverlapping(true);
if (!strsrch.isOverlapping()) {
errln("Error setting overlap option");
}
if (!assertEqualWithStringSearch(strsrch, search)) {
return;
}
search = NONOVERLAP[count];
strsrch.setOverlapping(false);
if (strsrch.isOverlapping()) {
errln("Error setting overlap option");
}
strsrch.reset();
if (!assertEqualWithStringSearch(strsrch, search)) {
errln("Error at test number " + count);
}
}
}
use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class SearchTest method TestBreakIteratorCanonical.
@Test
public void TestBreakIteratorCanonical() {
int count = 0;
while (count < 4) {
// special purposes for tests numbers 0-3
SearchData search = BREAKITERATORCANONICAL[count];
String text = search.text;
String pattern = search.pattern;
RuleBasedCollator collator = getCollator(search.collator);
collator.setStrength(search.strength);
BreakIterator breaker = getBreakIterator(search.breaker);
StringSearch strsrch = null;
try {
strsrch = new StringSearch(pattern, new StringCharacterIterator(text), collator, breaker);
} catch (Exception e) {
errln("Error creating string search data");
return;
}
strsrch.setCanonical(true);
if (!strsrch.getBreakIterator().equals(breaker)) {
errln("Error setting break iterator");
return;
}
if (!assertEqualWithStringSearch(strsrch, search)) {
collator.setStrength(TERTIARY);
return;
}
search = BREAKITERATOREXACT[count + 1];
breaker = getBreakIterator(search.breaker);
breaker.setText(strsrch.getTarget());
strsrch.setBreakIterator(breaker);
if (!strsrch.getBreakIterator().equals(breaker)) {
errln("Error setting break iterator");
return;
}
strsrch.reset();
strsrch.setCanonical(true);
if (!assertEqualWithStringSearch(strsrch, search)) {
errln("Error at test number " + count);
return;
}
count += 2;
}
for (count = 0; count < BREAKITERATORCANONICAL.length; count++) {
if (!assertEqual(BREAKITERATORCANONICAL[count])) {
errln("Error at test number " + count);
return;
}
}
}
use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class SearchTest method TestConstructor.
@Test
public void TestConstructor() {
String pattern = "pattern";
String text = "text";
StringCharacterIterator textiter = new StringCharacterIterator(text);
Collator defaultcollator = Collator.getInstance();
BreakIterator breaker = BreakIterator.getCharacterInstance();
breaker.setText(text);
StringSearch search = new StringSearch(pattern, text);
if (!search.getPattern().equals(pattern) || !search.getTarget().equals(textiter) || !search.getCollator().equals(defaultcollator)) /*|| !search.getBreakIterator().equals(breaker)*/
{
errln("StringSearch(String, String) error");
}
search = new StringSearch(pattern, textiter, m_fr_fr_);
if (!search.getPattern().equals(pattern) || !search.getTarget().equals(textiter) || !search.getCollator().equals(m_fr_fr_)) /*|| !search.getBreakIterator().equals(breaker)*/
{
errln("StringSearch(String, StringCharacterIterator, " + "RuleBasedCollator) error");
}
Locale de = new Locale("de", "DE");
breaker = BreakIterator.getCharacterInstance(de);
breaker.setText(text);
search = new StringSearch(pattern, textiter, de);
if (!search.getPattern().equals(pattern) || !search.getTarget().equals(textiter) || !search.getCollator().equals(Collator.getInstance(de))) /*|| !search.getBreakIterator().equals(breaker)*/
{
errln("StringSearch(String, StringCharacterIterator, Locale) " + "error");
}
search = new StringSearch(pattern, textiter, m_fr_fr_, m_en_wordbreaker_);
if (!search.getPattern().equals(pattern) || !search.getTarget().equals(textiter) || !search.getCollator().equals(m_fr_fr_) || !search.getBreakIterator().equals(m_en_wordbreaker_)) {
errln("StringSearch(String, StringCharacterIterator, Locale) " + "error");
}
}
use of android.icu.text.RuleBasedCollator in project j2objc by google.
the class SearchTest method assertCanonicalEqual.
boolean assertCanonicalEqual(SearchData search) {
Collator collator = getCollator(search.collator);
BreakIterator breaker = getBreakIterator(search.breaker);
StringSearch strsrch;
String text = search.text;
String pattern = search.pattern;
if (breaker != null) {
breaker.setText(text);
}
collator.setStrength(search.strength);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
try {
strsrch = new StringSearch(pattern, new StringCharacterIterator(text), (RuleBasedCollator) collator, breaker);
strsrch.setElementComparisonType(search.cmpType);
strsrch.setCanonical(true);
} catch (Exception e) {
errln("Error opening string search" + e.getMessage());
return false;
}
if (!assertEqualWithStringSearch(strsrch, search)) {
collator.setStrength(TERTIARY);
collator.setDecomposition(Collator.NO_DECOMPOSITION);
return false;
}
collator.setStrength(TERTIARY);
collator.setDecomposition(Collator.NO_DECOMPOSITION);
return true;
}
Aggregations