Java Code Examples for java.util.Locale.LanguageRange#parse()

The following examples show how to use java.util.Locale.LanguageRange#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bug8040211.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void test_filterTags() {
    boolean error = false;

    String ranges = "gti;q=0.2, gfx, kzj";
    String tags = "de-DE, gti, he, nyc, mwj, vaj, ktr, dtp";

    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTags
            = showLanguageTags(Locale.filterTags(priorityList, tagList));
    String expectedTags = "mwj, vaj, ktr, dtp, gti, nyc";

    if (!expectedTags.equals(actualTags)) {
        error = true;
        showErrorMessage("filterTags()",
                ranges, tags, expectedTags, actualTags);
    }

    if (error) {
        err = true;
        System.out.println("  test_filterTags() failed.");
    } else {
        System.out.println("  test_filterTags() passed.");
    }
}
 
Example 2
Source File: Bug8040211.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookupTag() {
    boolean error = false;

    String ranges = "en, tsf;q=0.2";
    String tags = "es, ja-JP, taj";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTag = Locale.lookupTag(priorityList, tagList);
    String expectedTag = "taj";

    if (!expectedTag.equals(actualTag)) {
        error = true;
        showErrorMessage("lookupTag()", ranges, tags, expectedTag, actualTag);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookupTag() failed.");
    } else {
        System.out.println("  test_lookupTag() passed.");
    }
}
 
Example 3
Source File: Bug8040211.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookupTag() {
    boolean error = false;

    String ranges = "en, tsf;q=0.2";
    String tags = "es, ja-JP, taj";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTag = Locale.lookupTag(priorityList, tagList);
    String expectedTag = "taj";

    if (!expectedTag.equals(actualTag)) {
        error = true;
        showErrorMessage("lookupTag()", ranges, tags, expectedTag, actualTag);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookupTag() failed.");
    } else {
        System.out.println("  test_lookupTag() passed.");
    }
}
 
Example 4
Source File: Bug8040211.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookup() {
    boolean error = false;

    String ranges = "en;q=0.2, yam, rmx;q=0.9";
    String tags = "de-DE, en, kwq, lmm";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    String actualLocale
            = Locale.lookup(priorityList, localeList).toLanguageTag();
    String expectedLocale = "kwq";

    if (!expectedLocale.equals(actualLocale)) {
        error = true;
        showErrorMessage("lookup()", ranges, tags, expectedLocale, actualLocale);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookup() failed.");
    } else {
        System.out.println("  test_lookup() passed.");
    }
}
 
Example 5
Source File: Bug8040211.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void test_filterTags() {
    boolean error = false;

    String ranges = "gti;q=0.2, gfx";
    String tags = "de-DE, gti, he, nyc, mwj, vaj";

    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTags
            = showLanguageTags(Locale.filterTags(priorityList, tagList));
    String expectedTags = "mwj, vaj, gti, nyc";

    if (!expectedTags.equals(actualTags)) {
        error = true;
        showErrorMessage("filterTags()",
                ranges, tags, expectedTags, actualTags);
    }

    if (error) {
        err = true;
        System.out.println("  test_filterTags() failed.");
    } else {
        System.out.println("  test_filterTags() passed.");
    }
}
 
Example 6
Source File: Bug8040211.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookup() {
    boolean error = false;

    String ranges = "en;q=0.2, yam, rmx;q=0.9";
    String tags = "de-DE, en, kwq, lmm";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    String actualLocale
            = Locale.lookup(priorityList, localeList).toLanguageTag();
    String expectedLocale = "kwq";

    if (!expectedLocale.equals(actualLocale)) {
        error = true;
        showErrorMessage("lookup()", ranges, tags, expectedLocale, actualLocale);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookup() failed.");
    } else {
        System.out.println("  test_lookup() passed.");
    }
}
 
