2017-09-27 00:25:20 +00:00
|
|
|
|
// © 2017 and later: Unicode, Inc. and others.
|
|
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
|
|
|
|
|
2017-10-04 22:51:06 +00:00
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
2017-10-05 00:47:38 +00:00
|
|
|
|
#if !UCONFIG_NO_FORMATTING && !UPRV_INCOMPLETE_CPP11_SUPPORT
|
2017-09-27 00:25:20 +00:00
|
|
|
|
|
2017-09-27 05:31:57 +00:00
|
|
|
|
#include "charstr.h"
|
2017-09-27 00:25:20 +00:00
|
|
|
|
#include <cstdarg>
|
2017-09-27 02:16:44 +00:00
|
|
|
|
#include "unicode/unum.h"
|
2017-09-27 00:25:20 +00:00
|
|
|
|
#include "unicode/numberformatter.h"
|
|
|
|
|
#include "number_types.h"
|
2017-09-27 02:16:44 +00:00
|
|
|
|
#include "numbertest.h"
|
2018-03-17 07:24:02 +00:00
|
|
|
|
#include "unicode/utypes.h"
|
2017-09-27 00:25:20 +00:00
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
// Horrible workaround for the lack of a status code in the constructor...
|
|
|
|
|
UErrorCode globalNumberFormatterApiTestStatus = U_ZERO_ERROR;
|
2017-09-27 00:25:20 +00:00
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
NumberFormatterApiTest::NumberFormatterApiTest()
|
|
|
|
|
: NumberFormatterApiTest(globalNumberFormatterApiTestStatus) {
|
|
|
|
|
}
|
2017-09-27 00:25:20 +00:00
|
|
|
|
|
2018-03-24 07:36:18 +00:00
|
|
|
|
NumberFormatterApiTest::NumberFormatterApiTest(UErrorCode& status)
|
|
|
|
|
: USD(u"USD", status),
|
|
|
|
|
GBP(u"GBP", status),
|
|
|
|
|
CZK(u"CZK", status),
|
|
|
|
|
CAD(u"CAD", status),
|
|
|
|
|
ESP(u"ESP", status),
|
|
|
|
|
PTE(u"PTE", status),
|
|
|
|
|
FRENCH_SYMBOLS(Locale::getFrench(), status),
|
|
|
|
|
SWISS_SYMBOLS(Locale("de-CH"), status),
|
|
|
|
|
MYANMAR_SYMBOLS(Locale("my"), status) {
|
2017-09-27 02:16:44 +00:00
|
|
|
|
|
2017-12-22 00:02:01 +00:00
|
|
|
|
// Check for error on the first MeasureUnit in case there is no data
|
|
|
|
|
LocalPointer<MeasureUnit> unit(MeasureUnit::createMeter(status));
|
2017-10-06 23:11:11 +00:00
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
|
dataerrln("%s %d status = %s", __FILE__, __LINE__, u_errorName(status));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-09-27 02:16:44 +00:00
|
|
|
|
METER = *unit;
|
2017-12-22 00:02:01 +00:00
|
|
|
|
|
|
|
|
|
DAY = *LocalPointer<MeasureUnit>(MeasureUnit::createDay(status));
|
|
|
|
|
SQUARE_METER = *LocalPointer<MeasureUnit>(MeasureUnit::createSquareMeter(status));
|
|
|
|
|
FAHRENHEIT = *LocalPointer<MeasureUnit>(MeasureUnit::createFahrenheit(status));
|
|
|
|
|
SECOND = *LocalPointer<MeasureUnit>(MeasureUnit::createSecond(status));
|
|
|
|
|
POUND = *LocalPointer<MeasureUnit>(MeasureUnit::createPound(status));
|
|
|
|
|
SQUARE_MILE = *LocalPointer<MeasureUnit>(MeasureUnit::createSquareMile(status));
|
|
|
|
|
JOULE = *LocalPointer<MeasureUnit>(MeasureUnit::createJoule(status));
|
|
|
|
|
FURLONG = *LocalPointer<MeasureUnit>(MeasureUnit::createFurlong(status));
|
2018-01-10 02:44:23 +00:00
|
|
|
|
KELVIN = *LocalPointer<MeasureUnit>(MeasureUnit::createKelvin(status));
|
2017-12-22 00:02:01 +00:00
|
|
|
|
|
|
|
|
|
MATHSANB = *LocalPointer<NumberingSystem>(NumberingSystem::createInstanceByName("mathsanb", status));
|
|
|
|
|
LATN = *LocalPointer<NumberingSystem>(NumberingSystem::createInstanceByName("latn", status));
|
2017-09-27 02:16:44 +00:00
|
|
|
|
}
|
2017-09-27 00:25:20 +00:00
|
|
|
|
|
2018-03-24 07:36:18 +00:00
|
|
|
|
void NumberFormatterApiTest::runIndexedTest(int32_t index, UBool exec, const char*& name, char*) {
|
2017-09-27 02:16:44 +00:00
|
|
|
|
if (exec) {
|
|
|
|
|
logln("TestSuite NumberFormatterApiTest: ");
|
|
|
|
|
}
|
|
|
|
|
TESTCASE_AUTO_BEGIN;
|
|
|
|
|
TESTCASE_AUTO(notationSimple);
|
|
|
|
|
TESTCASE_AUTO(notationScientific);
|
|
|
|
|
TESTCASE_AUTO(notationCompact);
|
|
|
|
|
TESTCASE_AUTO(unitMeasure);
|
2017-12-22 00:02:01 +00:00
|
|
|
|
TESTCASE_AUTO(unitCompoundMeasure);
|
2017-09-27 02:16:44 +00:00
|
|
|
|
TESTCASE_AUTO(unitCurrency);
|
|
|
|
|
TESTCASE_AUTO(unitPercent);
|
|
|
|
|
TESTCASE_AUTO(roundingFraction);
|
|
|
|
|
TESTCASE_AUTO(roundingFigures);
|
|
|
|
|
TESTCASE_AUTO(roundingFractionFigures);
|
|
|
|
|
TESTCASE_AUTO(roundingOther);
|
|
|
|
|
TESTCASE_AUTO(grouping);
|
|
|
|
|
TESTCASE_AUTO(padding);
|
|
|
|
|
TESTCASE_AUTO(integerWidth);
|
|
|
|
|
TESTCASE_AUTO(symbols);
|
|
|
|
|
// TODO: Add this method if currency symbols override support is added.
|
|
|
|
|
//TESTCASE_AUTO(symbolsOverride);
|
|
|
|
|
TESTCASE_AUTO(sign);
|
|
|
|
|
TESTCASE_AUTO(decimal);
|
2018-04-03 04:38:16 +00:00
|
|
|
|
TESTCASE_AUTO(multiplier);
|
2017-09-27 02:16:44 +00:00
|
|
|
|
TESTCASE_AUTO(locale);
|
2017-09-27 22:31:07 +00:00
|
|
|
|
TESTCASE_AUTO(formatTypes);
|
2017-09-27 02:16:44 +00:00
|
|
|
|
TESTCASE_AUTO(errors);
|
2018-02-08 06:06:08 +00:00
|
|
|
|
TESTCASE_AUTO(validRanges);
|
2018-03-17 07:24:02 +00:00
|
|
|
|
TESTCASE_AUTO(copyMove);
|
2017-09-27 02:16:44 +00:00
|
|
|
|
TESTCASE_AUTO_END;
|
|
|
|
|
}
|
2017-09-27 00:25:20 +00:00
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::notationSimple() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Basic",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with(),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0.8765",
|
|
|
|
|
u"0.08765",
|
|
|
|
|
u"0.008765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
2018-03-24 07:36:18 +00:00
|
|
|
|
assertFormatDescendingBig(
|
|
|
|
|
u"Big Simple",
|
|
|
|
|
u"notation-simple",
|
|
|
|
|
NumberFormatter::with().notation(Notation::simple()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650,000",
|
|
|
|
|
u"8,765,000",
|
|
|
|
|
u"876,500",
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Basic with Negative Sign",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with(),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-9876543.21,
|
|
|
|
|
u"-9,876,543.21");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::notationScientific() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Scientific",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"scientific",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::scientific()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"8.765E4",
|
|
|
|
|
u"8.765E3",
|
|
|
|
|
u"8.765E2",
|
|
|
|
|
u"8.765E1",
|
|
|
|
|
u"8.765E0",
|
|
|
|
|
u"8.765E-1",
|
|
|
|
|
u"8.765E-2",
|
|
|
|
|
u"8.765E-3",
|
|
|
|
|
u"0E0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Engineering",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"engineering",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::engineering()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87.65E3",
|
|
|
|
|
u"8.765E3",
|
|
|
|
|
u"876.5E0",
|
|
|
|
|
u"87.65E0",
|
|
|
|
|
u"8.765E0",
|
|
|
|
|
u"876.5E-3",
|
|
|
|
|
u"87.65E-3",
|
|
|
|
|
u"8.765E-3",
|
|
|
|
|
u"0E0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Scientific sign always shown",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"scientific/sign-always",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(
|
|
|
|
|
Notation::scientific().withExponentSignDisplay(UNumberSignDisplay::UNUM_SIGN_ALWAYS)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"8.765E+4",
|
|
|
|
|
u"8.765E+3",
|
|
|
|
|
u"8.765E+2",
|
|
|
|
|
u"8.765E+1",
|
|
|
|
|
u"8.765E+0",
|
|
|
|
|
u"8.765E-1",
|
|
|
|
|
u"8.765E-2",
|
|
|
|
|
u"8.765E-3",
|
|
|
|
|
u"0E+0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Scientific min exponent digits",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"scientific/+ee",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::scientific().withMinExponentDigits(2)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"8.765E04",
|
|
|
|
|
u"8.765E03",
|
|
|
|
|
u"8.765E02",
|
|
|
|
|
u"8.765E01",
|
|
|
|
|
u"8.765E00",
|
|
|
|
|
u"8.765E-01",
|
|
|
|
|
u"8.765E-02",
|
|
|
|
|
u"8.765E-03",
|
|
|
|
|
u"0E00");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Scientific Negative",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"scientific",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::scientific()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-1000000,
|
|
|
|
|
u"-1E6");
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::notationCompact() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Compact Short",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-short",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactShort()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"88K",
|
|
|
|
|
u"8.8K",
|
|
|
|
|
u"876",
|
|
|
|
|
u"88",
|
|
|
|
|
u"8.8",
|
|
|
|
|
u"0.88",
|
|
|
|
|
u"0.088",
|
|
|
|
|
u"0.0088",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Compact Long",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-long",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactLong()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"88 thousand",
|
|
|
|
|
u"8.8 thousand",
|
|
|
|
|
u"876",
|
|
|
|
|
u"88",
|
|
|
|
|
u"8.8",
|
|
|
|
|
u"0.88",
|
|
|
|
|
u"0.088",
|
|
|
|
|
u"0.0088",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Compact Short Currency",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-short currency/USD",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactShort()).unit(USD),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"$88K",
|
|
|
|
|
u"$8.8K",
|
|
|
|
|
u"$876",
|
|
|
|
|
u"$88",
|
|
|
|
|
u"$8.8",
|
|
|
|
|
u"$0.88",
|
|
|
|
|
u"$0.088",
|
|
|
|
|
u"$0.0088",
|
|
|
|
|
u"$0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Compact Short with ISO Currency",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-short currency/USD unit-width-iso-code",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactShort())
|
|
|
|
|
.unit(USD)
|
|
|
|
|
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"USD 88K",
|
|
|
|
|
u"USD 8.8K",
|
|
|
|
|
u"USD 876",
|
|
|
|
|
u"USD 88",
|
|
|
|
|
u"USD 8.8",
|
|
|
|
|
u"USD 0.88",
|
|
|
|
|
u"USD 0.088",
|
|
|
|
|
u"USD 0.0088",
|
|
|
|
|
u"USD 0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Compact Short with Long Name Currency",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-short currency/USD unit-width-full-name",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactShort())
|
|
|
|
|
.unit(USD)
|
|
|
|
|
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"88K US dollars",
|
|
|
|
|
u"8.8K US dollars",
|
|
|
|
|
u"876 US dollars",
|
|
|
|
|
u"88 US dollars",
|
|
|
|
|
u"8.8 US dollars",
|
|
|
|
|
u"0.88 US dollars",
|
|
|
|
|
u"0.088 US dollars",
|
|
|
|
|
u"0.0088 US dollars",
|
|
|
|
|
u"0 US dollars");
|
|
|
|
|
|
|
|
|
|
// Note: Most locales don't have compact long currency, so this currently falls back to short.
|
|
|
|
|
// This test case should be fixed when proper compact long currency patterns are added.
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Compact Long Currency",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-long currency/USD",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactLong()).unit(USD),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"$88K", // should be something like "$88 thousand"
|
|
|
|
|
u"$8.8K",
|
|
|
|
|
u"$876",
|
|
|
|
|
u"$88",
|
|
|
|
|
u"$8.8",
|
|
|
|
|
u"$0.88",
|
|
|
|
|
u"$0.088",
|
|
|
|
|
u"$0.0088",
|
|
|
|
|
u"$0");
|
|
|
|
|
|
|
|
|
|
// Note: Most locales don't have compact long currency, so this currently falls back to short.
|
|
|
|
|
// This test case should be fixed when proper compact long currency patterns are added.
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Compact Long with ISO Currency",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-long currency/USD unit-width-iso-code",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactLong())
|
|
|
|
|
.unit(USD)
|
|
|
|
|
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"USD 88K", // should be something like "USD 88 thousand"
|
|
|
|
|
u"USD 8.8K",
|
|
|
|
|
u"USD 876",
|
|
|
|
|
u"USD 88",
|
|
|
|
|
u"USD 8.8",
|
|
|
|
|
u"USD 0.88",
|
|
|
|
|
u"USD 0.088",
|
|
|
|
|
u"USD 0.0088",
|
|
|
|
|
u"USD 0");
|
|
|
|
|
|
|
|
|
|
// TODO: This behavior could be improved and should be revisited.
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Compact Long with Long Name Currency",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-long currency/USD unit-width-full-name",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactLong())
|
|
|
|
|
.unit(USD)
|
|
|
|
|
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"88 thousand US dollars",
|
|
|
|
|
u"8.8 thousand US dollars",
|
|
|
|
|
u"876 US dollars",
|
|
|
|
|
u"88 US dollars",
|
|
|
|
|
u"8.8 US dollars",
|
|
|
|
|
u"0.88 US dollars",
|
|
|
|
|
u"0.088 US dollars",
|
|
|
|
|
u"0.0088 US dollars",
|
|
|
|
|
u"0 US dollars");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Compact Plural One",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-long",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactLong()),
|
|
|
|
|
Locale::createFromName("es"),
|
|
|
|
|
1000000,
|
|
|
|
|
u"1 millón");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Compact Plural Other",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-long",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactLong()),
|
|
|
|
|
Locale::createFromName("es"),
|
|
|
|
|
2000000,
|
|
|
|
|
u"2 millones");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Compact with Negative Sign",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-short",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactShort()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-9876543.21,
|
|
|
|
|
u"-9.9M");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Compact Rounding",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-short",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactShort()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
990000,
|
|
|
|
|
u"990K");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Compact Rounding",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-short",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactShort()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
999000,
|
|
|
|
|
u"999K");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Compact Rounding",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-short",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactShort()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
999900,
|
|
|
|
|
u"1M");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Compact Rounding",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-short",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactShort()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
9900000,
|
|
|
|
|
u"9.9M");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Compact Rounding",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-short",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactShort()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
9990000,
|
|
|
|
|
u"10M");
|
2018-02-06 03:08:17 +00:00
|
|
|
|
|
|
|
|
|
// NOTE: There is no API for compact custom data in C++
|
|
|
|
|
// and thus no "Compact Somali No Figure" test
|
2017-09-27 00:25:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::unitMeasure() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
2017-12-22 00:02:01 +00:00
|
|
|
|
u"Meters Short and unit() method",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"measure-unit/length-meter",
|
2017-12-22 00:02:01 +00:00
|
|
|
|
NumberFormatter::with().unit(METER),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650 m",
|
|
|
|
|
u"8,765 m",
|
|
|
|
|
u"876.5 m",
|
|
|
|
|
u"87.65 m",
|
|
|
|
|
u"8.765 m",
|
|
|
|
|
u"0.8765 m",
|
|
|
|
|
u"0.08765 m",
|
|
|
|
|
u"0.008765 m",
|
|
|
|
|
u"0 m");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
2017-12-22 00:02:01 +00:00
|
|
|
|
u"Meters Long and adoptUnit() method",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"measure-unit/length-meter unit-width-full-name",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().adoptUnit(new MeasureUnit(METER))
|
|
|
|
|
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650 meters",
|
|
|
|
|
u"8,765 meters",
|
|
|
|
|
u"876.5 meters",
|
|
|
|
|
u"87.65 meters",
|
|
|
|
|
u"8.765 meters",
|
|
|
|
|
u"0.8765 meters",
|
|
|
|
|
u"0.08765 meters",
|
|
|
|
|
u"0.008765 meters",
|
|
|
|
|
u"0 meters");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Compact Meters Long",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"compact-long measure-unit/length-meter unit-width-full-name",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactLong())
|
2017-12-22 00:02:01 +00:00
|
|
|
|
.unit(METER)
|
2017-09-27 00:25:20 +00:00
|
|
|
|
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"88 thousand meters",
|
|
|
|
|
u"8.8 thousand meters",
|
|
|
|
|
u"876 meters",
|
|
|
|
|
u"88 meters",
|
|
|
|
|
u"8.8 meters",
|
|
|
|
|
u"0.88 meters",
|
|
|
|
|
u"0.088 meters",
|
|
|
|
|
u"0.0088 meters",
|
|
|
|
|
u"0 meters");
|
|
|
|
|
|
|
|
|
|
// TODO: Implement Measure in C++
|
|
|
|
|
// assertFormatSingleMeasure(
|
|
|
|
|
// u"Meters with Measure Input",
|
|
|
|
|
// NumberFormatter::with().unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
|
|
|
|
|
// Locale::getEnglish(),
|
|
|
|
|
// new Measure(5.43, new MeasureUnit(METER)),
|
|
|
|
|
// u"5.43 meters");
|
|
|
|
|
|
|
|
|
|
// TODO: Implement Measure in C++
|
|
|
|
|
// assertFormatSingleMeasure(
|
|
|
|
|
// u"Measure format method takes precedence over fluent chain",
|
2017-12-22 00:02:01 +00:00
|
|
|
|
// NumberFormatter::with().unit(METER),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
// Locale::getEnglish(),
|
|
|
|
|
// new Measure(5.43, USD),
|
|
|
|
|
// u"$5.43");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Meters with Negative Sign",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"measure-unit/length-meter",
|
2017-12-22 00:02:01 +00:00
|
|
|
|
NumberFormatter::with().unit(METER),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-9876543.21,
|
|
|
|
|
u"-9,876,543.21 m");
|
|
|
|
|
|
|
|
|
|
// The locale string "सान" appears only in brx.txt:
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Interesting Data Fallback 1",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"measure-unit/duration-day unit-width-full-name",
|
|
|
|
|
NumberFormatter::with().unit(DAY).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
Locale::createFromName("brx"),
|
|
|
|
|
5.43,
|
|
|
|
|
u"5.43 सान");
|
|
|
|
|
|
|
|
|
|
// Requires following the alias from unitsNarrow to unitsShort:
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Interesting Data Fallback 2",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"measure-unit/duration-day unit-width-narrow",
|
|
|
|
|
NumberFormatter::with().unit(DAY).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
Locale::createFromName("brx"),
|
|
|
|
|
5.43,
|
|
|
|
|
u"5.43 d");
|
|
|
|
|
|
|
|
|
|
// en_001.txt has a unitsNarrow/area/square-meter table, but table does not contain the OTHER unit,
|
|
|
|
|
// requiring fallback to the root.
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Interesting Data Fallback 3",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"measure-unit/area-square-meter unit-width-narrow",
|
|
|
|
|
NumberFormatter::with().unit(SQUARE_METER).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
Locale::createFromName("en-GB"),
|
|
|
|
|
5.43,
|
|
|
|
|
u"5.43 m²");
|
|
|
|
|
|
|
|
|
|
// es_US has "{0}°" for unitsNarrow/temperature/FAHRENHEIT.
|
|
|
|
|
// NOTE: This example is in the documentation.
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Difference between Narrow and Short (Narrow Version)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"measure-unit/temperature-fahrenheit unit-width-narrow",
|
|
|
|
|
NumberFormatter::with().unit(FAHRENHEIT).unitWidth(UNUM_UNIT_WIDTH_NARROW),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
Locale("es-US"),
|
|
|
|
|
5.43,
|
|
|
|
|
u"5.43°");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Difference between Narrow and Short (Short Version)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"measure-unit/temperature-fahrenheit unit-width-short",
|
|
|
|
|
NumberFormatter::with().unit(FAHRENHEIT).unitWidth(UNUM_UNIT_WIDTH_SHORT),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
Locale("es-US"),
|
|
|
|
|
5.43,
|
|
|
|
|
u"5.43 °F");
|
2018-01-10 02:44:23 +00:00
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"MeasureUnit form without {0} in CLDR pattern",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"measure-unit/temperature-kelvin unit-width-full-name",
|
|
|
|
|
NumberFormatter::with().unit(KELVIN).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
|
2018-01-10 02:44:23 +00:00
|
|
|
|
Locale("es-MX"),
|
|
|
|
|
1,
|
|
|
|
|
u"kelvin");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"MeasureUnit form without {0} in CLDR pattern and wide base form",
|
2018-03-24 08:06:34 +00:00
|
|
|
|
u"measure-unit/temperature-kelvin .00000000000000000000 unit-width-full-name",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::fixedFraction(20))
|
2018-01-10 02:44:23 +00:00
|
|
|
|
.unit(KELVIN)
|
|
|
|
|
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
|
|
|
|
|
Locale("es-MX"),
|
|
|
|
|
1,
|
|
|
|
|
u"kelvin");
|
2017-09-27 00:25:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 00:02:01 +00:00
|
|
|
|
void NumberFormatterApiTest::unitCompoundMeasure() {
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Meters Per Second Short (unit that simplifies) and perUnit method",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"measure-unit/length-meter per-measure-unit/duration-second",
|
2017-12-22 00:02:01 +00:00
|
|
|
|
NumberFormatter::with().unit(METER).perUnit(SECOND),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650 m/s",
|
|
|
|
|
u"8,765 m/s",
|
|
|
|
|
u"876.5 m/s",
|
|
|
|
|
u"87.65 m/s",
|
|
|
|
|
u"8.765 m/s",
|
|
|
|
|
u"0.8765 m/s",
|
|
|
|
|
u"0.08765 m/s",
|
|
|
|
|
u"0.008765 m/s",
|
|
|
|
|
u"0 m/s");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Pounds Per Square Mile Short (secondary unit has per-format) and adoptPerUnit method",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"measure-unit/mass-pound per-measure-unit/area-square-mile",
|
2017-12-22 00:02:01 +00:00
|
|
|
|
NumberFormatter::with().unit(POUND).adoptPerUnit(new MeasureUnit(SQUARE_MILE)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650 lb/mi²",
|
|
|
|
|
u"8,765 lb/mi²",
|
|
|
|
|
u"876.5 lb/mi²",
|
|
|
|
|
u"87.65 lb/mi²",
|
|
|
|
|
u"8.765 lb/mi²",
|
|
|
|
|
u"0.8765 lb/mi²",
|
|
|
|
|
u"0.08765 lb/mi²",
|
|
|
|
|
u"0.008765 lb/mi²",
|
|
|
|
|
u"0 lb/mi²");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Joules Per Furlong Short (unit with no simplifications or special patterns)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"measure-unit/energy-joule per-measure-unit/length-furlong",
|
2017-12-22 00:02:01 +00:00
|
|
|
|
NumberFormatter::with().unit(JOULE).perUnit(FURLONG),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650 J/fur",
|
|
|
|
|
u"8,765 J/fur",
|
|
|
|
|
u"876.5 J/fur",
|
|
|
|
|
u"87.65 J/fur",
|
|
|
|
|
u"8.765 J/fur",
|
|
|
|
|
u"0.8765 J/fur",
|
|
|
|
|
u"0.08765 J/fur",
|
|
|
|
|
u"0.008765 J/fur",
|
|
|
|
|
u"0 J/fur");
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::unitCurrency() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Currency",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/GBP",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().unit(GBP),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"£87,650.00",
|
|
|
|
|
u"£8,765.00",
|
|
|
|
|
u"£876.50",
|
|
|
|
|
u"£87.65",
|
|
|
|
|
u"£8.76",
|
|
|
|
|
u"£0.88",
|
|
|
|
|
u"£0.09",
|
|
|
|
|
u"£0.01",
|
|
|
|
|
u"£0.00");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Currency ISO",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/GBP unit-width-iso-code",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().unit(GBP).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"GBP 87,650.00",
|
|
|
|
|
u"GBP 8,765.00",
|
|
|
|
|
u"GBP 876.50",
|
|
|
|
|
u"GBP 87.65",
|
|
|
|
|
u"GBP 8.76",
|
|
|
|
|
u"GBP 0.88",
|
|
|
|
|
u"GBP 0.09",
|
|
|
|
|
u"GBP 0.01",
|
|
|
|
|
u"GBP 0.00");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Currency Long Name",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/GBP unit-width-full-name",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().unit(GBP).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650.00 British pounds",
|
|
|
|
|
u"8,765.00 British pounds",
|
|
|
|
|
u"876.50 British pounds",
|
|
|
|
|
u"87.65 British pounds",
|
|
|
|
|
u"8.76 British pounds",
|
|
|
|
|
u"0.88 British pounds",
|
|
|
|
|
u"0.09 British pounds",
|
|
|
|
|
u"0.01 British pounds",
|
|
|
|
|
u"0.00 British pounds");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Currency Hidden",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/GBP unit-width-hidden",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().unit(GBP).unitWidth(UNUM_UNIT_WIDTH_HIDDEN),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650.00",
|
|
|
|
|
u"8,765.00",
|
|
|
|
|
u"876.50",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.76",
|
|
|
|
|
u"0.88",
|
|
|
|
|
u"0.09",
|
|
|
|
|
u"0.01",
|
|
|
|
|
u"0.00");
|
|
|
|
|
|
|
|
|
|
// TODO: Implement Measure in C++
|
|
|
|
|
// assertFormatSingleMeasure(
|
|
|
|
|
// u"Currency with CurrencyAmount Input",
|
|
|
|
|
// NumberFormatter::with(),
|
|
|
|
|
// Locale::getEnglish(),
|
|
|
|
|
// new CurrencyAmount(5.43, GBP),
|
|
|
|
|
// u"£5.43");
|
|
|
|
|
|
|
|
|
|
// TODO: Enable this test when DecimalFormat wrapper is done.
|
|
|
|
|
// assertFormatSingle(
|
|
|
|
|
// u"Currency Long Name from Pattern Syntax", NumberFormatter.fromDecimalFormat(
|
|
|
|
|
// PatternStringParser.parseToProperties("0 ¤¤¤"),
|
|
|
|
|
// DecimalFormatSymbols.getInstance(Locale::getEnglish()),
|
|
|
|
|
// null).unit(GBP), Locale::getEnglish(), 1234567.89, u"1234568 British pounds");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency with Negative Sign",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/GBP",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().unit(GBP),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-9876543.21,
|
|
|
|
|
u"-£9,876,543.21");
|
2018-02-06 03:08:17 +00:00
|
|
|
|
|
|
|
|
|
// The full currency symbol is not shown in NARROW format.
|
|
|
|
|
// NOTE: This example is in the documentation.
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency Difference between Narrow and Short (Narrow Version)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD unit-width-narrow",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().unit(USD).unitWidth(UNUM_UNIT_WIDTH_NARROW),
|
|
|
|
|
Locale("en-CA"),
|
|
|
|
|
5.43,
|
|
|
|
|
u"$5.43");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency Difference between Narrow and Short (Short Version)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD unit-width-short",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().unit(USD).unitWidth(UNUM_UNIT_WIDTH_SHORT),
|
|
|
|
|
Locale("en-CA"),
|
|
|
|
|
5.43,
|
|
|
|
|
u"US$5.43");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency-dependent format (Control)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD unit-width-short",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().unit(USD).unitWidth(UNUM_UNIT_WIDTH_SHORT),
|
|
|
|
|
Locale("ca"),
|
|
|
|
|
444444.55,
|
|
|
|
|
u"444.444,55 USD");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency-dependent format (Test)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/ESP unit-width-short",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().unit(ESP).unitWidth(UNUM_UNIT_WIDTH_SHORT),
|
|
|
|
|
Locale("ca"),
|
|
|
|
|
444444.55,
|
|
|
|
|
u"₧ 444.445");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency-dependent symbols (Control)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD unit-width-short",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().unit(USD).unitWidth(UNUM_UNIT_WIDTH_SHORT),
|
|
|
|
|
Locale("pt-PT"),
|
|
|
|
|
444444.55,
|
|
|
|
|
u"444 444,55 US$");
|
|
|
|
|
|
|
|
|
|
// NOTE: This is a bit of a hack on CLDR's part. They set the currency symbol to U+200B (zero-
|
|
|
|
|
// width space), and they set the decimal separator to the $ symbol.
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency-dependent symbols (Test Short)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/PTE unit-width-short",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().unit(PTE).unitWidth(UNUM_UNIT_WIDTH_SHORT),
|
|
|
|
|
Locale("pt-PT"),
|
|
|
|
|
444444.55,
|
|
|
|
|
u"444,444$55 \u200B");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency-dependent symbols (Test Narrow)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/PTE unit-width-narrow",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().unit(PTE).unitWidth(UNUM_UNIT_WIDTH_NARROW),
|
|
|
|
|
Locale("pt-PT"),
|
|
|
|
|
444444.55,
|
|
|
|
|
u"444,444$55 PTE");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency-dependent symbols (Test ISO Code)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/PTE unit-width-iso-code",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().unit(PTE).unitWidth(UNUM_UNIT_WIDTH_ISO_CODE),
|
|
|
|
|
Locale("pt-PT"),
|
|
|
|
|
444444.55,
|
|
|
|
|
u"444,444$55 PTE");
|
2017-09-27 00:25:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::unitPercent() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Percent",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"percent",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().unit(NoUnit::percent()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650%",
|
|
|
|
|
u"8,765%",
|
|
|
|
|
u"876.5%",
|
|
|
|
|
u"87.65%",
|
|
|
|
|
u"8.765%",
|
|
|
|
|
u"0.8765%",
|
|
|
|
|
u"0.08765%",
|
|
|
|
|
u"0.008765%",
|
|
|
|
|
u"0%");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Permille",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"permille",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().unit(NoUnit::permille()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650‰",
|
|
|
|
|
u"8,765‰",
|
|
|
|
|
u"876.5‰",
|
|
|
|
|
u"87.65‰",
|
|
|
|
|
u"8.765‰",
|
|
|
|
|
u"0.8765‰",
|
|
|
|
|
u"0.08765‰",
|
|
|
|
|
u"0.008765‰",
|
|
|
|
|
u"0‰");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"NoUnit Base",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"base-unit",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().unit(NoUnit::base()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
51423,
|
|
|
|
|
u"51,423");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Percent with Negative Sign",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"percent",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().unit(NoUnit::percent()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-98.7654321,
|
|
|
|
|
u"-98.765432%");
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::roundingFraction() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Integer",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"round-integer",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::integer()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876",
|
|
|
|
|
u"88",
|
|
|
|
|
u"9",
|
|
|
|
|
u"1",
|
|
|
|
|
u"0",
|
|
|
|
|
u"0",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Fixed Fraction",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u".000",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::fixedFraction(3)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650.000",
|
|
|
|
|
u"8,765.000",
|
|
|
|
|
u"876.500",
|
|
|
|
|
u"87.650",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0.876",
|
|
|
|
|
u"0.088",
|
|
|
|
|
u"0.009",
|
|
|
|
|
u"0.000");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Min Fraction",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u".0+",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::minFraction(1)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650.0",
|
|
|
|
|
u"8,765.0",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0.8765",
|
|
|
|
|
u"0.08765",
|
|
|
|
|
u"0.008765",
|
|
|
|
|
u"0.0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Max Fraction",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u".#",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::maxFraction(1)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.6",
|
|
|
|
|
u"8.8",
|
|
|
|
|
u"0.9",
|
|
|
|
|
u"0.1",
|
|
|
|
|
u"0",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Min/Max Fraction",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u".0##",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::minMaxFraction(1, 3)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650.0",
|
|
|
|
|
u"8,765.0",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0.876",
|
|
|
|
|
u"0.088",
|
|
|
|
|
u"0.009",
|
|
|
|
|
u"0.0");
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::roundingFigures() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Fixed Significant",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"@@@",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::fixedDigits(3)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-98,
|
|
|
|
|
u"-98.0");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Fixed Significant Rounding",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"@@@",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::fixedDigits(3)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-98.7654321,
|
|
|
|
|
u"-98.8");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Fixed Significant Zero",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"@@@",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::fixedDigits(3)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0,
|
|
|
|
|
u"0.00");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Min Significant",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"@@+",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::minDigits(2)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-9,
|
|
|
|
|
u"-9.0");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Max Significant",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"@###",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::maxDigits(4)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
98.7654321,
|
|
|
|
|
u"98.77");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Min/Max Significant",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"@@@#",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::minMaxDigits(3, 4)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
9.99999,
|
|
|
|
|
u"10.0");
|
2018-03-30 08:21:06 +00:00
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Fixed Significant on zero with lots of integer width",
|
|
|
|
|
u"@ integer-width/+000",
|
|
|
|
|
NumberFormatter::with().rounding(Rounder::fixedDigits(1))
|
|
|
|
|
.integerWidth(IntegerWidth::zeroFillTo(3)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0,
|
|
|
|
|
"000");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Fixed Significant on zero with zero integer width",
|
|
|
|
|
u"@ integer-width/+",
|
|
|
|
|
NumberFormatter::with().rounding(Rounder::fixedDigits(1))
|
|
|
|
|
.integerWidth(IntegerWidth::zeroFillTo(0)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0,
|
|
|
|
|
"0");
|
2017-09-27 00:25:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::roundingFractionFigures() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Basic Significant", // for comparison
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"@#",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::maxDigits(2)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"88,000",
|
|
|
|
|
u"8,800",
|
|
|
|
|
u"880",
|
|
|
|
|
u"88",
|
|
|
|
|
u"8.8",
|
|
|
|
|
u"0.88",
|
|
|
|
|
u"0.088",
|
|
|
|
|
u"0.0088",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"FracSig minMaxFrac minSig",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u".0#/@@@+",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::minMaxFraction(1, 2).withMinDigits(3)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650.0",
|
|
|
|
|
u"8,765.0",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.76",
|
|
|
|
|
u"0.876", // minSig beats maxFrac
|
|
|
|
|
u"0.0876", // minSig beats maxFrac
|
|
|
|
|
u"0.00876", // minSig beats maxFrac
|
|
|
|
|
u"0.0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"FracSig minMaxFrac maxSig A",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u".0##/@#",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::minMaxFraction(1, 3).withMaxDigits(2)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"88,000.0", // maxSig beats maxFrac
|
|
|
|
|
u"8,800.0", // maxSig beats maxFrac
|
|
|
|
|
u"880.0", // maxSig beats maxFrac
|
|
|
|
|
u"88.0", // maxSig beats maxFrac
|
|
|
|
|
u"8.8", // maxSig beats maxFrac
|
|
|
|
|
u"0.88", // maxSig beats maxFrac
|
|
|
|
|
u"0.088",
|
|
|
|
|
u"0.009",
|
|
|
|
|
u"0.0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"FracSig minMaxFrac maxSig B",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u".00/@#",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::fixedFraction(2).withMaxDigits(2)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"88,000.00", // maxSig beats maxFrac
|
|
|
|
|
u"8,800.00", // maxSig beats maxFrac
|
|
|
|
|
u"880.00", // maxSig beats maxFrac
|
|
|
|
|
u"88.00", // maxSig beats maxFrac
|
|
|
|
|
u"8.80", // maxSig beats maxFrac
|
|
|
|
|
u"0.88",
|
|
|
|
|
u"0.09",
|
|
|
|
|
u"0.01",
|
|
|
|
|
u"0.00");
|
2018-02-06 03:08:17 +00:00
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"FracSig with trailing zeros A",
|
|
|
|
|
u".00/@@@+",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::fixedFraction(2).withMinDigits(3)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0.1,
|
|
|
|
|
u"0.10");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"FracSig with trailing zeros B",
|
|
|
|
|
u".00/@@@+",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::fixedFraction(2).withMinDigits(3)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0.0999999,
|
|
|
|
|
u"0.10");
|
2017-09-27 00:25:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::roundingOther() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Rounding None",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"round-unlimited",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::unlimited()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0.8765",
|
|
|
|
|
u"0.08765",
|
|
|
|
|
u"0.008765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Increment",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"round-increment/0.5",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::increment(0.5).withMinFraction(1)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650.0",
|
|
|
|
|
u"8,765.0",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.5",
|
|
|
|
|
u"9.0",
|
|
|
|
|
u"1.0",
|
|
|
|
|
u"0.0",
|
|
|
|
|
u"0.0",
|
|
|
|
|
u"0.0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Increment with Min Fraction",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"round-increment/0.50",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::increment(0.5).withMinFraction(2)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650.00",
|
|
|
|
|
u"8,765.00",
|
|
|
|
|
u"876.50",
|
|
|
|
|
u"87.50",
|
|
|
|
|
u"9.00",
|
|
|
|
|
u"1.00",
|
|
|
|
|
u"0.00",
|
|
|
|
|
u"0.00",
|
|
|
|
|
u"0.00");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Currency Standard",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/CZK round-currency-standard",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::currency(UCurrencyUsage::UCURR_USAGE_STANDARD))
|
|
|
|
|
.unit(CZK),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"CZK 87,650.00",
|
|
|
|
|
u"CZK 8,765.00",
|
|
|
|
|
u"CZK 876.50",
|
|
|
|
|
u"CZK 87.65",
|
|
|
|
|
u"CZK 8.76",
|
|
|
|
|
u"CZK 0.88",
|
|
|
|
|
u"CZK 0.09",
|
|
|
|
|
u"CZK 0.01",
|
|
|
|
|
u"CZK 0.00");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Currency Cash",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/CZK round-currency-cash",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::currency(UCurrencyUsage::UCURR_USAGE_CASH))
|
|
|
|
|
.unit(CZK),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"CZK 87,650",
|
|
|
|
|
u"CZK 8,765",
|
|
|
|
|
u"CZK 876",
|
|
|
|
|
u"CZK 88",
|
|
|
|
|
u"CZK 9",
|
|
|
|
|
u"CZK 1",
|
|
|
|
|
u"CZK 0",
|
|
|
|
|
u"CZK 0",
|
|
|
|
|
u"CZK 0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Currency Cash with Nickel Rounding",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/CAD round-currency-cash",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::currency(UCurrencyUsage::UCURR_USAGE_CASH))
|
|
|
|
|
.unit(CAD),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"CA$87,650.00",
|
|
|
|
|
u"CA$8,765.00",
|
|
|
|
|
u"CA$876.50",
|
|
|
|
|
u"CA$87.65",
|
|
|
|
|
u"CA$8.75",
|
|
|
|
|
u"CA$0.90",
|
|
|
|
|
u"CA$0.10",
|
|
|
|
|
u"CA$0.00",
|
|
|
|
|
u"CA$0.00");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Currency not in top-level fluent chain",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"round-integer", // calling .withCurrency() applies currency rounding rules immediately
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(
|
|
|
|
|
Rounder::currency(UCurrencyUsage::UCURR_USAGE_CASH).withCurrency(CZK)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876",
|
|
|
|
|
u"88",
|
|
|
|
|
u"9",
|
|
|
|
|
u"1",
|
|
|
|
|
u"0",
|
|
|
|
|
u"0",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
// NOTE: Other tests cover the behavior of the other rounding modes.
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Rounding Mode CEILING",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"round-integer/ceiling",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().rounding(Rounder::integer().withMode(UNumberFormatRoundingMode::UNUM_ROUND_CEILING)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"877",
|
|
|
|
|
u"88",
|
|
|
|
|
u"9",
|
|
|
|
|
u"1",
|
|
|
|
|
u"1",
|
|
|
|
|
u"1",
|
|
|
|
|
u"0");
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::grouping() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescendingBig(
|
|
|
|
|
u"Western Grouping",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"group-auto",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().grouping(UNUM_GROUPING_AUTO),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650,000",
|
|
|
|
|
u"8,765,000",
|
|
|
|
|
u"876,500",
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescendingBig(
|
|
|
|
|
u"Indic Grouping",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"group-auto",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().grouping(UNUM_GROUPING_AUTO),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
Locale("en-IN"),
|
|
|
|
|
u"8,76,50,000",
|
|
|
|
|
u"87,65,000",
|
|
|
|
|
u"8,76,500",
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescendingBig(
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"Western Grouping, Min 2",
|
|
|
|
|
u"group-min2",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().grouping(UNUM_GROUPING_MIN2),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650,000",
|
|
|
|
|
u"8,765,000",
|
|
|
|
|
u"876,500",
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescendingBig(
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"Indic Grouping, Min 2",
|
|
|
|
|
u"group-min2",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().grouping(UNUM_GROUPING_MIN2),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
Locale("en-IN"),
|
|
|
|
|
u"8,76,50,000",
|
|
|
|
|
u"87,65,000",
|
|
|
|
|
u"8,76,500",
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescendingBig(
|
|
|
|
|
u"No Grouping",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"group-off",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().grouping(UNUM_GROUPING_OFF),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
Locale("en-IN"),
|
|
|
|
|
u"87650000",
|
|
|
|
|
u"8765000",
|
|
|
|
|
u"876500",
|
|
|
|
|
u"87650",
|
|
|
|
|
u"8765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0");
|
2018-02-06 03:08:17 +00:00
|
|
|
|
|
2018-02-09 22:55:36 +00:00
|
|
|
|
assertFormatDescendingBig(
|
|
|
|
|
u"Indic locale with THOUSANDS grouping",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"group-thousands",
|
2018-02-09 22:55:36 +00:00
|
|
|
|
NumberFormatter::with().grouping(UNUM_GROUPING_THOUSANDS),
|
|
|
|
|
Locale("en-IN"),
|
|
|
|
|
u"87,650,000",
|
|
|
|
|
u"8,765,000",
|
|
|
|
|
u"876,500",
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
2018-02-06 03:08:17 +00:00
|
|
|
|
// NOTE: Hungarian is interesting because it has minimumGroupingDigits=4 in locale data
|
|
|
|
|
// If this test breaks due to data changes, find another locale that has minimumGroupingDigits.
|
|
|
|
|
assertFormatDescendingBig(
|
|
|
|
|
u"Hungarian Grouping",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"group-auto",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().grouping(UNUM_GROUPING_AUTO),
|
|
|
|
|
Locale("hu"),
|
|
|
|
|
u"87 650 000",
|
|
|
|
|
u"8 765 000",
|
|
|
|
|
u"876500",
|
|
|
|
|
u"87650",
|
|
|
|
|
u"8765",
|
|
|
|
|
u"876,5",
|
|
|
|
|
u"87,65",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescendingBig(
|
|
|
|
|
u"Hungarian Grouping, Min 2",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"group-min2",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().grouping(UNUM_GROUPING_MIN2),
|
|
|
|
|
Locale("hu"),
|
|
|
|
|
u"87 650 000",
|
|
|
|
|
u"8 765 000",
|
|
|
|
|
u"876500",
|
|
|
|
|
u"87650",
|
|
|
|
|
u"8765",
|
|
|
|
|
u"876,5",
|
|
|
|
|
u"87,65",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescendingBig(
|
|
|
|
|
u"Hungarian Grouping, Always",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"group-on-aligned",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().grouping(UNUM_GROUPING_ON_ALIGNED),
|
|
|
|
|
Locale("hu"),
|
|
|
|
|
u"87 650 000",
|
|
|
|
|
u"8 765 000",
|
|
|
|
|
u"876 500",
|
|
|
|
|
u"87 650",
|
|
|
|
|
u"8 765",
|
|
|
|
|
u"876,5",
|
|
|
|
|
u"87,65",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
// NOTE: Bulgarian is interesting because it has no grouping in the default currency format.
|
|
|
|
|
// If this test breaks due to data changes, find another locale that has no default grouping.
|
|
|
|
|
assertFormatDescendingBig(
|
|
|
|
|
u"Bulgarian Currency Grouping",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD group-auto",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().grouping(UNUM_GROUPING_AUTO).unit(USD),
|
|
|
|
|
Locale("bg"),
|
|
|
|
|
u"87650000,00 щ.д.",
|
|
|
|
|
u"8765000,00 щ.д.",
|
|
|
|
|
u"876500,00 щ.д.",
|
|
|
|
|
u"87650,00 щ.д.",
|
|
|
|
|
u"8765,00 щ.д.",
|
|
|
|
|
u"876,50 щ.д.",
|
|
|
|
|
u"87,65 щ.д.",
|
|
|
|
|
u"8,76 щ.д.",
|
|
|
|
|
u"0,00 щ.д.");
|
|
|
|
|
|
|
|
|
|
assertFormatDescendingBig(
|
|
|
|
|
u"Bulgarian Currency Grouping, Always",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD group-on-aligned",
|
2018-02-06 03:08:17 +00:00
|
|
|
|
NumberFormatter::with().grouping(UNUM_GROUPING_ON_ALIGNED).unit(USD),
|
|
|
|
|
Locale("bg"),
|
|
|
|
|
u"87 650 000,00 щ.д.",
|
|
|
|
|
u"8 765 000,00 щ.д.",
|
|
|
|
|
u"876 500,00 щ.д.",
|
|
|
|
|
u"87 650,00 щ.д.",
|
|
|
|
|
u"8 765,00 щ.д.",
|
|
|
|
|
u"876,50 щ.д.",
|
|
|
|
|
u"87,65 щ.д.",
|
|
|
|
|
u"8,76 щ.д.",
|
|
|
|
|
u"0,00 щ.д.");
|
|
|
|
|
|
2018-03-24 07:36:18 +00:00
|
|
|
|
MacroProps macros;
|
|
|
|
|
macros.grouper = Grouper(4, 1, 3, UNUM_GROUPING_COUNT);
|
|
|
|
|
assertFormatDescendingBig(
|
|
|
|
|
u"Custom Grouping via Internal API",
|
|
|
|
|
nullptr,
|
|
|
|
|
NumberFormatter::with().macros(macros),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"8,7,6,5,0000",
|
|
|
|
|
u"8,7,6,5000",
|
|
|
|
|
u"876500",
|
|
|
|
|
u"87650",
|
|
|
|
|
u"8765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0");
|
2017-09-27 00:25:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::padding() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Padding",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().padding(Padder::none()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0.8765",
|
|
|
|
|
u"0.08765",
|
|
|
|
|
u"0.008765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Padding",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().padding(
|
|
|
|
|
Padder::codePoints(
|
|
|
|
|
'*', 8, PadPosition::UNUM_PAD_AFTER_PREFIX)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"**87,650",
|
|
|
|
|
u"***8,765",
|
|
|
|
|
u"***876.5",
|
|
|
|
|
u"***87.65",
|
|
|
|
|
u"***8.765",
|
|
|
|
|
u"**0.8765",
|
|
|
|
|
u"*0.08765",
|
|
|
|
|
u"0.008765",
|
|
|
|
|
u"*******0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Padding with code points",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().padding(
|
|
|
|
|
Padder::codePoints(
|
|
|
|
|
0x101E4, 8, PadPosition::UNUM_PAD_AFTER_PREFIX)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"𐇤𐇤87,650",
|
|
|
|
|
u"𐇤𐇤𐇤8,765",
|
|
|
|
|
u"𐇤𐇤𐇤876.5",
|
|
|
|
|
u"𐇤𐇤𐇤87.65",
|
|
|
|
|
u"𐇤𐇤𐇤8.765",
|
|
|
|
|
u"𐇤𐇤0.8765",
|
|
|
|
|
u"𐇤0.08765",
|
|
|
|
|
u"0.008765",
|
|
|
|
|
u"𐇤𐇤𐇤𐇤𐇤𐇤𐇤0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Padding with wide digits",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().padding(
|
|
|
|
|
Padder::codePoints(
|
|
|
|
|
'*', 8, PadPosition::UNUM_PAD_AFTER_PREFIX))
|
|
|
|
|
.adoptSymbols(new NumberingSystem(MATHSANB)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"**𝟴𝟳,𝟲𝟱𝟬",
|
|
|
|
|
u"***𝟴,𝟳𝟲𝟱",
|
|
|
|
|
u"***𝟴𝟳𝟲.𝟱",
|
|
|
|
|
u"***𝟴𝟳.𝟲𝟱",
|
|
|
|
|
u"***𝟴.𝟳𝟲𝟱",
|
|
|
|
|
u"**𝟬.𝟴𝟳𝟲𝟱",
|
|
|
|
|
u"*𝟬.𝟬𝟴𝟳𝟲𝟱",
|
|
|
|
|
u"𝟬.𝟬𝟬𝟴𝟳𝟲𝟱",
|
|
|
|
|
u"*******𝟬");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Padding with currency spacing",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().padding(
|
|
|
|
|
Padder::codePoints(
|
|
|
|
|
'*', 10, PadPosition::UNUM_PAD_AFTER_PREFIX))
|
|
|
|
|
.unit(GBP)
|
|
|
|
|
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"GBP 87,650.00",
|
|
|
|
|
u"GBP 8,765.00",
|
|
|
|
|
u"GBP*876.50",
|
|
|
|
|
u"GBP**87.65",
|
|
|
|
|
u"GBP***8.76",
|
|
|
|
|
u"GBP***0.88",
|
|
|
|
|
u"GBP***0.09",
|
|
|
|
|
u"GBP***0.01",
|
|
|
|
|
u"GBP***0.00");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Pad Before Prefix",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().padding(
|
|
|
|
|
Padder::codePoints(
|
|
|
|
|
'*', 8, PadPosition::UNUM_PAD_BEFORE_PREFIX)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-88.88,
|
|
|
|
|
u"**-88.88");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Pad After Prefix",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().padding(
|
|
|
|
|
Padder::codePoints(
|
|
|
|
|
'*', 8, PadPosition::UNUM_PAD_AFTER_PREFIX)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-88.88,
|
|
|
|
|
u"-**88.88");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Pad Before Suffix",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().padding(
|
|
|
|
|
Padder::codePoints(
|
|
|
|
|
'*', 8, PadPosition::UNUM_PAD_BEFORE_SUFFIX)).unit(NoUnit::percent()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
88.88,
|
|
|
|
|
u"88.88**%");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Pad After Suffix",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().padding(
|
|
|
|
|
Padder::codePoints(
|
|
|
|
|
'*', 8, PadPosition::UNUM_PAD_AFTER_SUFFIX)).unit(NoUnit::percent()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
88.88,
|
|
|
|
|
u"88.88%**");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency Spacing with Zero Digit Padding Broken",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().padding(
|
|
|
|
|
Padder::codePoints(
|
|
|
|
|
'0', 12, PadPosition::UNUM_PAD_AFTER_PREFIX))
|
|
|
|
|
.unit(GBP)
|
|
|
|
|
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
514.23,
|
|
|
|
|
u"GBP 000514.23"); // TODO: This is broken; it renders too wide (13 instead of 12).
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::integerWidth() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Integer Width Default",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"integer-width/+0",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(1)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0.8765",
|
|
|
|
|
u"0.08765",
|
|
|
|
|
u"0.008765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Integer Width Zero Fill 0",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"integer-width/+",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(0)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u".8765",
|
|
|
|
|
u".08765",
|
|
|
|
|
u".008765",
|
|
|
|
|
u""); // TODO: Avoid the empty string here?
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Integer Width Zero Fill 3",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"integer-width/+000",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(3)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"087.65",
|
|
|
|
|
u"008.765",
|
|
|
|
|
u"000.8765",
|
|
|
|
|
u"000.08765",
|
|
|
|
|
u"000.008765",
|
|
|
|
|
u"000");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Integer Width Max 3",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"integer-width/##0",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(1).truncateAt(3)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"650",
|
|
|
|
|
u"765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0.8765",
|
|
|
|
|
u"0.08765",
|
|
|
|
|
u"0.008765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Integer Width Fixed 2",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"integer-width/00",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(2).truncateAt(2)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"50",
|
|
|
|
|
u"65",
|
|
|
|
|
u"76.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"08.765",
|
|
|
|
|
u"00.8765",
|
|
|
|
|
u"00.08765",
|
|
|
|
|
u"00.008765",
|
|
|
|
|
u"00");
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::symbols() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"French Symbols with Japanese Data 1",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().symbols(FRENCH_SYMBOLS),
|
|
|
|
|
Locale::getJapan(),
|
|
|
|
|
u"87 650",
|
|
|
|
|
u"8 765",
|
|
|
|
|
u"876,5",
|
|
|
|
|
u"87,65",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"0,8765",
|
|
|
|
|
u"0,08765",
|
|
|
|
|
u"0,008765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"French Symbols with Japanese Data 2",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().notation(Notation::compactShort()).symbols(FRENCH_SYMBOLS),
|
|
|
|
|
Locale::getJapan(),
|
|
|
|
|
12345,
|
|
|
|
|
u"1,2\u4E07");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Latin Numbering System with Arabic Data",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD latin",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().adoptSymbols(new NumberingSystem(LATN)).unit(USD),
|
|
|
|
|
Locale("ar"),
|
|
|
|
|
u"US$ 87,650.00",
|
|
|
|
|
u"US$ 8,765.00",
|
|
|
|
|
u"US$ 876.50",
|
|
|
|
|
u"US$ 87.65",
|
|
|
|
|
u"US$ 8.76",
|
|
|
|
|
u"US$ 0.88",
|
|
|
|
|
u"US$ 0.09",
|
|
|
|
|
u"US$ 0.01",
|
|
|
|
|
u"US$ 0.00");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Math Numbering System with French Data",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"numbering-system/mathsanb",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().adoptSymbols(new NumberingSystem(MATHSANB)),
|
|
|
|
|
Locale::getFrench(),
|
|
|
|
|
u"𝟴𝟳 𝟲𝟱𝟬",
|
|
|
|
|
u"𝟴 𝟳𝟲𝟱",
|
|
|
|
|
u"𝟴𝟳𝟲,𝟱",
|
|
|
|
|
u"𝟴𝟳,𝟲𝟱",
|
|
|
|
|
u"𝟴,𝟳𝟲𝟱",
|
|
|
|
|
u"𝟬,𝟴𝟳𝟲𝟱",
|
|
|
|
|
u"𝟬,𝟬𝟴𝟳𝟲𝟱",
|
|
|
|
|
u"𝟬,𝟬𝟬𝟴𝟳𝟲𝟱",
|
|
|
|
|
u"𝟬");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Swiss Symbols (used in documentation)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().symbols(SWISS_SYMBOLS),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
12345.67,
|
|
|
|
|
u"12’345.67");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Myanmar Symbols (used in documentation)",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().symbols(MYANMAR_SYMBOLS),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
12345.67,
|
|
|
|
|
u"\u1041\u1042,\u1043\u1044\u1045.\u1046\u1047");
|
|
|
|
|
|
|
|
|
|
// NOTE: Locale ar puts ¤ after the number in NS arab but before the number in NS latn.
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency symbol should precede number in ar with NS latn",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD latin",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().adoptSymbols(new NumberingSystem(LATN)).unit(USD),
|
|
|
|
|
Locale("ar"),
|
|
|
|
|
12345.67,
|
|
|
|
|
u"US$ 12,345.67");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency symbol should precede number in ar@numbers=latn",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().unit(USD),
|
|
|
|
|
Locale("ar@numbers=latn"),
|
|
|
|
|
12345.67,
|
|
|
|
|
u"US$ 12,345.67");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
2018-02-26 23:32:05 +00:00
|
|
|
|
u"Currency symbol should follow number in ar-EG with NS arab",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().unit(USD),
|
2018-02-26 23:32:05 +00:00
|
|
|
|
Locale("ar-EG"),
|
2017-09-27 00:25:20 +00:00
|
|
|
|
12345.67,
|
|
|
|
|
u"١٢٬٣٤٥٫٦٧ US$");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Currency symbol should follow number in ar@numbers=arab",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().unit(USD),
|
|
|
|
|
Locale("ar@numbers=arab"),
|
|
|
|
|
12345.67,
|
|
|
|
|
u"١٢٬٣٤٥٫٦٧ US$");
|
|
|
|
|
|
2017-12-01 07:57:05 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"NumberingSystem in API should win over @numbers keyword",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD latin",
|
2017-12-01 07:57:05 +00:00
|
|
|
|
NumberFormatter::with().adoptSymbols(new NumberingSystem(LATN)).unit(USD),
|
|
|
|
|
Locale("ar@numbers=arab"),
|
|
|
|
|
12345.67,
|
|
|
|
|
u"US$ 12,345.67");
|
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2018-03-24 07:36:18 +00:00
|
|
|
|
assertEquals(
|
|
|
|
|
"NumberingSystem in API should win over @numbers keyword in reverse order",
|
2017-12-01 07:57:05 +00:00
|
|
|
|
u"US$ 12,345.67",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
NumberFormatter::withLocale(Locale("ar@numbers=arab")).adoptSymbols(new NumberingSystem(LATN))
|
|
|
|
|
.unit(USD)
|
|
|
|
|
.formatDouble(12345.67, status)
|
|
|
|
|
.toString());
|
2017-12-01 07:57:05 +00:00
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
|
DecimalFormatSymbols symbols = SWISS_SYMBOLS;
|
|
|
|
|
UnlocalizedNumberFormatter f = NumberFormatter::with().symbols(symbols);
|
|
|
|
|
symbols.setSymbol(DecimalFormatSymbols::ENumberFormatSymbol::kGroupingSeparatorSymbol, u"!", status);
|
|
|
|
|
assertFormatSingle(
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"Symbols object should be copied", nullptr, f, Locale::getEnglish(), 12345.67, u"12’345.67");
|
2017-09-27 00:25:20 +00:00
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"The last symbols setter wins",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"latin",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().symbols(symbols).adoptSymbols(new NumberingSystem(LATN)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
12345.67,
|
|
|
|
|
u"12,345.67");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"The last symbols setter wins",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
nullptr,
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().adoptSymbols(new NumberingSystem(LATN)).symbols(symbols),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
12345.67,
|
|
|
|
|
u"12!345.67");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Enable if/when currency symbol override is added.
|
|
|
|
|
//void NumberFormatterTest::symbolsOverride() {
|
|
|
|
|
// DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(Locale::getEnglish());
|
|
|
|
|
// dfs.setCurrencySymbol("@");
|
|
|
|
|
// dfs.setInternationalCurrencySymbol("foo");
|
|
|
|
|
// assertFormatSingle(
|
|
|
|
|
// u"Custom Short Currency Symbol",
|
|
|
|
|
// NumberFormatter::with().unit(Currency.getInstance("XXX")).symbols(dfs),
|
|
|
|
|
// Locale::getEnglish(),
|
|
|
|
|
// 12.3,
|
|
|
|
|
// u"@ 12.30");
|
|
|
|
|
//}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::sign() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Auto Positive",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"sign-auto",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_AUTO),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
444444,
|
|
|
|
|
u"444,444");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Auto Negative",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"sign-auto",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_AUTO),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-444444,
|
|
|
|
|
u"-444,444");
|
|
|
|
|
|
2018-01-30 02:49:07 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Auto Zero",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"sign-auto",
|
2018-01-30 02:49:07 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_AUTO),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0,
|
|
|
|
|
u"0");
|
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Always Positive",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"sign-always",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ALWAYS),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
444444,
|
|
|
|
|
u"+444,444");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Always Negative",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"sign-always",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ALWAYS),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-444444,
|
|
|
|
|
u"-444,444");
|
|
|
|
|
|
2018-01-30 02:49:07 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Always Zero",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"sign-always",
|
2018-01-30 02:49:07 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ALWAYS),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0,
|
|
|
|
|
u"+0");
|
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Never Positive",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"sign-never",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_NEVER),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
444444,
|
|
|
|
|
u"444,444");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Never Negative",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"sign-never",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_NEVER),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-444444,
|
|
|
|
|
u"444,444");
|
|
|
|
|
|
2018-01-30 02:49:07 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Never Zero",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"sign-never",
|
2018-01-30 02:49:07 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_NEVER),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0,
|
|
|
|
|
u"0");
|
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Accounting Positive",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD sign-accounting",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING).unit(USD),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
444444,
|
|
|
|
|
u"$444,444.00");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Accounting Negative",
|
2018-03-24 08:06:34 +00:00
|
|
|
|
u"currency/USD sign-accounting",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING).unit(USD),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-444444,
|
|
|
|
|
u"($444,444.00)");
|
|
|
|
|
|
2018-01-30 02:49:07 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Accounting Zero",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD sign-accounting",
|
2018-01-30 02:49:07 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING).unit(USD),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0,
|
|
|
|
|
u"$0.00");
|
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Accounting-Always Positive",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD sign-accounting-always",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_ALWAYS).unit(USD),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
444444,
|
|
|
|
|
u"+$444,444.00");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Accounting-Always Negative",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD sign-accounting-always",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_ALWAYS).unit(USD),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-444444,
|
|
|
|
|
u"($444,444.00)");
|
|
|
|
|
|
2018-01-30 02:49:07 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Accounting-Always Zero",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD sign-accounting-always",
|
2018-01-30 02:49:07 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_ALWAYS).unit(USD),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0,
|
|
|
|
|
u"+$0.00");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Except-Zero Positive",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"sign-except-zero",
|
2018-01-30 02:49:07 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_EXCEPT_ZERO),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
444444,
|
|
|
|
|
u"+444,444");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Except-Zero Negative",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"sign-except-zero",
|
2018-01-30 02:49:07 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_EXCEPT_ZERO),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-444444,
|
|
|
|
|
u"-444,444");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Except-Zero Zero",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"sign-except-zero",
|
2018-01-30 02:49:07 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_EXCEPT_ZERO),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0,
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Accounting-Except-Zero Positive",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD sign-accounting-except-zero",
|
2018-01-30 02:49:07 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO).unit(USD),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
444444,
|
|
|
|
|
u"+$444,444.00");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Accounting-Except-Zero Negative",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD sign-accounting-except-zero",
|
2018-01-30 02:49:07 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO).unit(USD),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-444444,
|
|
|
|
|
u"($444,444.00)");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Accounting-Except-Zero Zero",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD sign-accounting-except-zero",
|
2018-01-30 02:49:07 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO).unit(USD),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0,
|
|
|
|
|
u"$0.00");
|
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Sign Accounting Negative Hidden",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"currency/USD unit-width-hidden sign-accounting",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING)
|
|
|
|
|
.unit(USD)
|
|
|
|
|
.unitWidth(UNUM_UNIT_WIDTH_HIDDEN),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
-444444,
|
|
|
|
|
u"(444,444.00)");
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::decimal() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Decimal Default",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"decimal-auto",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().decimal(UNumberDecimalSeparatorDisplay::UNUM_DECIMAL_SEPARATOR_AUTO),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0.8765",
|
|
|
|
|
u"0.08765",
|
|
|
|
|
u"0.008765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Decimal Always Shown",
|
2018-03-24 07:36:18 +00:00
|
|
|
|
u"decimal-always",
|
2017-09-27 00:25:20 +00:00
|
|
|
|
NumberFormatter::with().decimal(UNumberDecimalSeparatorDisplay::UNUM_DECIMAL_SEPARATOR_ALWAYS),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650.",
|
|
|
|
|
u"8,765.",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0.8765",
|
|
|
|
|
u"0.08765",
|
|
|
|
|
u"0.008765",
|
|
|
|
|
u"0.");
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-03 04:38:16 +00:00
|
|
|
|
void NumberFormatterApiTest::multiplier() {
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Multiplier None",
|
2018-04-04 01:26:18 +00:00
|
|
|
|
u"multiply/1",
|
2018-04-03 04:38:16 +00:00
|
|
|
|
NumberFormatter::with().multiplier(Multiplier::none()),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"876.5",
|
|
|
|
|
u"87.65",
|
|
|
|
|
u"8.765",
|
|
|
|
|
u"0.8765",
|
|
|
|
|
u"0.08765",
|
|
|
|
|
u"0.008765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Multiplier Power of Ten",
|
2018-04-04 01:26:18 +00:00
|
|
|
|
u"multiply/1000000",
|
2018-04-03 04:38:16 +00:00
|
|
|
|
NumberFormatter::with().multiplier(Multiplier::powerOfTen(6)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"87,650,000,000",
|
|
|
|
|
u"8,765,000,000",
|
|
|
|
|
u"876,500,000",
|
|
|
|
|
u"87,650,000",
|
|
|
|
|
u"8,765,000",
|
|
|
|
|
u"876,500",
|
|
|
|
|
u"87,650",
|
|
|
|
|
u"8,765",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Multiplier Arbitrary Double",
|
2018-04-04 01:26:18 +00:00
|
|
|
|
u"multiply/5.2",
|
2018-04-03 04:38:16 +00:00
|
|
|
|
NumberFormatter::with().multiplier(Multiplier::arbitraryDouble(5.2)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"455,780",
|
|
|
|
|
u"45,578",
|
|
|
|
|
u"4,557.8",
|
|
|
|
|
u"455.78",
|
|
|
|
|
u"45.578",
|
|
|
|
|
u"4.5578",
|
|
|
|
|
u"0.45578",
|
|
|
|
|
u"0.045578",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Multiplier Arbitrary BigDecimal",
|
2018-04-04 01:26:18 +00:00
|
|
|
|
u"multiply/5.2",
|
2018-04-03 04:38:16 +00:00
|
|
|
|
NumberFormatter::with().multiplier(Multiplier::arbitraryDecimal({"5.2", -1})),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"455,780",
|
|
|
|
|
u"45,578",
|
|
|
|
|
u"4,557.8",
|
|
|
|
|
u"455.78",
|
|
|
|
|
u"45.578",
|
|
|
|
|
u"4.5578",
|
|
|
|
|
u"0.45578",
|
|
|
|
|
u"0.045578",
|
|
|
|
|
u"0");
|
|
|
|
|
|
|
|
|
|
assertFormatDescending(
|
|
|
|
|
u"Multiplier Zero",
|
2018-04-04 01:26:18 +00:00
|
|
|
|
u"multiply/0",
|
2018-04-03 04:38:16 +00:00
|
|
|
|
NumberFormatter::with().multiplier(Multiplier::arbitraryDouble(0)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
u"0",
|
|
|
|
|
u"0",
|
|
|
|
|
u"0",
|
|
|
|
|
u"0",
|
|
|
|
|
u"0",
|
|
|
|
|
u"0",
|
|
|
|
|
u"0",
|
|
|
|
|
u"0",
|
|
|
|
|
u"0");
|
2018-04-04 01:26:18 +00:00
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Multiplier Skeleton Scientific Notation and Percent",
|
|
|
|
|
u"percent multiply/1E2",
|
|
|
|
|
NumberFormatter::with().unit(NoUnit::percent()).multiplier(Multiplier::powerOfTen(2)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
0.5,
|
|
|
|
|
u"50%");
|
|
|
|
|
|
|
|
|
|
assertFormatSingle(
|
|
|
|
|
u"Negative Multiplier",
|
|
|
|
|
u"multiply/-5.2",
|
|
|
|
|
NumberFormatter::with().multiplier(Multiplier::arbitraryDouble(-5.2)),
|
|
|
|
|
Locale::getEnglish(),
|
|
|
|
|
2,
|
|
|
|
|
u"-10.4");
|
2018-04-03 04:38:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::locale() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
// Coverage for the locale setters.
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
UnicodeString actual = NumberFormatter::withLocale(Locale::getFrench()).formatInt(1234, status)
|
|
|
|
|
.toString();
|
|
|
|
|
assertEquals("Locale withLocale()", u"1 234", actual);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 22:31:07 +00:00
|
|
|
|
void NumberFormatterApiTest::formatTypes() {
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
LocalizedNumberFormatter formatter = NumberFormatter::withLocale(Locale::getEnglish());
|
|
|
|
|
const char* str1 = "98765432123456789E1";
|
|
|
|
|
UnicodeString actual = formatter.formatDecimal(str1, status).toString();
|
|
|
|
|
assertEquals("Format decNumber", u"987,654,321,234,567,890", actual);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
|
void NumberFormatterApiTest::errors() {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
LocalizedNumberFormatter lnf = NumberFormatter::withLocale(Locale::getEnglish()).rounding(
|
|
|
|
|
Rounder::fixedFraction(
|
|
|
|
|
-1));
|
|
|
|
|
|
|
|
|
|
{
|
2017-10-25 01:26:48 +00:00
|
|
|
|
UErrorCode status1 = U_ZERO_ERROR;
|
|
|
|
|
UErrorCode status2 = U_ZERO_ERROR;
|
|
|
|
|
FormattedNumber fn = lnf.formatInt(1, status1);
|
2017-09-27 00:25:20 +00:00
|
|
|
|
assertEquals(
|
2018-03-24 07:36:18 +00:00
|
|
|
|
"Should fail since rounder is not legal", U_NUMBER_ARG_OUTOFBOUNDS_ERROR, status1);
|
2017-10-25 01:26:48 +00:00
|
|
|
|
FieldPosition fp;
|
|
|
|
|
fn.populateFieldPosition(fp, status2);
|
|
|
|
|
assertEquals(
|
2018-03-24 07:36:18 +00:00
|
|
|
|
"Should fail on terminal method", U_NUMBER_ARG_OUTOFBOUNDS_ERROR, status2);
|
2017-09-27 00:25:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
lnf.copyErrorTo(status);
|
|
|
|
|
assertEquals(
|
2018-03-24 07:36:18 +00:00
|
|
|
|
"Should fail since rounder is not legal", U_NUMBER_ARG_OUTOFBOUNDS_ERROR, status);
|
2017-09-27 00:25:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-08 06:06:08 +00:00
|
|
|
|
void NumberFormatterApiTest::validRanges() {
|
|
|
|
|
|
|
|
|
|
#define EXPECTED_MAX_INT_FRAC_SIG 999
|
|
|
|
|
|
|
|
|
|
#define VALID_RANGE_ASSERT(status, method, lowerBound, argument) { \
|
|
|
|
|
UErrorCode expectedStatus = ((lowerBound <= argument) && (argument <= EXPECTED_MAX_INT_FRAC_SIG)) \
|
|
|
|
|
? U_ZERO_ERROR \
|
|
|
|
|
: U_NUMBER_ARG_OUTOFBOUNDS_ERROR; \
|
|
|
|
|
assertEquals( \
|
|
|
|
|
UnicodeString(u"Incorrect status for " #method " on input ") \
|
|
|
|
|
+ Int64ToUnicodeString(argument), \
|
|
|
|
|
expectedStatus, \
|
|
|
|
|
status); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define VALID_RANGE_ONEARG(setting, method, lowerBound) { \
|
|
|
|
|
for (int32_t argument = -2; argument <= EXPECTED_MAX_INT_FRAC_SIG + 2; argument++) { \
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR; \
|
|
|
|
|
NumberFormatter::with().setting(method(argument)).copyErrorTo(status); \
|
|
|
|
|
VALID_RANGE_ASSERT(status, method, lowerBound, argument); \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define VALID_RANGE_TWOARGS(setting, method, lowerBound) { \
|
|
|
|
|
for (int32_t argument = -2; argument <= EXPECTED_MAX_INT_FRAC_SIG + 2; argument++) { \
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR; \
|
|
|
|
|
/* Pass EXPECTED_MAX_INT_FRAC_SIG as the second argument so arg1 <= arg2 in expected cases */ \
|
|
|
|
|
NumberFormatter::with().setting(method(argument, EXPECTED_MAX_INT_FRAC_SIG)).copyErrorTo(status); \
|
|
|
|
|
VALID_RANGE_ASSERT(status, method, lowerBound, argument); \
|
|
|
|
|
status = U_ZERO_ERROR; \
|
|
|
|
|
/* Pass lowerBound as the first argument so arg1 <= arg2 in expected cases */ \
|
|
|
|
|
NumberFormatter::with().setting(method(lowerBound, argument)).copyErrorTo(status); \
|
|
|
|
|
VALID_RANGE_ASSERT(status, method, lowerBound, argument); \
|
|
|
|
|
/* Check that first argument must be less than or equal to second argument */ \
|
|
|
|
|
NumberFormatter::with().setting(method(argument, argument - 1)).copyErrorTo(status); \
|
|
|
|
|
assertEquals("Incorrect status for " #method " on max < min input", \
|
|
|
|
|
U_NUMBER_ARG_OUTOFBOUNDS_ERROR, \
|
|
|
|
|
status); \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VALID_RANGE_ONEARG(rounding, Rounder::fixedFraction, 0);
|
|
|
|
|
VALID_RANGE_ONEARG(rounding, Rounder::minFraction, 0);
|
|
|
|
|
VALID_RANGE_ONEARG(rounding, Rounder::maxFraction, 0);
|
|
|
|
|
VALID_RANGE_TWOARGS(rounding, Rounder::minMaxFraction, 0);
|
|
|
|
|
VALID_RANGE_ONEARG(rounding, Rounder::fixedDigits, 1);
|
|
|
|
|
VALID_RANGE_ONEARG(rounding, Rounder::minDigits, 1);
|
|
|
|
|
VALID_RANGE_ONEARG(rounding, Rounder::maxDigits, 1);
|
|
|
|
|
VALID_RANGE_TWOARGS(rounding, Rounder::minMaxDigits, 1);
|
|
|
|
|
VALID_RANGE_ONEARG(rounding, Rounder::fixedFraction(1).withMinDigits, 1);
|
|
|
|
|
VALID_RANGE_ONEARG(rounding, Rounder::fixedFraction(1).withMaxDigits, 1);
|
|
|
|
|
VALID_RANGE_ONEARG(notation, Notation::scientific().withMinExponentDigits, 1);
|
|
|
|
|
VALID_RANGE_ONEARG(integerWidth, IntegerWidth::zeroFillTo, 0);
|
|
|
|
|
VALID_RANGE_ONEARG(integerWidth, IntegerWidth::zeroFillTo(0).truncateAt, -1);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-17 07:24:02 +00:00
|
|
|
|
void NumberFormatterApiTest::copyMove() {
|
|
|
|
|
IcuTestErrorCode status(*this, "copyMove");
|
|
|
|
|
|
|
|
|
|
// Default constructors
|
|
|
|
|
LocalizedNumberFormatter l1;
|
|
|
|
|
assertEquals("Initial behavior", u"10", l1.formatInt(10, status).toString());
|
|
|
|
|
assertEquals("Initial call count", 1, l1.getCallCount());
|
|
|
|
|
assertTrue("Initial compiled", l1.getCompiled() == nullptr);
|
|
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
|
l1 = NumberFormatter::withLocale("en").unit(NoUnit::percent()).threshold(3);
|
|
|
|
|
assertEquals("Initial behavior", u"10%", l1.formatInt(10, status).toString());
|
|
|
|
|
assertEquals("Initial call count", 1, l1.getCallCount());
|
|
|
|
|
assertTrue("Initial compiled", l1.getCompiled() == nullptr);
|
|
|
|
|
l1.formatInt(123, status);
|
|
|
|
|
assertEquals("Still not compiled", 2, l1.getCallCount());
|
|
|
|
|
assertTrue("Still not compiled", l1.getCompiled() == nullptr);
|
|
|
|
|
l1.formatInt(123, status);
|
|
|
|
|
assertEquals("Compiled", u"10%", l1.formatInt(10, status).toString());
|
|
|
|
|
assertEquals("Compiled", INT32_MIN, l1.getCallCount());
|
|
|
|
|
assertTrue("Compiled", l1.getCompiled() != nullptr);
|
|
|
|
|
|
|
|
|
|
// Copy constructor
|
|
|
|
|
LocalizedNumberFormatter l2 = l1;
|
|
|
|
|
assertEquals("[constructor] Copy behavior", u"10%", l2.formatInt(10, status).toString());
|
|
|
|
|
assertEquals("[constructor] Copy should not have compiled state", 1, l2.getCallCount());
|
|
|
|
|
assertTrue("[constructor] Copy should not have compiled state", l2.getCompiled() == nullptr);
|
|
|
|
|
|
|
|
|
|
// Move constructor
|
|
|
|
|
LocalizedNumberFormatter l3 = std::move(l1);
|
|
|
|
|
assertEquals("[constructor] Move behavior", u"10%", l3.formatInt(10, status).toString());
|
|
|
|
|
assertEquals("[constructor] Move *should* have compiled state", INT32_MIN, l3.getCallCount());
|
|
|
|
|
assertTrue("[constructor] Move *should* have compiled state", l3.getCompiled() != nullptr);
|
|
|
|
|
assertEquals("[constructor] Source should be reset after move", 0, l1.getCallCount());
|
|
|
|
|
assertTrue("[constructor] Source should be reset after move", l1.getCompiled() == nullptr);
|
|
|
|
|
|
|
|
|
|
// Reset l1 and l2 to check for macro-props copying for behavior testing
|
|
|
|
|
l1 = NumberFormatter::withLocale("en");
|
|
|
|
|
l2 = NumberFormatter::withLocale("en");
|
|
|
|
|
|
|
|
|
|
// Copy assignment
|
|
|
|
|
l1 = l3;
|
|
|
|
|
assertEquals("[assignment] Copy behavior", u"10%", l1.formatInt(10, status).toString());
|
|
|
|
|
assertEquals("[assignment] Copy should not have compiled state", 1, l1.getCallCount());
|
|
|
|
|
assertTrue("[assignment] Copy should not have compiled state", l1.getCompiled() == nullptr);
|
|
|
|
|
|
|
|
|
|
// Move assignment
|
|
|
|
|
l2 = std::move(l3);
|
|
|
|
|
assertEquals("[assignment] Move behavior", u"10%", l2.formatInt(10, status).toString());
|
|
|
|
|
assertEquals("[assignment] Move *should* have compiled state", INT32_MIN, l2.getCallCount());
|
|
|
|
|
assertTrue("[assignment] Move *should* have compiled state", l2.getCompiled() != nullptr);
|
|
|
|
|
assertEquals("[assignment] Source should be reset after move", 0, l3.getCallCount());
|
|
|
|
|
assertTrue("[assignment] Source should be reset after move", l3.getCompiled() == nullptr);
|
|
|
|
|
|
|
|
|
|
// Coverage tests for UnlocalizedNumberFormatter
|
|
|
|
|
UnlocalizedNumberFormatter u1;
|
|
|
|
|
assertEquals("Default behavior", u"10", u1.locale("en").formatInt(10, status).toString());
|
|
|
|
|
u1 = u1.unit(NoUnit::percent());
|
|
|
|
|
assertEquals("Copy assignment", u"10%", u1.locale("en").formatInt(10, status).toString());
|
|
|
|
|
UnlocalizedNumberFormatter u2 = u1;
|
|
|
|
|
assertEquals("Copy constructor", u"10%", u2.locale("en").formatInt(10, status).toString());
|
|
|
|
|
UnlocalizedNumberFormatter u3 = std::move(u1);
|
|
|
|
|
assertEquals("Move constructor", u"10%", u3.locale("en").formatInt(10, status).toString());
|
|
|
|
|
u1 = NumberFormatter::with();
|
|
|
|
|
u1 = std::move(u2);
|
|
|
|
|
assertEquals("Move assignment", u"10%", u1.locale("en").formatInt(10, status).toString());
|
|
|
|
|
|
|
|
|
|
// FormattedNumber move operators
|
|
|
|
|
FormattedNumber result = l1.formatInt(10, status);
|
|
|
|
|
assertEquals("FormattedNumber move constructor", u"10%", result.toString());
|
|
|
|
|
result = l1.formatInt(20, status);
|
|
|
|
|
assertEquals("FormattedNumber move assignment", u"20%", result.toString());
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
|
|
2018-03-24 07:36:18 +00:00
|
|
|
|
void NumberFormatterApiTest::assertFormatDescending(const char16_t* umessage, const char16_t* uskeleton,
|
|
|
|
|
const UnlocalizedNumberFormatter& f, Locale locale,
|
|
|
|
|
...) {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, locale);
|
2018-03-24 07:36:18 +00:00
|
|
|
|
UnicodeString message(TRUE, umessage, -1);
|
2017-09-27 00:25:20 +00:00
|
|
|
|
static double inputs[] = {87650, 8765, 876.5, 87.65, 8.765, 0.8765, 0.08765, 0.008765, 0};
|
|
|
|
|
const LocalizedNumberFormatter l1 = f.threshold(0).locale(locale); // no self-regulation
|
|
|
|
|
const LocalizedNumberFormatter l2 = f.threshold(1).locale(locale); // all self-regulation
|
2018-03-24 07:36:18 +00:00
|
|
|
|
IcuTestErrorCode status(*this, "assertFormatDescending");
|
|
|
|
|
status.setScope(message);
|
|
|
|
|
UnicodeString expecteds[10];
|
2017-09-27 00:25:20 +00:00
|
|
|
|
for (int16_t i = 0; i < 9; i++) {
|
|
|
|
|
char16_t caseNumber = u'0' + i;
|
|
|
|
|
double d = inputs[i];
|
|
|
|
|
UnicodeString expected = va_arg(args, const char16_t*);
|
2018-03-24 07:36:18 +00:00
|
|
|
|
expecteds[i] = expected;
|
2017-09-27 00:25:20 +00:00
|
|
|
|
UnicodeString actual1 = l1.formatDouble(d, status).toString();
|
|
|
|
|
assertSuccess(message + u": Unsafe Path: " + caseNumber, status);
|
|
|
|
|
assertEquals(message + u": Unsafe Path: " + caseNumber, expected, actual1);
|
|
|
|
|
UnicodeString actual2 = l2.formatDouble(d, status).toString();
|
|
|
|
|
assertSuccess(message + u": Safe Path: " + caseNumber, status);
|
|
|
|
|
assertEquals(message + u": Safe Path: " + caseNumber, expected, actual2);
|
|
|
|
|
}
|
2018-03-24 07:36:18 +00:00
|
|
|
|
if (uskeleton != nullptr) { // if null, skeleton is declared as undefined.
|
|
|
|
|
UnicodeString skeleton(TRUE, uskeleton, -1);
|
|
|
|
|
// Only compare normalized skeletons: the tests need not provide the normalized forms.
|
|
|
|
|
// Use the normalized form to construct the testing formatter to guarantee no loss of info.
|
|
|
|
|
UnicodeString normalized = NumberFormatter::fromSkeleton(skeleton, status).toSkeleton(status);
|
|
|
|
|
assertEquals(message + ": Skeleton:", normalized, f.toSkeleton(status));
|
|
|
|
|
LocalizedNumberFormatter l3 = NumberFormatter::fromSkeleton(normalized, status).locale(locale);
|
|
|
|
|
for (int32_t i = 0; i < 9; i++) {
|
|
|
|
|
double d = inputs[i];
|
|
|
|
|
UnicodeString actual3 = l3.formatDouble(d, status).toString();
|
|
|
|
|
assertEquals(message + ": Skeleton Path: " + d, expecteds[i], actual3);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
assertUndefinedSkeleton(f);
|
|
|
|
|
}
|
2017-09-27 00:25:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-24 07:36:18 +00:00
|
|
|
|
void NumberFormatterApiTest::assertFormatDescendingBig(const char16_t* umessage, const char16_t* uskeleton,
|
|
|
|
|
const UnlocalizedNumberFormatter& f, Locale locale,
|
|
|
|
|
...) {
|
2017-09-27 00:25:20 +00:00
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, locale);
|
2018-03-24 07:36:18 +00:00
|
|
|
|
UnicodeString message(TRUE, umessage, -1);
|
2017-09-27 00:25:20 +00:00
|
|
|
|
static double inputs[] = {87650000, 8765000, 876500, 87650, 8765, 876.5, 87.65, 8.765, 0};
|
|
|
|
|
const LocalizedNumberFormatter l1 = f.threshold(0).locale(locale); // no self-regulation
|
|
|
|
|
const LocalizedNumberFormatter l2 = f.threshold(1).locale(locale); // all self-regulation
|
2018-03-24 07:36:18 +00:00
|
|
|
|
IcuTestErrorCode status(*this, "assertFormatDescendingBig");
|
|
|
|
|
status.setScope(message);
|
|
|
|
|
UnicodeString expecteds[10];
|
2017-09-27 00:25:20 +00:00
|
|
|
|
for (int16_t i = 0; i < 9; i++) {
|
|
|
|
|
char16_t caseNumber = u'0' + i;
|
|
|
|
|
double d = inputs[i];
|
|
|
|
|
UnicodeString expected = va_arg(args, const char16_t*);
|
2018-03-24 07:36:18 +00:00
|
|
|
|
expecteds[i] = expected;
|
2017-09-27 00:25:20 +00:00
|
|
|
|
UnicodeString actual1 = l1.formatDouble(d, status).toString();
|
|
|
|
|
assertSuccess(message + u": Unsafe Path: " + caseNumber, status);
|
|
|
|
|
assertEquals(message + u": Unsafe Path: " + caseNumber, expected, actual1);
|
|
|
|
|
UnicodeString actual2 = l2.formatDouble(d, status).toString();
|
|
|
|
|
assertSuccess(message + u": Safe Path: " + caseNumber, status);
|
|
|
|
|
assertEquals(message + u": Safe Path: " + caseNumber, expected, actual2);
|
|
|
|
|
}
|
2018-03-24 07:36:18 +00:00
|
|
|
|
if (uskeleton != nullptr) { // if null, skeleton is declared as undefined.
|
|
|
|
|
UnicodeString skeleton(TRUE, uskeleton, -1);
|
|
|
|
|
// Only compare normalized skeletons: the tests need not provide the normalized forms.
|
|
|
|
|
// Use the normalized form to construct the testing formatter to guarantee no loss of info.
|
|
|
|
|
UnicodeString normalized = NumberFormatter::fromSkeleton(skeleton, status).toSkeleton(status);
|
|
|
|
|
assertEquals(message + ": Skeleton:", normalized, f.toSkeleton(status));
|
|
|
|
|
LocalizedNumberFormatter l3 = NumberFormatter::fromSkeleton(normalized, status).locale(locale);
|
|
|
|
|
for (int32_t i = 0; i < 9; i++) {
|
|
|
|
|
double d = inputs[i];
|
|
|
|
|
UnicodeString actual3 = l3.formatDouble(d, status).toString();
|
|
|
|
|
assertEquals(message + ": Skeleton Path: " + d, expecteds[i], actual3);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
assertUndefinedSkeleton(f);
|
|
|
|
|
}
|
2017-09-27 00:25:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-24 07:36:18 +00:00
|
|
|
|
void NumberFormatterApiTest::assertFormatSingle(const char16_t* umessage, const char16_t* uskeleton,
|
|
|
|
|
const UnlocalizedNumberFormatter& f, Locale locale,
|
|
|
|
|
double input, const UnicodeString& expected) {
|
|
|
|
|
UnicodeString message(TRUE, umessage, -1);
|
2017-09-27 00:25:20 +00:00
|
|
|
|
const LocalizedNumberFormatter l1 = f.threshold(0).locale(locale); // no self-regulation
|
|
|
|
|
const LocalizedNumberFormatter l2 = f.threshold(1).locale(locale); // all self-regulation
|
2018-03-24 07:36:18 +00:00
|
|
|
|
IcuTestErrorCode status(*this, "assertFormatSingle");
|
|
|
|
|
status.setScope(message);
|
2017-09-27 00:25:20 +00:00
|
|
|
|
UnicodeString actual1 = l1.formatDouble(input, status).toString();
|
|
|
|
|
assertSuccess(message + u": Unsafe Path", status);
|
|
|
|
|
assertEquals(message + u": Unsafe Path", expected, actual1);
|
|
|
|
|
UnicodeString actual2 = l2.formatDouble(input, status).toString();
|
|
|
|
|
assertSuccess(message + u": Safe Path", status);
|
|
|
|
|
assertEquals(message + u": Safe Path", expected, actual2);
|
2018-03-24 07:36:18 +00:00
|
|
|
|
if (uskeleton != nullptr) { // if null, skeleton is declared as undefined.
|
|
|
|
|
UnicodeString skeleton(TRUE, uskeleton, -1);
|
|
|
|
|
// Only compare normalized skeletons: the tests need not provide the normalized forms.
|
|
|
|
|
// Use the normalized form to construct the testing formatter to ensure no loss of info.
|
|
|
|
|
UnicodeString normalized = NumberFormatter::fromSkeleton(skeleton, status).toSkeleton(status);
|
|
|
|
|
assertEquals(message + ": Skeleton:", normalized, f.toSkeleton(status));
|
|
|
|
|
LocalizedNumberFormatter l3 = NumberFormatter::fromSkeleton(normalized, status).locale(locale);
|
|
|
|
|
UnicodeString actual3 = l3.formatDouble(input, status).toString();
|
|
|
|
|
assertEquals(message + ": Skeleton Path: " + input, expected, actual3);
|
|
|
|
|
} else {
|
|
|
|
|
assertUndefinedSkeleton(f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NumberFormatterApiTest::assertUndefinedSkeleton(const UnlocalizedNumberFormatter& f) {
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
UnicodeString skeleton = f.toSkeleton(status);
|
|
|
|
|
assertEquals(
|
|
|
|
|
u"Expect toSkeleton to fail, but passed, producing: " + skeleton,
|
|
|
|
|
U_UNSUPPORTED_ERROR,
|
|
|
|
|
status);
|
2017-09-27 00:25:20 +00:00
|
|
|
|
}
|
2017-09-27 05:31:57 +00:00
|
|
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|