Search in sources :

Example 6 with ReplaceableString

use of android.icu.text.ReplaceableString in project j2objc by google.

the class StringTokenizerTest method TestMatches.

/* Tests the method
     *      public int matches(Replaceable text, int[] offset, int limit, boolean incremental)
     */
@Test
public void TestMatches() {
    // Tests when "return incremental ? U_PARTIAL_MATCH : U_MATCH;" is true and false
    ReplaceableString rs = new ReplaceableString("dummy");
    // Create a large Unicode set
    UnicodeSet us = new UnicodeSet(0, 100000);
    us.add("dummy");
    int[] offset = { 0 };
    int limit = 0;
    if (us.matches(null, offset, limit, true) != UnicodeSet.U_PARTIAL_MATCH) {
        errln("UnicodeSet.matches is suppose to return " + UnicodeSet.U_PARTIAL_MATCH + " but got " + us.matches(null, offset, limit, true));
    }
    if (us.matches(null, offset, limit, false) != UnicodeSet.U_MATCH) {
        errln("UnicodeSet.matches is suppose to return " + UnicodeSet.U_MATCH + " but got " + us.matches(null, offset, limit, false));
    }
    // Tests when "int maxLen = forward ? limit-offset[0] : offset[0]-limit;" is true and false
    try {
        // Takes the letter "d"
        offset[0] = 0;
        us.matches(rs, offset, 1, true);
        // Takes the letter "y"
        offset[0] = 4;
        us.matches(rs, offset, 1, true);
    } catch (Exception e) {
        errln("UnicodeSet.matches is not suppose to return an exception");
    }
// TODO: Tests when "if (forward && length < highWaterLength)" is true
}
Also used : ReplaceableString(android.icu.text.ReplaceableString) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 7 with ReplaceableString

use of android.icu.text.ReplaceableString in project j2objc by google.

the class CompoundTransliteratorTest method TestTransliterate.

@Test
public void TestTransliterate() {
    logln("Testing the handleTransliterate() API of CompoundTransliterator");
    Transliterator ct1 = null;
    try {
        ct1 = Transliterator.getInstance("Any-Hex;Hex-Any");
    } catch (IllegalArgumentException iae) {
        errln("FAIL: construction using CompoundTransliterator(String ID) failed for " + "Any-Hex;Hex-Any");
        throw iae;
    }
    String s = "abcabc";
    expect(ct1, s, s);
    Transliterator.Position index = new Transliterator.Position();
    ReplaceableString rsource2 = new ReplaceableString(s);
    String expectedResult = s;
    ct1.transliterate(rsource2, index);
    ct1.finishTransliteration(rsource2, index);
    String result = rsource2.toString();
    expectAux(ct1.getID() + ":ReplaceableString, index(0,0,0,0)", s + "->" + rsource2, result.equals(expectedResult), expectedResult);
    Transliterator.Position index2 = new Transliterator.Position(1, 3, 2, 3);
    ReplaceableString rsource3 = new ReplaceableString(s);
    ct1.transliterate(rsource3, index2);
    ct1.finishTransliteration(rsource3, index2);
    result = rsource3.toString();
    expectAux(ct1.getID() + ":String, index2(1,2,2,3)", s + "->" + rsource3, result.equals(expectedResult), expectedResult);
    String[] Data = { // ID, input string, transliterated string
    "Any-Hex;Hex-Any;Any-Hex", "hello", "\\u0068\\u0065\\u006C\\u006C\\u006F", "Any-Hex;Hex-Any", "hello! How are you?", "hello! How are you?", // quotes lost
    "Devanagari-Latin;Latin-Devanagari", // quotes lost
    "\u092D\u0948'\u0930'\u0935", // quotes lost
    "\u092D\u0948\u0930\u0935", "Latin-Cyrillic;Cyrillic-Latin", "a'b'k'd'e'f'g'h'i'j'Shch'shch'zh'h", "a'b'k'd'e'f'g'h'i'j'Shch'shch'zh'h", "Latin-Greek;Greek-Latin", "ABGabgAKLMN", "ABGabgAKLMN", // "Latin-Arabic;Arabic-Latin",               "Ad'r'a'b'i'k'dh'dd'gh", "Adrabikdhddgh",
    "Hiragana-Katakana", "\u3041\u308f\u3099\u306e\u304b\u3092\u3099", "\u30A1\u30f7\u30ce\u30ab\u30fa", "Hiragana-Katakana;Katakana-Hiragana", "\u3041\u308f\u3099\u306e\u304b\u3051", "\u3041\u308f\u3099\u306e\u304b\u3051", "Katakana-Hiragana;Hiragana-Katakana", "\u30A1\u30f7\u30ce\u30f5\u30f6", "\u30A1\u30f7\u30ce\u30ab\u30b1", "Latin-Katakana;Katakana-Latin", "vavivuvevohuzizuzoninunasesuzezu", "vavivuvevohuzizuzoninunasesuzezu" };
    Transliterator ct2 = null;
    for (int i = 0; i < Data.length; i += 3) {
        try {
            ct2 = Transliterator.getInstance(Data[i + 0]);
        } catch (IllegalArgumentException iae2) {
            errln("FAIL: CompoundTransliterator construction failed for " + Data[i + 0]);
            throw iae2;
        }
        expect(ct2, Data[i + 1], Data[i + 2]);
    }
}
Also used : ReplaceableString(android.icu.text.ReplaceableString) ReplaceableString(android.icu.text.ReplaceableString) Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Example 8 with ReplaceableString