Example 7
Source File: Bug8040211.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookupTag() {
    boolean error = false;

    String ranges = "en, tsf;q=0.2";
    String tags = "es, ja-JP, taj";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTag = Locale.lookupTag(priorityList, tagList);
    String expectedTag = "taj";

    if (!expectedTag.equals(actualTag)) {
        error = true;
        showErrorMessage("lookupTag()", ranges, tags, expectedTag, actualTag);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookupTag() failed.");
    } else {
        System.out.println("  test_lookupTag() passed.");
    }
}
 
Example 8
Source File: Bug8040211.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookupTag() {
    boolean error = false;

    String ranges = "en, tsf;q=0.2";
    String tags = "es, ja-JP, taj";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTag = Locale.lookupTag(priorityList, tagList);
    String expectedTag = "taj";

    if (!expectedTag.equals(actualTag)) {
        error = true;
        showErrorMessage("lookupTag()", ranges, tags, expectedTag, actualTag);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookupTag() failed.");
    } else {
        System.out.println("  test_lookupTag() passed.");
    }
}
 
Example 9
Source File: Bug8040211.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void test_filterTags() {
    boolean error = false;

    String ranges = "gti;q=0.2, gfx, kzj";
    String tags = "de-DE, gti, he, nyc, mwj, vaj, ktr, dtp";

    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTags
            = showLanguageTags(Locale.filterTags(priorityList, tagList));
    String expectedTags = "mwj, vaj, ktr, dtp, gti, nyc";

    if (!expectedTags.equals(actualTags)) {
        error = true;
        showErrorMessage("filterTags()",
                ranges, tags, expectedTags, actualTags);
    }

    if (error) {
        err = true;
        System.out.println("  test_filterTags() failed.");
    } else {
        System.out.println("  test_filterTags() passed.");
    }
}
 
Example 10
Source File: Bug8040211.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookup() {
    boolean error = false;

    String ranges = "en;q=0.2, yam, rmx;q=0.9";
    String tags = "de-DE, en, kwq, lmm";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    String actualLocale
            = Locale.lookup(priorityList, localeList).toLanguageTag();
    String expectedLocale = "kwq";

    if (!expectedLocale.equals(actualLocale)) {
        error = true;
        showErrorMessage("lookup()", ranges, tags, expectedLocale, actualLocale);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookup() failed.");
    } else {
        System.out.println("  test_lookup() passed.");
    }
}
 
Example 11
Source File: Bug8040211.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void test_lookupTag() {
    boolean error = false;

    String ranges = "en, tsf;q=0.2";
    String tags = "es, ja-JP, taj";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<String> tagList = generateLanguageTags(tags);
    String actualTag = Locale.lookupTag(priorityList, tagList);
    String expectedTag = "taj";

    if (!expectedTag.equals(actualTag)) {
        error = true;
        showErrorMessage("lookupTag()", ranges, tags, expectedTag, actualTag);
    }

    if (error) {
        err = true;
        System.out.println("  test_lookupTag() failed.");
    } else {
        System.out.println("  test_lookupTag() passed.");
    }
}
 
Example 12
Source File: AcceptLanguageLocaleResolver.java    From nubes with Apache License 2.0 5 votes vote down vote up
@Override
public Locale resolve(RoutingContext context, List<Locale> availableLocales) {
  String accept = context.request().getHeader(ACCEPT_LANGUAGE.toString());
  if (accept == null) {
    return null;
  }
  List<LanguageRange> ranges = LanguageRange.parse(accept);
  if (ranges.isEmpty()) {
    return null;
  }
  return Locale.lookup(ranges, availableLocales);
}
 
Example 13
Source File: Bug8159420.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testFilter(FilteringMode mode) {

        String ranges = "hi-IN, itc-Ital";
        String tags = "hi-IN, itc-Ital";
        List<LanguageRange> priorityList = LanguageRange.parse(ranges);
        List<Locale> tagList = generateLocales(tags);
        String actualLocales = showLocales(Locale.filter(priorityList, tagList, mode));
        String expectedLocales = "hi-IN, itc-Ital";

        if (!expectedLocales.equals(actualLocales)) {
            System.err.println("testFilter(" + mode + ") failed on language ranges:"
                    + " [" + ranges + "] and language tags: [" + tags + "]");
            err = true;
        }
    }
 
