Changeset 19054 in josm


Ignore:
Timestamp:
2024-04-23T16:13:30+02:00 (2 weeks ago)
Author:
taylor.smock
Message:

See r19043: Drop COMPAT locale provider

The CLDR provider does not currently return the CET for GMT+01:00. Using only SPI
will result in the "correct" CET timezone abbreviation. If using both, CLDR wins
and returns GMT+01:00. In addition, there are locales that do not use the Western
Arabic numeral system. Specifically, Arabic uses the Eastern Arabic numeral
system, Persian uses the Urdu numeral system, and Marathi uses the Devanagari
numeral system. Of note, while the first character for the Eastern Arabic and
Urdu numeral systems looks the same, it is a different character.

Location:
trunk/test/unit/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/tools/JosmDecimalFormatSymbolsProviderTest.java

    r19053 r19054  
    55import static org.junit.jupiter.api.Assertions.assertNotNull;
    66import static org.junit.jupiter.api.Assertions.assertTrue;
     7import static org.junit.jupiter.api.Assertions.fail;
    78
    89import java.io.IOException;
     
    1516import org.junit.jupiter.api.BeforeAll;
    1617import org.junit.jupiter.api.Test;
     18import org.junit.jupiter.params.ParameterizedTest;
     19import org.junit.jupiter.params.provider.MethodSource;
    1720
    1821/**
     
    3235    }
    3336
    34     @Test
    35     void testGroupingSeparator() {
     37    static Stream<Locale> testGroupingSeparator() {
    3638        System.out.println(Locale.getDefault());
    3739
    3840        assertTrue(I18n.getAvailableTranslations().count() > 10);
    39         I18n.getAvailableTranslations().forEach(this::checkGroupingSymbol);
    40         Stream.of("", "AU", "IE", "US", "UK").map(country -> new Locale("en", country, "")).forEach(this::checkGroupingSymbol);
    41         Stream.of("", "AT", "CH", "DE").map(country -> new Locale("de", country, "")).forEach(this::checkGroupingSymbol);
     41        return Stream.concat(
     42                I18n.getAvailableTranslations(),
     43                Stream.concat(Stream.of("", "AU", "IE", "US", "UK").map(country -> new Locale("en", country, "")),
     44                        Stream.of("", "AT", "CH", "DE").map(country -> new Locale("de", country, ""))
     45                ));
    4246    }
    4347
    44     private void checkGroupingSymbol(Locale locale) {
    45         assertEquals("123\u202F456", DecimalFormat.getInstance(locale).format(123_456), locale.toString());
     48    @ParameterizedTest
     49    @MethodSource
     50    void testGroupingSeparator(Locale locale) {
     51        final String formattedNumber = DecimalFormat.getInstance(locale).format(123_456);
     52        // Note: If you have to add another numeral system, please indicate the name and the locale(s) it is for.
     53        if (formattedNumber.startsWith("1")) {
     54            // Western Arabic (for most locales)
     55            assertEquals("123\u202F456", formattedNumber, locale.toString() + ": " + locale.getDisplayName());
     56        } else if (formattedNumber.startsWith("١")) {
     57            // Eastern Arabic (for Arabic locale)
     58            assertEquals("١٢٣\u202F٤٥٦", formattedNumber, locale.toString() + ": " + locale.getDisplayName());
     59        } else if (formattedNumber.startsWith("۱")) {
     60            // Urdu (for Persian locale)
     61            assertEquals("۱۲۳\u202F۴۵۶", formattedNumber, locale.toString() + ": " + locale.getDisplayName());
     62        } else if (formattedNumber.startsWith("१")) {
     63            // Devanagari (for Marathi locale)
     64            assertEquals("१२३\u202F४५६", formattedNumber, locale.toString() + ": " + locale.getDisplayName());
     65        } else {
     66            fail(locale.toString() + " (" + locale.getDisplayName() + "): " + formattedNumber);
     67        }
    4668    }
    4769
  • trunk/test/unit/org/openstreetmap/josm/tools/date/DateUtilsTest.java

    r18870 r19054  
    160160
    161161        setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
    162         assertEquals("1:00:00 AM CET", DateUtils.formatTime(new Date(0), DateFormat.LONG));
     162        assertEquals("1:00:00 AM GMT+01:00", DateUtils.formatTime(new Date(0), DateFormat.LONG), "This is mostly dependent upon java.locale.providers. CET is also OK.");
    163163    }
    164164
     
    308308        }
    309309    }
     310
     311    /**
     312     * Some Java version use narrow no-break space ("NNBSP") instead of a space.
     313     * @param time The time string with NNBSP instead of a space
     314     * @return The time with spaces instead of NNBSP
     315     */
     316    private static String replaceWhitespace(String time) {
     317        return time.replace((char) 8239 /* "NNBSP" */, ' ');
     318    }
    310319}
Note: See TracChangeset for help on using the changeset viewer.