use of android.icu.text.ReplaceableString in project j2objc by google.

the class TransliteratorTest method keyboardAux.

private void keyboardAux(Transliterator t, String[] DATA) {
    Transliterator.Position index = new Transliterator.Position();
    ReplaceableString s = new ReplaceableString();
    for (int i = 0; i < DATA.length; i += 2) {
        StringBuffer log;
        if (DATA[i] != null) {
            log = new StringBuffer(s.toString() + " + " + DATA[i] + " -> ");
            t.transliterate(s, index, DATA[i]);
        } else {
            log = new StringBuffer(s.toString() + " => ");
            t.finishTransliteration(s, index);
        }
        UtilityExtensions.formatInput(log, s, index);
        if (s.toString().equals(DATA[i + 1])) {
            logln(log.toString());
        } else {
            errln("FAIL: " + log.toString() + ", expected " + DATA[i + 1]);
        }
    }
}
Also used : ReplaceableString(android.icu.text.ReplaceableString) Transliterator(android.icu.text.Transliterator)

Example 9 with ReplaceableString

use of android.icu.text.ReplaceableString in project j2objc by google.

the class TransliteratorTest method CheckIncrementalAux.

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 && pos.limit != 0 && !t.getID().equals("Hex-Any/Unicode")) {
        errln("No Progress, " + t.getID() + ": " + UtilityExtensions.formatInput(test, pos));
        gotError = true;
    } else {
        logln("PASS Progress, " + t.getID() + ": " + UtilityExtensions.formatInput(test, pos));
    }
    t.finishTransliteration(test, pos);
    if (pos.start != pos.limit) {
        errln("Incomplete, " + t.getID() + ":  " + UtilityExtensions.formatInput(test, pos));
        gotError = true;
    }
    if (!gotError) {
    // errln("FAIL: Did not get expected error");
    }
}
Also used : ReplaceableString(android.icu.text.ReplaceableString) Replaceable(android.icu.text.Replaceable) Transliterator(android.icu.text.Transliterator)

Example 10 with ReplaceableString

use of android.icu.text.ReplaceableString in project j2objc by google.

the class TransliteratorTest method TestPositionHandling.

/**
 * Confirm that the contextStart, contextLimit, start, and limit
 * behave correctly.
 */
@Test
public void TestPositionHandling() {
    // Array of 3n items
    // Each item is <rules>, <input>, <expected output>
    String[] DATA = { "a{t} > SS ; {t}b > UU ; {t} > TT ;", // pos 0,9,0,9
    "xtat txtb", "xTTaSS TTxUUb", "a{t} > SS ; {t}b > UU ; {t} > TT ;", // pos 2,9,3,8
    "xtat txtb", "xtaSS TTxUUb", "a{t} > SS ; {t}b > UU ; {t} > TT ;", // pos 3,8,3,8
    "xtat txtb", "xtaTT TTxTTb" };
    // Array of 4n positions -- these go with the DATA array
    // They are: contextStart, contextLimit, start, limit
    int[] POS = { 0, 9, 0, 9, 2, 9, 3, 8, 3, 8, 3, 8 };
    int n = DATA.length / 3;
    for (int i = 0; i < n; i++) {
        Transliterator t = Transliterator.createFromRules("<ID>", DATA[3 * i], Transliterator.FORWARD);
        Transliterator.Position pos = new Transliterator.Position(POS[4 * i], POS[4 * i + 1], POS[4 * i + 2], POS[4 * i + 3]);
        ReplaceableString rsource = new ReplaceableString(DATA[3 * i + 1]);
        t.transliterate(rsource, pos);
        t.finishTransliteration(rsource, pos);
        String result = rsource.toString();
        String exp = DATA[3 * i + 2];
        expectAux(Utility.escape(DATA[3 * i]), DATA[3 * i + 1], result, result.equals(exp), exp);
    }
}
Also used : ReplaceableString(android.icu.text.ReplaceableString) CaseInsensitiveString(android.icu.util.CaseInsensitiveString) ReplaceableString(android.icu.text.ReplaceableString) Transliterator(android.icu.text.Transliterator) Test(org.junit.Test)

Aggregations

ReplaceableString (android.icu.text.ReplaceableString)12 Transliterator (android.icu.text.Transliterator)8 Test (org.junit.Test)7 CaseInsensitiveString (android.icu.util.CaseInsensitiveString)3 Replaceable (android.icu.text.Replaceable)1 UCharacterIterator (android.icu.text.UCharacterIterator)1 UnicodeSet (android.icu.text.UnicodeSet)1 CharacterIterator (java.text.CharacterIterator)1 StringCharacterIterator (java.text.StringCharacterIterator)1 ArrayList (java.util.ArrayList)1