Example 14
Source File: Bug8159420.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testParse() {
    String ranges = "HI-Deva, ja-hIrA-JP, RKI";
    try {
        LanguageRange.parse(ranges);
    } catch (Exception ex) {
        System.err.println("[testParse() failed on range string: "
                + ranges + "] due to "+ex);
        err = true;
    }
}
 
Example 15
Source File: Bug8040211.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void test_parse() {
    boolean error = false;
    String str = "Accept-Language: aam, adp, aue, bcg, cqu, ema,"
            + " en-gb-oed, gti, kdz, koj, kwq, kxe, lii, lmm, mtm, ngv,"
            + " oyb, phr, pub, suj, taj;q=0.9, ar-hyw;q=0.8, yug;q=0.5, gfx;q=0.4";
    ArrayList<LanguageRange> expected = new ArrayList<>();
    expected.add(new LanguageRange("aam", 1.0));
    expected.add(new LanguageRange("aas", 1.0));
    expected.add(new LanguageRange("adp", 1.0));
    expected.add(new LanguageRange("dz", 1.0));
    expected.add(new LanguageRange("aue", 1.0));
    expected.add(new LanguageRange("ktz", 1.0));
    expected.add(new LanguageRange("bcg", 1.0));
    expected.add(new LanguageRange("bgm", 1.0));
    expected.add(new LanguageRange("cqu", 1.0));
    expected.add(new LanguageRange("quh", 1.0));
    expected.add(new LanguageRange("ema", 1.0));
    expected.add(new LanguageRange("uok", 1.0));
    expected.add(new LanguageRange("en-gb-oed", 1.0));
    expected.add(new LanguageRange("en-gb-oxendict", 1.0));
    expected.add(new LanguageRange("gti", 1.0));
    expected.add(new LanguageRange("nyc", 1.0));
    expected.add(new LanguageRange("kdz", 1.0));
    expected.add(new LanguageRange("ncp", 1.0));
    expected.add(new LanguageRange("koj", 1.0));
    expected.add(new LanguageRange("kwv", 1.0));
    expected.add(new LanguageRange("kwq", 1.0));
    expected.add(new LanguageRange("yam", 1.0));
    expected.add(new LanguageRange("kxe", 1.0));
    expected.add(new LanguageRange("tvd", 1.0));
    expected.add(new LanguageRange("lii", 1.0));
    expected.add(new LanguageRange("raq", 1.0));
    expected.add(new LanguageRange("lmm", 1.0));
    expected.add(new LanguageRange("rmx", 1.0));
    expected.add(new LanguageRange("mtm", 1.0));
    expected.add(new LanguageRange("ymt", 1.0));
    expected.add(new LanguageRange("ngv", 1.0));
    expected.add(new LanguageRange("nnx", 1.0));
    expected.add(new LanguageRange("oyb", 1.0));
    expected.add(new LanguageRange("thx", 1.0));
    expected.add(new LanguageRange("skk", 1.0));
    expected.add(new LanguageRange("jeg", 1.0));
    expected.add(new LanguageRange("phr", 1.0));
    expected.add(new LanguageRange("pmu", 1.0));
    expected.add(new LanguageRange("pub", 1.0));
    expected.add(new LanguageRange("puz", 1.0));
    expected.add(new LanguageRange("suj", 1.0));
    expected.add(new LanguageRange("xsj", 1.0));
    expected.add(new LanguageRange("taj", 0.9));
    expected.add(new LanguageRange("tsf", 0.9));
    expected.add(new LanguageRange("ar-hyw", 0.8));
    expected.add(new LanguageRange("yug", 0.5));
    expected.add(new LanguageRange("yuu", 0.5));
    expected.add(new LanguageRange("gfx", 0.4));
    expected.add(new LanguageRange("oun", 0.4));
    expected.add(new LanguageRange("mwj", 0.4));
    expected.add(new LanguageRange("vaj", 0.4));
    List<LanguageRange> got = LanguageRange.parse(str);
    if (!areEqual(expected, got)) {
        error = true;
        System.err.println("    language parse() test failed.");
    }

    if (error) {
        err = true;
        System.err.println("  test_parse() failed.");
    } else {
        System.out.println("  test_parse() passed.");
    }

}
 
