Search in sources :

Example 1 with StringPrep

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

the class TestIDNA method TestNamePrepConformance.

@Test
public void TestNamePrepConformance() throws Exception {
    StringPrep namePrep = StringPrep.getInstance(StringPrep.RFC3491_NAMEPREP);
    for (int i = 0; i < TestData.conformanceTestCases.length; i++) {
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
        try {
            StringBuffer output = namePrep.prepare(iter, StringPrep.DEFAULT);
            if (testCase.output != null && output != null && !testCase.output.equals(output.toString())) {
                errln("Did not get the expected output. Expected: " + prettify(testCase.output) + " Got: " + prettify(output));
            }
            if (testCase.expected != null && !unassignedException.equals(testCase.expected)) {
                errln("Did not get the expected exception. The operation succeeded!");
            }
        } catch (StringPrepParseException ex) {
            if (testCase.expected == null || !ex.equals(testCase.expected)) {
                errln("Did not get the expected exception for source: " + testCase.input + " Got:  " + ex.toString());
            }
        }
        try {
            iter.setToStart();
            StringBuffer output = namePrep.prepare(iter, StringPrep.ALLOW_UNASSIGNED);
            if (testCase.output != null && output != null && !testCase.output.equals(output.toString())) {
                errln("Did not get the expected output. Expected: " + prettify(testCase.output) + " Got: " + prettify(output));
            }
            if (testCase.expected != null && !unassignedException.equals(testCase.expected)) {
                errln("Did not get the expected exception. The operation succeeded!");
            }
        } catch (StringPrepParseException ex) {
            if (testCase.expected == null || !ex.equals(testCase.expected)) {
                errln("Did not get the expected exception for source: " + testCase.input + " Got:  " + ex.toString());
            }
        }
    }
}
Also used : StringPrepParseException(android.icu.text.StringPrepParseException) StringPrep(android.icu.text.StringPrep) UCharacterIterator(android.icu.text.UCharacterIterator) Test(org.junit.Test)

Example 2 with StringPrep

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

the class TestStringPrepProfiles method TestProfiles.

@Test
public void TestProfiles() {
    String profileName = null;
    StringPrep sprep = null;
    String result = null;
    String src = null;
    String expected = null;
    for (int i = 0; i < testCases.length; i++) {
        for (int j = 0; j < testCases[i].length; j++) {
            if (j == 0) {
                profileName = testCases[i][j];
                sprep = StringPrep.getInstance(getOptionFromProfileName(profileName));
            } else {
                src = testCases[i][j];
                expected = testCases[i][++j];
                try {
                    result = sprep.prepare(src, StringPrep.ALLOW_UNASSIGNED);
                    if (src.startsWith("FAIL")) {
                        errln("Failed: Expected error for Test[" + i + "] Profile: " + profileName);
                    } else if (!result.equals(expected)) {
                        errln("Failed: Test[" + i + "] Result string does not match expected string for StringPrep test for profile: " + profileName);
                    }
                } catch (StringPrepParseException ex) {
                    if (!src.startsWith("FAIL")) {
                        errln("Failed: Test[" + i + "] StringPrep profile " + profileName + " got error: " + ex);
                    }
                }
            }
        }
    }
}
Also used : StringPrepParseException(android.icu.text.StringPrepParseException) StringPrep(android.icu.text.StringPrep) Test(org.junit.Test)

Aggregations

StringPrep (android.icu.text.StringPrep)2 StringPrepParseException (android.icu.text.StringPrepParseException)2 Test (org.junit.Test)2 UCharacterIterator (android.icu.text.UCharacterIterator)1