Example 16
Source File: Bug8040211.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void test_parse() {
    boolean error = false;
    String str = "Accept-Language: aam, adp, aue, ema, en-gb-oed,"
            + " gti, koj, kwq, kxe, lii, lmm, mtm, ngv, oyb, phr, pub,"
            + " suj, taj;q=0.9, yug;q=0.5, gfx;q=0.4";
    ArrayList<LanguageRange> expected = new ArrayList<>();
    expected.add(new LanguageRange("aam", 1.0));
    expected.add(new LanguageRange("aas", 1.0));
    expected.add(new LanguageRange("adp", 1.0));
    expected.add(new LanguageRange("dz", 1.0));
    expected.add(new LanguageRange("aue", 1.0));
    expected.add(new LanguageRange("ktz", 1.0));
    expected.add(new LanguageRange("ema", 1.0));
    expected.add(new LanguageRange("uok", 1.0));
    expected.add(new LanguageRange("en-gb-oed", 1.0));
    expected.add(new LanguageRange("en-gb-oxendict", 1.0));
    expected.add(new LanguageRange("gti", 1.0));
    expected.add(new LanguageRange("nyc", 1.0));
    expected.add(new LanguageRange("koj", 1.0));
    expected.add(new LanguageRange("kwv", 1.0));
    expected.add(new LanguageRange("kwq", 1.0));
    expected.add(new LanguageRange("yam", 1.0));
    expected.add(new LanguageRange("kxe", 1.0));
    expected.add(new LanguageRange("tvd", 1.0));
    expected.add(new LanguageRange("lii", 1.0));
    expected.add(new LanguageRange("raq", 1.0));
    expected.add(new LanguageRange("lmm", 1.0));
    expected.add(new LanguageRange("rmx", 1.0));
    expected.add(new LanguageRange("mtm", 1.0));
    expected.add(new LanguageRange("ymt", 1.0));
    expected.add(new LanguageRange("ngv", 1.0));
    expected.add(new LanguageRange("nnx", 1.0));
    expected.add(new LanguageRange("oyb", 1.0));
    expected.add(new LanguageRange("thx", 1.0));
    expected.add(new LanguageRange("phr", 1.0));
    expected.add(new LanguageRange("pmu", 1.0));
    expected.add(new LanguageRange("pub", 1.0));
    expected.add(new LanguageRange("puz", 1.0));
    expected.add(new LanguageRange("suj", 1.0));
    expected.add(new LanguageRange("xsj", 1.0));
    expected.add(new LanguageRange("taj", 0.9));
    expected.add(new LanguageRange("tsf", 0.9));
    expected.add(new LanguageRange("yug", 0.5));
    expected.add(new LanguageRange("yuu", 0.5));
    expected.add(new LanguageRange("gfx", 0.4));
    expected.add(new LanguageRange("oun", 0.4));
    expected.add(new LanguageRange("mwj", 0.4));
    expected.add(new LanguageRange("vaj", 0.4));
    List<LanguageRange> got = LanguageRange.parse(str);
    if (!areEqual(expected, got)) {
        error = true;
        System.err.println("    language parse() test failed.");
    }

    if (error) {
        err = true;
        System.err.println("  test_parse() failed.");
    } else {
        System.out.println("  test_parse() passed.");
    }

}
 
Example 17
Source File: Bug8040211.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void test_filter() {
    boolean error = false;

    String ranges = "mtm-RU, en-gb-oed, coy, ar-HY";
    String tags = "de-DE, en, mtm-RU, ymt-RU, en-gb-oxendict, ja-JP, pij, nts, ar-arevela";
    FilteringMode mode = EXTENDED_FILTERING;

    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> tagList = generateLocales(tags);
    String actualLocales
            = showLocales(Locale.filter(priorityList, tagList, mode));
    String expectedLocales = "mtm-RU, ymt-RU, en-GB-oxendict, nts, pij";

    if (!expectedLocales.equals(actualLocales)) {
        error = true;
        showErrorMessage("#1 filter(" + mode + ")",
                ranges, tags, expectedLocales, actualLocales);
    }

    ranges = "phr-*-IN, ja-JP";
    tags = "en, pmu-Guru-IN, ja-Latn-JP, iw";
    mode = EXTENDED_FILTERING;

    priorityList = LanguageRange.parse(ranges);
    tagList = generateLocales(tags);
    actualLocales = showLocales(Locale.filter(priorityList, tagList, mode));
    expectedLocales = "pmu-Guru-IN, ja-Latn-JP";

    if (!expectedLocales.equals(actualLocales)) {
        error = true;
        showErrorMessage("#2 filter(" + mode + ")",
                ranges, tags, expectedLocales, actualLocales);
    }

    if (error) {
        err = true;
        System.out.println("  test_filter() failed.");
    } else {
        System.out.println("  test_filter() passed.");
    }
}
 
Example 18
Source File: Bug8040211.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void test_filter() {
    boolean error = false;

    String ranges = "mtm-RU, en-gb-oed, coy, ar-HY";
    String tags = "de-DE, en, mtm-RU, ymt-RU, en-gb-oxendict, ja-JP, pij, nts, ar-arevela";
    FilteringMode mode = EXTENDED_FILTERING;

    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> tagList = generateLocales(tags);
    String actualLocales
            = showLocales(Locale.filter(priorityList, tagList, mode));
    String expectedLocales = "mtm-RU, ymt-RU, en-GB-oxendict, nts, pij";

    if (!expectedLocales.equals(actualLocales)) {
        error = true;
        showErrorMessage("#1 filter(" + mode + ")",
                ranges, tags, expectedLocales, actualLocales);
    }

    ranges = "phr-*-IN, ja-JP";
    tags = "en, pmu-Guru-IN, ja-Latn-JP, iw";
    mode = EXTENDED_FILTERING;

    priorityList = LanguageRange.parse(ranges);
    tagList = generateLocales(tags);
    actualLocales = showLocales(Locale.filter(priorityList, tagList, mode));
    expectedLocales = "pmu-Guru-IN, ja-Latn-JP";

    if (!expectedLocales.equals(actualLocales)) {
        error = true;
        showErrorMessage("#2 filter(" + mode + ")",
                ranges, tags, expectedLocales, actualLocales);
    }

    if (error) {
        err = true;
        System.out.println("  test_filter() failed.");
    } else {
        System.out.println("  test_filter() passed.");
    }
}
 
Example 19
Source File: Bug8040211.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void test_parse() {
    boolean error = false;
    String str = "Accept-Language: aam, adp, aue, bcg, cqu, ema,"
            + " en-gb-oed, gti, kdz, koj, kwq, kxe, lii, lmm, mtm, ngv,"
            + " oyb, phr, pub, suj, taj;q=0.9, ar-hyw;q=0.8, yug;q=0.5, gfx;q=0.4";
    ArrayList<LanguageRange> expected = new ArrayList<>();
    expected.add(new LanguageRange("aam", 1.0));
    expected.add(new LanguageRange("aas", 1.0));
    expected.add(new LanguageRange("adp", 1.0));
    expected.add(new LanguageRange("dz", 1.0));
    expected.add(new LanguageRange("aue", 1.0));
    expected.add(new LanguageRange("ktz", 1.0));
    expected.add(new LanguageRange("bcg", 1.0));
    expected.add(new LanguageRange("bgm", 1.0));
    expected.add(new LanguageRange("cqu", 1.0));
    expected.add(new LanguageRange("quh", 1.0));
    expected.add(new LanguageRange("ema", 1.0));
    expected.add(new LanguageRange("uok", 1.0));
    expected.add(new LanguageRange("en-gb-oed", 1.0));
    expected.add(new LanguageRange("en-gb-oxendict", 1.0));
    expected.add(new LanguageRange("gti", 1.0));
    expected.add(new LanguageRange("nyc", 1.0));
    expected.add(new LanguageRange("kdz", 1.0));
    expected.add(new LanguageRange("ncp", 1.0));
    expected.add(new LanguageRange("koj", 1.0));
    expected.add(new LanguageRange("kwv", 1.0));
    expected.add(new LanguageRange("kwq", 1.0));
    expected.add(new LanguageRange("yam", 1.0));
    expected.add(new LanguageRange("kxe", 1.0));
    expected.add(new LanguageRange("tvd", 1.0));
    expected.add(new LanguageRange("lii", 1.0));
    expected.add(new LanguageRange("raq", 1.0));
    expected.add(new LanguageRange("lmm", 1.0));
    expected.add(new LanguageRange("rmx", 1.0));
    expected.add(new LanguageRange("mtm", 1.0));
    expected.add(new LanguageRange("ymt", 1.0));
    expected.add(new LanguageRange("ngv", 1.0));
    expected.add(new LanguageRange("nnx", 1.0));
    expected.add(new LanguageRange("oyb", 1.0));
    expected.add(new LanguageRange("thx", 1.0));
    expected.add(new LanguageRange("skk", 1.0));
    expected.add(new LanguageRange("jeg", 1.0));
    expected.add(new LanguageRange("phr", 1.0));
    expected.add(new LanguageRange("pmu", 1.0));
    expected.add(new LanguageRange("pub", 1.0));
    expected.add(new LanguageRange("puz", 1.0));
    expected.add(new LanguageRange("suj", 1.0));
    expected.add(new LanguageRange("xsj", 1.0));
    expected.add(new LanguageRange("taj", 0.9));
    expected.add(new LanguageRange("tsf", 0.9));
    expected.add(new LanguageRange("ar-hyw", 0.8));
    expected.add(new LanguageRange("yug", 0.5));
    expected.add(new LanguageRange("yuu", 0.5));
    expected.add(new LanguageRange("gfx", 0.4));
    expected.add(new LanguageRange("oun", 0.4));
    expected.add(new LanguageRange("mwj", 0.4));
    expected.add(new LanguageRange("vaj", 0.4));
    List<LanguageRange> got = LanguageRange.parse(str);
    if (!areEqual(expected, got)) {
        error = true;
        System.err.println("    language parse() test failed.");
    }

    if (error) {
        err = true;
        System.err.println("  test_parse() failed.");
    } else {
        System.out.println("  test_parse() passed.");
    }

}
 
Example 20
Source File: Bug8040211.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void test_filter() {
    boolean error = false;

    String ranges = "mtm-RU, en-gb-oed, coy, ar-HY";
    String tags = "de-DE, en, mtm-RU, ymt-RU, en-gb-oxendict, ja-JP, pij, nts, ar-arevela";
    FilteringMode mode = EXTENDED_FILTERING;

    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> tagList = generateLocales(tags);
    String actualLocales
            = showLocales(Locale.filter(priorityList, tagList, mode));
    String expectedLocales = "mtm-RU, ymt-RU, en-GB-oxendict, nts, pij";

    if (!expectedLocales.equals(actualLocales)) {
        error = true;
        showErrorMessage("#1 filter(" + mode + ")",
                ranges, tags, expectedLocales, actualLocales);
    }

    ranges = "phr-*-IN, ja-JP";
    tags = "en, pmu-Guru-IN, ja-Latn-JP, iw";
    mode = EXTENDED_FILTERING;

    priorityList = LanguageRange.parse(ranges);
    tagList = generateLocales(tags);
    actualLocales = showLocales(Locale.filter(priorityList, tagList, mode));
    expectedLocales = "pmu-Guru-IN, ja-Latn-JP";

    if (!expectedLocales.equals(actualLocales)) {
        error = true;
        showErrorMessage("#2 filter(" + mode + ")",
                ranges, tags, expectedLocales, actualLocales);
    }

    if (error) {
        err = true;
        System.out.println("  test_filter() failed.");
    } else {
        System.out.println("  test_filter() passed.");
    }
}