assertFormatDescending(
u"Basic",
u"",
+ u"",
NumberFormatter::with(),
Locale::getEnglish(),
u"87,650",
assertFormatDescendingBig(
u"Big Simple",
u"notation-simple",
+ u"",
NumberFormatter::with().notation(Notation::simple()),
Locale::getEnglish(),
u"87,650,000",
assertFormatSingle(
u"Basic with Negative Sign",
u"",
+ u"",
NumberFormatter::with(),
Locale::getEnglish(),
-9876543.21,
assertFormatDescending(
u"Scientific",
u"scientific",
+ u"E0",
NumberFormatter::with().notation(Notation::scientific()),
Locale::getEnglish(),
u"8.765E4",
assertFormatDescending(
u"Engineering",
u"engineering",
+ u"EE0",
NumberFormatter::with().notation(Notation::engineering()),
Locale::getEnglish(),
u"87.65E3",
assertFormatDescending(
u"Scientific sign always shown",
u"scientific/sign-always",
+ u"E+!0",
NumberFormatter::with().notation(
Notation::scientific().withExponentSignDisplay(UNumberSignDisplay::UNUM_SIGN_ALWAYS)),
Locale::getEnglish(),
assertFormatDescending(
u"Scientific min exponent digits",
u"scientific/+ee",
+ u"E00",
NumberFormatter::with().notation(Notation::scientific().withMinExponentDigits(2)),
Locale::getEnglish(),
u"8.765E04",
assertFormatSingle(
u"Scientific Negative",
u"scientific",
+ u"E0",
NumberFormatter::with().notation(Notation::scientific()),
Locale::getEnglish(),
-1000000,
assertFormatSingle(
u"Scientific Infinity",
u"scientific",
+ u"E0",
NumberFormatter::with().notation(Notation::scientific()),
Locale::getEnglish(),
-uprv_getInfinity(),
assertFormatSingle(
u"Scientific NaN",
u"scientific",
+ u"E0",
NumberFormatter::with().notation(Notation::scientific()),
Locale::getEnglish(),
uprv_getNaN(),
assertFormatDescending(
u"Compact Short",
u"compact-short",
+ u"K",
NumberFormatter::with().notation(Notation::compactShort()),
Locale::getEnglish(),
u"88K",
assertFormatDescending(
u"Compact Long",
u"compact-long",
+ u"KK",
NumberFormatter::with().notation(Notation::compactLong()),
Locale::getEnglish(),
u"88 thousand",
assertFormatDescending(
u"Compact Short Currency",
u"compact-short currency/USD",
+ u"K currency/USD",
NumberFormatter::with().notation(Notation::compactShort()).unit(USD),
Locale::getEnglish(),
u"$88K",
assertFormatDescending(
u"Compact Short with ISO Currency",
u"compact-short currency/USD unit-width-iso-code",
+ u"K currency/USD unit-width-iso-code",
NumberFormatter::with().notation(Notation::compactShort())
.unit(USD)
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE),
assertFormatDescending(
u"Compact Short with Long Name Currency",
u"compact-short currency/USD unit-width-full-name",
+ u"K currency/USD unit-width-full-name",
NumberFormatter::with().notation(Notation::compactShort())
.unit(USD)
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
assertFormatDescending(
u"Compact Long Currency",
u"compact-long currency/USD",
+ u"KK currency/USD",
NumberFormatter::with().notation(Notation::compactLong()).unit(USD),
Locale::getEnglish(),
u"$88K", // should be something like "$88 thousand"
assertFormatDescending(
u"Compact Long with ISO Currency",
u"compact-long currency/USD unit-width-iso-code",
+ u"KK currency/USD unit-width-iso-code",
NumberFormatter::with().notation(Notation::compactLong())
.unit(USD)
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE),
assertFormatDescending(
u"Compact Long with Long Name Currency",
u"compact-long currency/USD unit-width-full-name",
+ u"KK currency/USD unit-width-full-name",
NumberFormatter::with().notation(Notation::compactLong())
.unit(USD)
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
assertFormatSingle(
u"Compact Plural One",
u"compact-long",
+ u"KK",
NumberFormatter::with().notation(Notation::compactLong()),
Locale::createFromName("es"),
1000000,
assertFormatSingle(
u"Compact Plural Other",
u"compact-long",
+ u"KK",
NumberFormatter::with().notation(Notation::compactLong()),
Locale::createFromName("es"),
2000000,
assertFormatSingle(
u"Compact with Negative Sign",
u"compact-short",
+ u"K",
NumberFormatter::with().notation(Notation::compactShort()),
Locale::getEnglish(),
-9876543.21,
assertFormatSingle(
u"Compact Rounding",
u"compact-short",
+ u"K",
NumberFormatter::with().notation(Notation::compactShort()),
Locale::getEnglish(),
990000,
assertFormatSingle(
u"Compact Rounding",
u"compact-short",
+ u"K",
NumberFormatter::with().notation(Notation::compactShort()),
Locale::getEnglish(),
999000,
assertFormatSingle(
u"Compact Rounding",
u"compact-short",
+ u"K",
NumberFormatter::with().notation(Notation::compactShort()),
Locale::getEnglish(),
999900,
assertFormatSingle(
u"Compact Rounding",
u"compact-short",
+ u"K",
NumberFormatter::with().notation(Notation::compactShort()),
Locale::getEnglish(),
9900000,
assertFormatSingle(
u"Compact Rounding",
u"compact-short",
+ u"K",
NumberFormatter::with().notation(Notation::compactShort()),
Locale::getEnglish(),
9990000,
assertFormatSingle(
u"Compact in zh-Hant-HK",
u"compact-short",
+ u"K",
NumberFormatter::with().notation(Notation::compactShort()),
Locale("zh-Hant-HK"),
1e7,
assertFormatSingle(
u"Compact in zh-Hant",
u"compact-short",
+ u"K",
NumberFormatter::with().notation(Notation::compactShort()),
Locale("zh-Hant"),
1e7,
assertFormatSingle(
u"Compact Infinity",
u"compact-short",
+ u"K",
NumberFormatter::with().notation(Notation::compactShort()),
Locale::getEnglish(),
-uprv_getInfinity(),
assertFormatSingle(
u"Compact NaN",
u"compact-short",
+ u"K",
NumberFormatter::with().notation(Notation::compactShort()),
Locale::getEnglish(),
uprv_getNaN(),
assertFormatDescending(
u"Meters Short and unit() method",
u"measure-unit/length-meter",
+ u"unit/meter",
NumberFormatter::with().unit(MeasureUnit::getMeter()),
Locale::getEnglish(),
u"87,650 m",
assertFormatDescending(
u"Meters Long and adoptUnit() method",
u"measure-unit/length-meter unit-width-full-name",
+ u"unit/meter unit-width-full-name",
NumberFormatter::with().adoptUnit(new MeasureUnit(METER))
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
Locale::getEnglish(),
assertFormatDescending(
u"Compact Meters Long",
u"compact-long measure-unit/length-meter unit-width-full-name",
+ u"KK unit/meter unit-width-full-name",
NumberFormatter::with().notation(Notation::compactLong())
.unit(METER)
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
assertFormatSingle(
u"Meters with Negative Sign",
u"measure-unit/length-meter",
+ u"unit/meter",
NumberFormatter::with().unit(METER),
Locale::getEnglish(),
-9876543.21,
assertFormatSingle(
u"Interesting Data Fallback 1",
u"measure-unit/duration-day unit-width-full-name",
+ u"unit/day unit-width-full-name",
NumberFormatter::with().unit(DAY).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
Locale::createFromName("brx"),
5.43,
assertFormatSingle(
u"Interesting Data Fallback 2",
u"measure-unit/duration-day unit-width-narrow",
+ u"unit/day unit-width-narrow",
NumberFormatter::with().unit(DAY).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW),
Locale::createFromName("brx"),
5.43,
assertFormatSingle(
u"Interesting Data Fallback 3",
u"measure-unit/area-square-meter unit-width-narrow",
+ u"unit/square-meter unit-width-narrow",
NumberFormatter::with().unit(SQUARE_METER).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW),
Locale::createFromName("en-GB"),
5.43,
assertFormatSingle(
u"Interesting Data Fallback 4",
u"measure-unit/area-square-meter unit-width-narrow",
+ u"unit/square-meter unit-width-narrow",
NumberFormatter::with().unit(SQUARE_METER).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW),
Locale::createFromName("root"),
5.43,
assertFormatSingle(
u"Difference between Narrow and Short (Narrow Version)",
u"measure-unit/temperature-fahrenheit unit-width-narrow",
+ u"unit/fahrenheit unit-width-narrow",
NumberFormatter::with().unit(FAHRENHEIT).unitWidth(UNUM_UNIT_WIDTH_NARROW),
Locale("es-US"),
5.43,
assertFormatSingle(
u"Difference between Narrow and Short (Short Version)",
u"measure-unit/temperature-fahrenheit unit-width-short",
+ u"unit/fahrenheit unit-width-short",
NumberFormatter::with().unit(FAHRENHEIT).unitWidth(UNUM_UNIT_WIDTH_SHORT),
Locale("es-US"),
5.43,
assertFormatSingle(
u"MeasureUnit form without {0} in CLDR pattern",
u"measure-unit/temperature-kelvin unit-width-full-name",
+ u"unit/kelvin unit-width-full-name",
NumberFormatter::with().unit(KELVIN).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
Locale("es-MX"),
1,
assertFormatSingle(
u"MeasureUnit form without {0} in CLDR pattern and wide base form",
u"measure-unit/temperature-kelvin .00000000000000000000 unit-width-full-name",
+ u"unit/kelvin .00000000000000000000 unit-width-full-name",
NumberFormatter::with().precision(Precision::fixedFraction(20))
.unit(KELVIN)
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
assertFormatSingle(
u"Person unit not in short form",
u"measure-unit/duration-year-person unit-width-full-name",
+ u"unit/year-person unit-width-full-name",
NumberFormatter::with().unit(MeasureUnit::getYearPerson())
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
Locale("es-MX"),
assertFormatDescending(
u"Meters Per Second Short (unit that simplifies) and perUnit method",
u"measure-unit/length-meter per-measure-unit/duration-second",
+ u"~unit/meter-per-second", // does not round-trip to the full skeleton above
NumberFormatter::with().unit(METER).perUnit(SECOND),
Locale::getEnglish(),
u"87,650 m/s",
assertFormatDescending(
u"Pounds Per Square Mile Short (secondary unit has per-format) and adoptPerUnit method",
u"measure-unit/mass-pound per-measure-unit/area-square-mile",
+ u"unit/pound-per-square-mile",
NumberFormatter::with().unit(POUND).adoptPerUnit(new MeasureUnit(SQUARE_MILE)),
Locale::getEnglish(),
u"87,650 lb/mi²",
assertFormatDescending(
u"Joules Per Furlong Short (unit with no simplifications or special patterns)",
u"measure-unit/energy-joule per-measure-unit/length-furlong",
+ u"unit/joule-per-furlong",
NumberFormatter::with().unit(JOULE).perUnit(FURLONG),
Locale::getEnglish(),
u"87,650 J/fur",
assertFormatDescending(
u"Currency",
u"currency/GBP",
+ u"currency/GBP",
NumberFormatter::with().unit(GBP),
Locale::getEnglish(),
u"£87,650.00",
assertFormatDescending(
u"Currency ISO",
u"currency/GBP unit-width-iso-code",
+ u"currency/GBP unit-width-iso-code",
NumberFormatter::with().unit(GBP).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE),
Locale::getEnglish(),
u"GBP 87,650.00",
assertFormatDescending(
u"Currency Long Name",
u"currency/GBP unit-width-full-name",
+ u"currency/GBP unit-width-full-name",
NumberFormatter::with().unit(GBP).unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
Locale::getEnglish(),
u"87,650.00 British pounds",
assertFormatDescending(
u"Currency Hidden",
u"currency/GBP unit-width-hidden",
+ u"currency/GBP unit-width-hidden",
NumberFormatter::with().unit(GBP).unitWidth(UNUM_UNIT_WIDTH_HIDDEN),
Locale::getEnglish(),
u"87,650.00",
assertFormatSingle(
u"Currency with Negative Sign",
u"currency/GBP",
+ u"currency/GBP",
NumberFormatter::with().unit(GBP),
Locale::getEnglish(),
-9876543.21,
assertFormatSingle(
u"Currency Difference between Narrow and Short (Narrow Version)",
u"currency/USD unit-width-narrow",
+ u"currency/USD unit-width-narrow",
NumberFormatter::with().unit(USD).unitWidth(UNUM_UNIT_WIDTH_NARROW),
Locale("en-CA"),
5.43,
assertFormatSingle(
u"Currency Difference between Narrow and Short (Short Version)",
u"currency/USD unit-width-short",
+ u"currency/USD unit-width-short",
NumberFormatter::with().unit(USD).unitWidth(UNUM_UNIT_WIDTH_SHORT),
Locale("en-CA"),
5.43,
assertFormatSingle(
u"Currency-dependent format (Control)",
u"currency/USD unit-width-short",
+ u"currency/USD unit-width-short",
NumberFormatter::with().unit(USD).unitWidth(UNUM_UNIT_WIDTH_SHORT),
Locale("ca"),
444444.55,
assertFormatSingle(
u"Currency-dependent format (Test)",
u"currency/ESP unit-width-short",
+ u"currency/ESP unit-width-short",
NumberFormatter::with().unit(ESP).unitWidth(UNUM_UNIT_WIDTH_SHORT),
Locale("ca"),
444444.55,
assertFormatSingle(
u"Currency-dependent symbols (Control)",
u"currency/USD unit-width-short",
+ u"currency/USD unit-width-short",
NumberFormatter::with().unit(USD).unitWidth(UNUM_UNIT_WIDTH_SHORT),
Locale("pt-PT"),
444444.55,
assertFormatSingle(
u"Currency-dependent symbols (Test Short)",
u"currency/PTE unit-width-short",
+ u"currency/PTE unit-width-short",
NumberFormatter::with().unit(PTE).unitWidth(UNUM_UNIT_WIDTH_SHORT),
Locale("pt-PT"),
444444.55,
assertFormatSingle(
u"Currency-dependent symbols (Test Narrow)",
u"currency/PTE unit-width-narrow",
+ u"currency/PTE unit-width-narrow",
NumberFormatter::with().unit(PTE).unitWidth(UNUM_UNIT_WIDTH_NARROW),
Locale("pt-PT"),
444444.55,
assertFormatSingle(
u"Currency-dependent symbols (Test ISO Code)",
u"currency/PTE unit-width-iso-code",
+ u"currency/PTE unit-width-iso-code",
NumberFormatter::with().unit(PTE).unitWidth(UNUM_UNIT_WIDTH_ISO_CODE),
Locale("pt-PT"),
444444.55,
assertFormatSingle(
u"Plural form depending on visible digits (ICU-20499)",
u"currency/RON unit-width-full-name",
+ u"currency/RON unit-width-full-name",
NumberFormatter::with().unit(RON).unitWidth(UNUM_UNIT_WIDTH_FULL_NAME),
Locale("ro-RO"),
24,
assertFormatDescending(
u"Percent",
u"percent",
+ u"%",
NumberFormatter::with().unit(NoUnit::percent()),
Locale::getEnglish(),
u"87,650%",
assertFormatDescending(
u"Permille",
u"permille",
+ u"permille",
NumberFormatter::with().unit(NoUnit::permille()),
Locale::getEnglish(),
u"87,650‰",
assertFormatSingle(
u"NoUnit Base",
u"base-unit",
+ u"",
NumberFormatter::with().unit(NoUnit::base()),
Locale::getEnglish(),
51423,
assertFormatSingle(
u"Percent with Negative Sign",
u"percent",
+ u"%",
NumberFormatter::with().unit(NoUnit::percent()),
Locale::getEnglish(),
-98.7654321,
assertFormatDescending(
u"Integer",
u"precision-integer",
+ u".",
NumberFormatter::with().precision(Precision::integer()),
Locale::getEnglish(),
u"87,650",
assertFormatDescending(
u"Fixed Fraction",
u".000",
+ u".000",
NumberFormatter::with().precision(Precision::fixedFraction(3)),
Locale::getEnglish(),
u"87,650.000",
assertFormatDescending(
u"Min Fraction",
u".0+",
+ u".0+",
NumberFormatter::with().precision(Precision::minFraction(1)),
Locale::getEnglish(),
u"87,650.0",
assertFormatDescending(
u"Max Fraction",
u".#",
+ u".#",
NumberFormatter::with().precision(Precision::maxFraction(1)),
Locale::getEnglish(),
u"87,650",
assertFormatDescending(
u"Min/Max Fraction",
u".0##",
+ u".0##",
NumberFormatter::with().precision(Precision::minMaxFraction(1, 3)),
Locale::getEnglish(),
u"87,650.0",
assertFormatSingle(
u"Fixed Significant",
u"@@@",
+ u"@@@",
NumberFormatter::with().precision(Precision::fixedSignificantDigits(3)),
Locale::getEnglish(),
-98,
assertFormatSingle(
u"Fixed Significant Rounding",
u"@@@",
+ u"@@@",
NumberFormatter::with().precision(Precision::fixedSignificantDigits(3)),
Locale::getEnglish(),
-98.7654321,
assertFormatSingle(
u"Fixed Significant Zero",
u"@@@",
+ u"@@@",
NumberFormatter::with().precision(Precision::fixedSignificantDigits(3)),
Locale::getEnglish(),
0,
assertFormatSingle(
u"Min Significant",
u"@@+",
+ u"@@+",
NumberFormatter::with().precision(Precision::minSignificantDigits(2)),
Locale::getEnglish(),
-9,
assertFormatSingle(
u"Max Significant",
u"@###",
+ u"@###",
NumberFormatter::with().precision(Precision::maxSignificantDigits(4)),
Locale::getEnglish(),
98.7654321,
assertFormatSingle(
u"Min/Max Significant",
u"@@@#",
+ u"@@@#",
NumberFormatter::with().precision(Precision::minMaxSignificantDigits(3, 4)),
Locale::getEnglish(),
9.99999,
assertFormatSingle(
u"Fixed Significant on zero with lots of integer width",
u"@ integer-width/+000",
+ u"@ 000",
NumberFormatter::with().precision(Precision::fixedSignificantDigits(1))
.integerWidth(IntegerWidth::zeroFillTo(3)),
Locale::getEnglish(),
assertFormatSingle(
u"Fixed Significant on zero with zero integer width",
u"@ integer-width/+",
+ u"@ integer-width/+",
NumberFormatter::with().precision(Precision::fixedSignificantDigits(1))
.integerWidth(IntegerWidth::zeroFillTo(0)),
Locale::getEnglish(),
assertFormatDescending(
u"Basic Significant", // for comparison
u"@#",
+ u"@#",
NumberFormatter::with().precision(Precision::maxSignificantDigits(2)),
Locale::getEnglish(),
u"88,000",
assertFormatDescending(
u"FracSig minMaxFrac minSig",
u".0#/@@@+",
+ u".0#/@@@+",
NumberFormatter::with().precision(Precision::minMaxFraction(1, 2).withMinDigits(3)),
Locale::getEnglish(),
u"87,650.0",
assertFormatDescending(
u"FracSig minMaxFrac maxSig A",
u".0##/@#",
+ u".0##/@#",
NumberFormatter::with().precision(Precision::minMaxFraction(1, 3).withMaxDigits(2)),
Locale::getEnglish(),
u"88,000.0", // maxSig beats maxFrac
assertFormatDescending(
u"FracSig minMaxFrac maxSig B",
u".00/@#",
+ u".00/@#",
NumberFormatter::with().precision(Precision::fixedFraction(2).withMaxDigits(2)),
Locale::getEnglish(),
u"88,000.00", // maxSig beats maxFrac
assertFormatSingle(
u"FracSig with trailing zeros A",
u".00/@@@+",
+ u".00/@@@+",
NumberFormatter::with().precision(Precision::fixedFraction(2).withMinDigits(3)),
Locale::getEnglish(),
0.1,
assertFormatSingle(
u"FracSig with trailing zeros B",
u".00/@@@+",
+ u".00/@@@+",
NumberFormatter::with().precision(Precision::fixedFraction(2).withMinDigits(3)),
Locale::getEnglish(),
0.0999999,
assertFormatDescending(
u"Rounding None",
u"precision-unlimited",
+ u".+",
NumberFormatter::with().precision(Precision::unlimited()),
Locale::getEnglish(),
u"87,650",
assertFormatDescending(
u"Increment",
u"precision-increment/0.5",
+ u"precision-increment/0.5",
NumberFormatter::with().precision(Precision::increment(0.5).withMinFraction(1)),
Locale::getEnglish(),
u"87,650.0",
assertFormatDescending(
u"Increment with Min Fraction",
u"precision-increment/0.50",
+ u"precision-increment/0.50",
NumberFormatter::with().precision(Precision::increment(0.5).withMinFraction(2)),
Locale::getEnglish(),
u"87,650.00",
assertFormatDescending(
u"Strange Increment",
u"precision-increment/3.140",
+ u"precision-increment/3.140",
NumberFormatter::with().precision(Precision::increment(3.14).withMinFraction(3)),
Locale::getEnglish(),
u"87,649.960",
assertFormatDescending(
u"Increment Resolving to Power of 10",
u"precision-increment/0.010",
+ u"precision-increment/0.010",
NumberFormatter::with().precision(Precision::increment(0.01).withMinFraction(3)),
Locale::getEnglish(),
u"87,650.000",
assertFormatDescending(
u"Currency Standard",
u"currency/CZK precision-currency-standard",
+ u"currency/CZK precision-currency-standard",
NumberFormatter::with().precision(Precision::currency(UCurrencyUsage::UCURR_USAGE_STANDARD))
.unit(CZK),
Locale::getEnglish(),
assertFormatDescending(
u"Currency Cash",
u"currency/CZK precision-currency-cash",
+ u"currency/CZK precision-currency-cash",
NumberFormatter::with().precision(Precision::currency(UCurrencyUsage::UCURR_USAGE_CASH))
.unit(CZK),
Locale::getEnglish(),
assertFormatDescending(
u"Currency Cash with Nickel Rounding",
u"currency/CAD precision-currency-cash",
+ u"currency/CAD precision-currency-cash",
NumberFormatter::with().precision(Precision::currency(UCurrencyUsage::UCURR_USAGE_CASH))
.unit(CAD),
Locale::getEnglish(),
assertFormatDescending(
u"Currency not in top-level fluent chain",
u"precision-integer", // calling .withCurrency() applies currency rounding rules immediately
+ u".",
NumberFormatter::with().precision(
Precision::currency(UCurrencyUsage::UCURR_USAGE_CASH).withCurrency(CZK)),
Locale::getEnglish(),
assertFormatDescending(
u"Rounding Mode CEILING",
u"precision-integer rounding-mode-ceiling",
+ u". rounding-mode-ceiling",
NumberFormatter::with().precision(Precision::integer()).roundingMode(UNUM_ROUND_CEILING),
Locale::getEnglish(),
u"87,650",
assertFormatDescendingBig(
u"Western Grouping",
u"group-auto",
+ u"",
NumberFormatter::with().grouping(UNUM_GROUPING_AUTO),
Locale::getEnglish(),
u"87,650,000",
assertFormatDescendingBig(
u"Indic Grouping",
u"group-auto",
+ u"",
NumberFormatter::with().grouping(UNUM_GROUPING_AUTO),
Locale("en-IN"),
u"8,76,50,000",
assertFormatDescendingBig(
u"Western Grouping, Min 2",
u"group-min2",
+ u",?",
NumberFormatter::with().grouping(UNUM_GROUPING_MIN2),
Locale::getEnglish(),
u"87,650,000",
assertFormatDescendingBig(
u"Indic Grouping, Min 2",
u"group-min2",
+ u",?",
NumberFormatter::with().grouping(UNUM_GROUPING_MIN2),
Locale("en-IN"),
u"8,76,50,000",
assertFormatDescendingBig(
u"No Grouping",
u"group-off",
+ u",_",
NumberFormatter::with().grouping(UNUM_GROUPING_OFF),
Locale("en-IN"),
u"87650000",
assertFormatDescendingBig(
u"Indic locale with THOUSANDS grouping",
u"group-thousands",
+ u"group-thousands",
NumberFormatter::with().grouping(UNUM_GROUPING_THOUSANDS),
Locale("en-IN"),
u"87,650,000",
assertFormatDescendingBig(
u"Polish Grouping",
u"group-auto",
+ u"",
NumberFormatter::with().grouping(UNUM_GROUPING_AUTO),
Locale("pl"),
u"87 650 000",
assertFormatDescendingBig(
u"Polish Grouping, Min 2",
u"group-min2",
+ u",?",
NumberFormatter::with().grouping(UNUM_GROUPING_MIN2),
Locale("pl"),
u"87 650 000",
assertFormatDescendingBig(
u"Polish Grouping, Always",
u"group-on-aligned",
+ u",!",
NumberFormatter::with().grouping(UNUM_GROUPING_ON_ALIGNED),
Locale("pl"),
u"87 650 000",
assertFormatDescendingBig(
u"Bulgarian Currency Grouping",
u"currency/USD group-auto",
+ u"currency/USD",
NumberFormatter::with().grouping(UNUM_GROUPING_AUTO).unit(USD),
Locale("bg"),
u"87650000,00 щ.д.",
assertFormatDescendingBig(
u"Bulgarian Currency Grouping, Always",
u"currency/USD group-on-aligned",
+ u"currency/USD ,!",
NumberFormatter::with().grouping(UNUM_GROUPING_ON_ALIGNED).unit(USD),
Locale("bg"),
u"87 650 000,00 щ.д.",
assertFormatDescendingBig(
u"Custom Grouping via Internal API",
nullptr,
+ nullptr,
NumberFormatter::with().macros(macros),
Locale::getEnglish(),
u"8,7,6,5,0000",
assertFormatDescending(
u"Padding",
nullptr,
+ nullptr,
NumberFormatter::with().padding(Padder::none()),
Locale::getEnglish(),
u"87,650",
assertFormatDescending(
u"Padding",
nullptr,
+ nullptr,
NumberFormatter::with().padding(
Padder::codePoints(
'*', 8, PadPosition::UNUM_PAD_AFTER_PREFIX)),
assertFormatDescending(
u"Padding with code points",
nullptr,
+ nullptr,
NumberFormatter::with().padding(
Padder::codePoints(
0x101E4, 8, PadPosition::UNUM_PAD_AFTER_PREFIX)),
assertFormatDescending(
u"Padding with wide digits",
nullptr,
+ nullptr,
NumberFormatter::with().padding(
Padder::codePoints(
'*', 8, PadPosition::UNUM_PAD_AFTER_PREFIX))
assertFormatDescending(
u"Padding with currency spacing",
nullptr,
+ nullptr,
NumberFormatter::with().padding(
Padder::codePoints(
'*', 10, PadPosition::UNUM_PAD_AFTER_PREFIX))
assertFormatSingle(
u"Pad Before Prefix",
nullptr,
+ nullptr,
NumberFormatter::with().padding(
Padder::codePoints(
'*', 8, PadPosition::UNUM_PAD_BEFORE_PREFIX)),
assertFormatSingle(
u"Pad After Prefix",
nullptr,
+ nullptr,
NumberFormatter::with().padding(
Padder::codePoints(
'*', 8, PadPosition::UNUM_PAD_AFTER_PREFIX)),
assertFormatSingle(
u"Pad Before Suffix",
nullptr,
+ nullptr,
NumberFormatter::with().padding(
Padder::codePoints(
'*', 8, PadPosition::UNUM_PAD_BEFORE_SUFFIX)).unit(NoUnit::percent()),
assertFormatSingle(
u"Pad After Suffix",
nullptr,
+ nullptr,
NumberFormatter::with().padding(
Padder::codePoints(
'*', 8, PadPosition::UNUM_PAD_AFTER_SUFFIX)).unit(NoUnit::percent()),
assertFormatSingle(
u"Currency Spacing with Zero Digit Padding Broken",
nullptr,
+ nullptr,
NumberFormatter::with().padding(
Padder::codePoints(
'0', 12, PadPosition::UNUM_PAD_AFTER_PREFIX))
assertFormatDescending(
u"Integer Width Default",
u"integer-width/+0",
+ u"0",
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(1)),
Locale::getEnglish(),
u"87,650",
assertFormatDescending(
u"Integer Width Zero Fill 0",
u"integer-width/+",
+ u"integer-width/+",
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(0)),
Locale::getEnglish(),
u"87,650",
assertFormatDescending(
u"Integer Width Zero Fill 3",
u"integer-width/+000",
+ u"000",
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(3)),
Locale::getEnglish(),
u"87,650",
assertFormatDescending(
u"Integer Width Max 3",
u"integer-width/##0",
+ u"integer-width/##0",
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(1).truncateAt(3)),
Locale::getEnglish(),
u"650",
assertFormatDescending(
u"Integer Width Fixed 2",
u"integer-width/00",
+ u"integer-width/00",
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(2).truncateAt(2)),
Locale::getEnglish(),
u"50",
assertFormatDescending(
u"Integer Width Compact",
u"compact-short integer-width/000",
+ u"compact-short integer-width/000",
NumberFormatter::with()
.notation(Notation::compactShort())
.integerWidth(IntegerWidth::zeroFillTo(3).truncateAt(3)),
assertFormatDescending(
u"Integer Width Scientific",
u"scientific integer-width/000",
+ u"scientific integer-width/000",
NumberFormatter::with()
.notation(Notation::scientific())
.integerWidth(IntegerWidth::zeroFillTo(3).truncateAt(3)),
assertFormatDescending(
u"Integer Width Engineering",
u"engineering integer-width/000",
+ u"engineering integer-width/000",
NumberFormatter::with()
.notation(Notation::engineering())
.integerWidth(IntegerWidth::zeroFillTo(3).truncateAt(3)),
assertFormatSingle(
u"Integer Width Remove All A",
u"integer-width/00",
+ u"integer-width/00",
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(2).truncateAt(2)),
"en",
2500,
assertFormatSingle(
u"Integer Width Remove All B",
u"integer-width/00",
+ u"integer-width/00",
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(2).truncateAt(2)),
"en",
25000,
assertFormatSingle(
u"Integer Width Remove All B, Bytes Mode",
u"integer-width/00",
+ u"integer-width/00",
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(2).truncateAt(2)),
"en",
// Note: this double produces all 17 significant digits
assertFormatDescending(
u"French Symbols with Japanese Data 1",
nullptr,
+ nullptr,
NumberFormatter::with().symbols(FRENCH_SYMBOLS),
Locale::getJapan(),
u"87\u202F650",
assertFormatSingle(
u"French Symbols with Japanese Data 2",
nullptr,
+ nullptr,
NumberFormatter::with().notation(Notation::compactShort()).symbols(FRENCH_SYMBOLS),
Locale::getJapan(),
12345,
assertFormatDescending(
u"Latin Numbering System with Arabic Data",
u"currency/USD latin",
+ u"currency/USD latin",
NumberFormatter::with().adoptSymbols(new NumberingSystem(LATN)).unit(USD),
Locale("ar"),
u"US$ 87,650.00",
assertFormatDescending(
u"Math Numbering System with French Data",
u"numbering-system/mathsanb",
+ u"numbering-system/mathsanb",
NumberFormatter::with().adoptSymbols(new NumberingSystem(MATHSANB)),
Locale::getFrench(),
u"𝟴𝟳\u202F𝟲𝟱𝟬",
assertFormatSingle(
u"Swiss Symbols (used in documentation)",
nullptr,
+ nullptr,
NumberFormatter::with().symbols(SWISS_SYMBOLS),
Locale::getEnglish(),
12345.67,
assertFormatSingle(
u"Myanmar Symbols (used in documentation)",
nullptr,
+ nullptr,
NumberFormatter::with().symbols(MYANMAR_SYMBOLS),
Locale::getEnglish(),
12345.67,
assertFormatSingle(
u"Currency symbol should precede number in ar with NS latn",
u"currency/USD latin",
+ u"currency/USD latin",
NumberFormatter::with().adoptSymbols(new NumberingSystem(LATN)).unit(USD),
Locale("ar"),
12345.67,
assertFormatSingle(
u"Currency symbol should precede number in ar@numbers=latn",
u"currency/USD",
+ u"currency/USD",
NumberFormatter::with().unit(USD),
Locale("ar@numbers=latn"),
12345.67,
assertFormatSingle(
u"Currency symbol should follow number in ar-EG with NS arab",
u"currency/USD",
+ u"currency/USD",
NumberFormatter::with().unit(USD),
Locale("ar-EG"),
12345.67,
assertFormatSingle(
u"Currency symbol should follow number in ar@numbers=arab",
u"currency/USD",
+ u"currency/USD",
NumberFormatter::with().unit(USD),
Locale("ar@numbers=arab"),
12345.67,
assertFormatSingle(
u"NumberingSystem in API should win over @numbers keyword",
u"currency/USD latin",
+ u"currency/USD latin",
NumberFormatter::with().adoptSymbols(new NumberingSystem(LATN)).unit(USD),
Locale("ar@numbers=arab"),
12345.67,
UnlocalizedNumberFormatter f = NumberFormatter::with().symbols(symbols);
symbols.setSymbol(DecimalFormatSymbols::ENumberFormatSymbol::kGroupingSeparatorSymbol, u"!", status);
assertFormatSingle(
- u"Symbols object should be copied", nullptr, f, Locale::getEnglish(), 12345.67, u"12’345.67");
+ u"Symbols object should be copied",
+ nullptr,
+ nullptr,
+ f,
+ Locale::getEnglish(),
+ 12345.67,
+ u"12’345.67");
assertFormatSingle(
u"The last symbols setter wins",
u"latin",
+ u"latin",
NumberFormatter::with().symbols(symbols).adoptSymbols(new NumberingSystem(LATN)),
Locale::getEnglish(),
12345.67,
assertFormatSingle(
u"The last symbols setter wins",
nullptr,
+ nullptr,
NumberFormatter::with().adoptSymbols(new NumberingSystem(LATN)).symbols(symbols),
Locale::getEnglish(),
12345.67,
assertFormatSingle(
u"Sign Auto Positive",
u"sign-auto",
+ u"",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_AUTO),
Locale::getEnglish(),
444444,
assertFormatSingle(
u"Sign Auto Negative",
u"sign-auto",
+ u"",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_AUTO),
Locale::getEnglish(),
-444444,
assertFormatSingle(
u"Sign Auto Zero",
u"sign-auto",
+ u"",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_AUTO),
Locale::getEnglish(),
0,
assertFormatSingle(
u"Sign Always Positive",
u"sign-always",
+ u"+!",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ALWAYS),
Locale::getEnglish(),
444444,
assertFormatSingle(
u"Sign Always Negative",
u"sign-always",
+ u"+!",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ALWAYS),
Locale::getEnglish(),
-444444,
assertFormatSingle(
u"Sign Always Zero",
u"sign-always",
+ u"+!",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ALWAYS),
Locale::getEnglish(),
0,
assertFormatSingle(
u"Sign Never Positive",
u"sign-never",
+ u"+_",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_NEVER),
Locale::getEnglish(),
444444,
assertFormatSingle(
u"Sign Never Negative",
u"sign-never",
+ u"+_",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_NEVER),
Locale::getEnglish(),
-444444,
assertFormatSingle(
u"Sign Never Zero",
u"sign-never",
+ u"+_",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_NEVER),
Locale::getEnglish(),
0,
assertFormatSingle(
u"Sign Accounting Positive",
u"currency/USD sign-accounting",
+ u"currency/USD ()",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING).unit(USD),
Locale::getEnglish(),
444444,
assertFormatSingle(
u"Sign Accounting Negative",
u"currency/USD sign-accounting",
+ u"currency/USD ()",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING).unit(USD),
Locale::getEnglish(),
-444444,
assertFormatSingle(
u"Sign Accounting Zero",
u"currency/USD sign-accounting",
+ u"currency/USD ()",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING).unit(USD),
Locale::getEnglish(),
0,
assertFormatSingle(
u"Sign Accounting-Always Positive",
u"currency/USD sign-accounting-always",
+ u"currency/USD ()!",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_ALWAYS).unit(USD),
Locale::getEnglish(),
444444,
assertFormatSingle(
u"Sign Accounting-Always Negative",
u"currency/USD sign-accounting-always",
+ u"currency/USD ()!",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_ALWAYS).unit(USD),
Locale::getEnglish(),
-444444,
assertFormatSingle(
u"Sign Accounting-Always Zero",
u"currency/USD sign-accounting-always",
+ u"currency/USD ()!",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_ALWAYS).unit(USD),
Locale::getEnglish(),
0,
assertFormatSingle(
u"Sign Except-Zero Positive",
u"sign-except-zero",
+ u"+?",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_EXCEPT_ZERO),
Locale::getEnglish(),
444444,
assertFormatSingle(
u"Sign Except-Zero Negative",
u"sign-except-zero",
+ u"+?",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_EXCEPT_ZERO),
Locale::getEnglish(),
-444444,
assertFormatSingle(
u"Sign Except-Zero Zero",
u"sign-except-zero",
+ u"+?",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_EXCEPT_ZERO),
Locale::getEnglish(),
0,
assertFormatSingle(
u"Sign Accounting-Except-Zero Positive",
u"currency/USD sign-accounting-except-zero",
+ u"currency/USD ()?",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO).unit(USD),
Locale::getEnglish(),
444444,
assertFormatSingle(
u"Sign Accounting-Except-Zero Negative",
u"currency/USD sign-accounting-except-zero",
+ u"currency/USD ()?",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO).unit(USD),
Locale::getEnglish(),
-444444,
assertFormatSingle(
u"Sign Accounting-Except-Zero Zero",
u"currency/USD sign-accounting-except-zero",
+ u"currency/USD ()?",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO).unit(USD),
Locale::getEnglish(),
0,
assertFormatSingle(
u"Sign Accounting Negative Hidden",
u"currency/USD unit-width-hidden sign-accounting",
+ u"currency/USD unit-width-hidden ()",
NumberFormatter::with()
.sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING)
.unit(USD)
assertFormatSingle(
u"Sign Accounting Negative Narrow",
u"currency/USD unit-width-narrow sign-accounting",
+ u"currency/USD unit-width-narrow ()",
NumberFormatter::with()
.sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING)
.unit(USD)
assertFormatSingle(
u"Sign Accounting Negative Short",
u"currency/USD sign-accounting",
+ u"currency/USD ()",
NumberFormatter::with()
.sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING)
.unit(USD)
assertFormatSingle(
u"Sign Accounting Negative Iso Code",
u"currency/USD unit-width-iso-code sign-accounting",
+ u"currency/USD unit-width-iso-code ()",
NumberFormatter::with()
.sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING)
.unit(USD)
assertFormatSingle(
u"Sign Accounting Negative Full Name",
u"currency/USD unit-width-full-name sign-accounting",
+ u"currency/USD unit-width-full-name ()",
NumberFormatter::with()
.sign(UNumberSignDisplay::UNUM_SIGN_ACCOUNTING)
.unit(USD)
assertFormatDescending(
u"Decimal Default",
u"decimal-auto",
+ u"",
NumberFormatter::with().decimal(UNumberDecimalSeparatorDisplay::UNUM_DECIMAL_SEPARATOR_AUTO),
Locale::getEnglish(),
u"87,650",
assertFormatDescending(
u"Decimal Always Shown",
u"decimal-always",
+ u"decimal-always",
NumberFormatter::with().decimal(UNumberDecimalSeparatorDisplay::UNUM_DECIMAL_SEPARATOR_ALWAYS),
Locale::getEnglish(),
u"87,650.",
assertFormatDescending(
u"Multiplier None",
u"scale/1",
+ u"",
NumberFormatter::with().scale(Scale::none()),
Locale::getEnglish(),
u"87,650",
assertFormatDescending(
u"Multiplier Power of Ten",
u"scale/1000000",
+ u"scale/1E6",
NumberFormatter::with().scale(Scale::powerOfTen(6)),
Locale::getEnglish(),
u"87,650,000,000",
assertFormatDescending(
u"Multiplier Arbitrary Double",
u"scale/5.2",
+ u"scale/5.2",
NumberFormatter::with().scale(Scale::byDouble(5.2)),
Locale::getEnglish(),
u"455,780",
assertFormatDescending(
u"Multiplier Arbitrary BigDecimal",
u"scale/5.2",
+ u"scale/5.2",
NumberFormatter::with().scale(Scale::byDecimal({"5.2", -1})),
Locale::getEnglish(),
u"455,780",
assertFormatDescending(
u"Multiplier Arbitrary Double And Power Of Ten",
u"scale/5200",
+ u"scale/5200",
NumberFormatter::with().scale(Scale::byDoubleAndPowerOfTen(5.2, 3)),
Locale::getEnglish(),
u"455,780,000",
assertFormatDescending(
u"Multiplier Zero",
u"scale/0",
+ u"scale/0",
NumberFormatter::with().scale(Scale::byDouble(0)),
Locale::getEnglish(),
u"0",
assertFormatSingle(
u"Multiplier Skeleton Scientific Notation and Percent",
u"percent scale/1E2",
+ u"%x100",
NumberFormatter::with().unit(NoUnit::percent()).scale(Scale::powerOfTen(2)),
Locale::getEnglish(),
0.5,
assertFormatSingle(
u"Negative Multiplier",
u"scale/-5.2",
+ u"scale/-5.2",
NumberFormatter::with().scale(Scale::byDouble(-5.2)),
Locale::getEnglish(),
2,
assertFormatSingle(
u"Negative One Multiplier",
u"scale/-1",
+ u"scale/-1",
NumberFormatter::with().scale(Scale::byDouble(-1)),
Locale::getEnglish(),
444444,
assertFormatSingle(
u"Two-Type Multiplier with Overlap",
u"scale/10000",
+ u"scale/1E4",
NumberFormatter::with().scale(Scale::byDoubleAndPowerOfTen(100, 2)),
Locale::getEnglish(),
2,
// Test the skeleton examples in userguide/format_parse/numbers/skeletons.md
struct TestCase {
const char16_t* skeleton;
+ const char16_t* conciseSkeleton;
double input;
const char16_t* expected;
} cases[] = {
- {u"percent", 25, u"25%"},
- {u".00", 25, u"25.00"},
- {u"percent .00", 25, u"25.00%"},
- {u"scale/100", 0.3, u"30"},
- {u"percent scale/100", 0.3, u"30%"},
- {u"measure-unit/length-meter", 5, u"5 m"},
- {u"measure-unit/length-meter unit-width-full-name", 5, u"5 meters"},
- {u"currency/CAD", 10, u"CA$10.00"},
- {u"currency/CAD unit-width-narrow", 10, u"$10.00"},
- {u"compact-short", 5000, u"5K"},
- {u"compact-long", 5000, u"5 thousand"},
- {u"compact-short currency/CAD", 5000, u"CA$5K"},
- {u"", 5000, u"5,000"},
- {u"group-min2", 5000, u"5000"},
- {u"group-min2", 15000, u"15,000"},
- {u"sign-always", 60, u"+60"},
- {u"sign-always", 0, u"+0"},
- {u"sign-except-zero", 60, u"+60"},
- {u"sign-except-zero", 0, u"0"},
- {u"sign-accounting currency/CAD", -40, u"(CA$40.00)"}
+ {u"percent", u"%", 25, u"25%"},
+ {u".00", u".00", 25, u"25.00"},
+ {u"percent .00", u"% .00", 25, u"25.00%"},
+ {u"scale/100", u"scale/100", 0.3, u"30"},
+ {u"percent scale/100", u"%x100", 0.3, u"30%"},
+ {u"measure-unit/length-meter", u"unit/meter", 5, u"5 m"},
+ {u"measure-unit/length-meter unit-width-full-name", u"unit/meter unit-width-full-name", 5, u"5 meters"},
+ {u"currency/CAD", u"currency/CAD", 10, u"CA$10.00"},
+ {u"currency/CAD unit-width-narrow", u"currency/CAD unit-width-narrow", 10, u"$10.00"},
+ {u"compact-short", u"K", 5000, u"5K"},
+ {u"compact-long", u"KK", 5000, u"5 thousand"},
+ {u"compact-short currency/CAD", u"K currency/CAD", 5000, u"CA$5K"},
+ {u"", u"", 5000, u"5,000"},
+ {u"group-min2", u",?", 5000, u"5000"},
+ {u"group-min2", u",?", 15000, u"15,000"},
+ {u"sign-always", u"+!", 60, u"+60"},
+ {u"sign-always", u"+!", 0, u"+0"},
+ {u"sign-except-zero", u"+?", 60, u"+60"},
+ {u"sign-except-zero", u"+?", 0, u"0"},
+ {u"sign-accounting currency/CAD", u"() currency/CAD", -40, u"(CA$40.00)"}
};
for (const auto& cas : cases) {
.formatDouble(cas.input, status);
assertEquals(cas.skeleton, cas.expected, actual.toTempString(status));
status.errIfFailureAndReset();
+ FormattedNumber actualConcise = NumberFormatter::forSkeleton(cas.conciseSkeleton, status)
+ .locale("en-US")
+ .formatDouble(cas.input, status);
+ assertEquals(cas.conciseSkeleton, cas.expected, actualConcise.toTempString(status));
+ status.errIfFailureAndReset();
}
}
FormattedNumber fmtd = assertFormatSingle(
message,
u"",
+ u"",
NumberFormatter::with(),
Locale::getEnglish(),
-9876543210.12,
FormattedNumber result = assertFormatSingle(
message,
u"measure-unit/temperature-fahrenheit",
+ u"unit/fahrenheit",
NumberFormatter::with().unit(FAHRENHEIT),
Locale::getEnglish(),
68,
FormattedNumber result = assertFormatSingle(
message,
u"measure-unit/temperature-fahrenheit per-measure-unit/duration-day",
+ u"unit/fahrenheit-per-day",
NumberFormatter::with().unit(FAHRENHEIT).perUnit(DAY),
Locale::getEnglish(),
68,
FormattedNumber result = assertFormatSingle(
message,
u"measure-unit/length-meter unit-width-full-name",
+ u"unit/meter unit-width-full-name",
NumberFormatter::with().unit(METER).unitWidth(UNUM_UNIT_WIDTH_FULL_NAME),
Locale::getEnglish(),
68,
FormattedNumber result = assertFormatSingle(
message,
u"measure-unit/length-meter per-measure-unit/duration-second unit-width-full-name",
+ u"~unit/meter-per-second unit-width-full-name", // does not round-trip to the full skeleton above
NumberFormatter::with().unit(METER).perUnit(SECOND).unitWidth(UNUM_UNIT_WIDTH_FULL_NAME),
"ky", // locale with the interesting data
68,
FormattedNumber result = assertFormatSingle(
message,
u"measure-unit/temperature-fahrenheit unit-width-full-name",
+ u"unit/fahrenheit unit-width-full-name",
NumberFormatter::with().unit(FAHRENHEIT).unitWidth(UNUM_UNIT_WIDTH_FULL_NAME),
"vi", // locale with the interesting data
68,
FormattedNumber result = assertFormatSingle(
message,
u"measure-unit/temperature-kelvin",
+ u"unit/kelvin",
NumberFormatter::with().unit(KELVIN),
"fa", // locale with the interesting data
68,
FormattedNumber result = assertFormatSingle(
message,
u"compact-short",
+ u"K",
NumberFormatter::with().notation(Notation::compactShort()),
Locale::getUS(),
65000,
FormattedNumber result = assertFormatSingle(
message,
u"compact-long",
+ u"KK",
NumberFormatter::with().notation(Notation::compactLong()),
Locale::getUS(),
65000,
FormattedNumber result = assertFormatSingle(
message,
u"compact-long",
+ u"KK",
NumberFormatter::with().notation(Notation::compactLong()),
"fil", // locale with interesting data
6000,
FormattedNumber result = assertFormatSingle(
message,
u"compact-long",
+ u"KK",
NumberFormatter::with().notation(Notation::compactLong()),
"he", // locale with interesting data
6000,
FormattedNumber result = assertFormatSingle(
message,
u"compact-short currency/USD",
+ u"K currency/USD",
NumberFormatter::with().notation(Notation::compactShort()).unit(USD),
"sr_Latn", // locale with interesting data
65000,
FormattedNumber result = assertFormatSingle(
message,
u"currency/USD unit-width-full-name",
+ u"currency/USD unit-width-full-name",
NumberFormatter::with().unit(USD)
.unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME),
"en",
FormattedNumber result = assertFormatSingle(
message,
u"compact-long measure-unit/length-meter unit-width-full-name",
+ u"KK unit/meter unit-width-full-name",
NumberFormatter::with().notation(Notation::compactLong())
.unit(METER)
.unitWidth(UNUM_UNIT_WIDTH_FULL_NAME),
}
-void NumberFormatterApiTest::assertFormatDescending(const char16_t* umessage, const char16_t* uskeleton,
- const UnlocalizedNumberFormatter& f, Locale locale,
- ...) {
+void NumberFormatterApiTest::assertFormatDescending(
+ const char16_t* umessage,
+ const char16_t* uskeleton,
+ const char16_t* conciseSkeleton,
+ const UnlocalizedNumberFormatter& f,
+ Locale locale,
+ ...) {
va_list args;
va_start(args, locale);
UnicodeString message(TRUE, umessage, -1);
UnicodeString actual3 = l3.formatDouble(d, status).toString(status);
assertEquals(message + ": Skeleton Path: '" + normalized + "': " + d, expecteds[i], actual3);
}
+ // Concise skeletons should have same output, and usually round-trip to the normalized skeleton.
+ // If the concise skeleton starts with '~', disable the round-trip check.
+ bool shouldRoundTrip = true;
+ if (conciseSkeleton[0] == u'~') {
+ conciseSkeleton++;
+ shouldRoundTrip = false;
+ }
+ LocalizedNumberFormatter l4 = NumberFormatter::forSkeleton(conciseSkeleton, status).locale(locale);
+ if (shouldRoundTrip) {
+ assertEquals(message + ": Concise Skeleton:", normalized, l4.toSkeleton(status));
+ }
+ for (int32_t i = 0; i < 9; i++) {
+ double d = inputs[i];
+ UnicodeString actual4 = l4.formatDouble(d, status).toString(status);
+ assertEquals(message + ": Concise Skeleton Path: '" + normalized + "': " + d, expecteds[i], actual4);
+ }
} else {
assertUndefinedSkeleton(f);
}
}
-void NumberFormatterApiTest::assertFormatDescendingBig(const char16_t* umessage, const char16_t* uskeleton,
- const UnlocalizedNumberFormatter& f, Locale locale,
- ...) {
+void NumberFormatterApiTest::assertFormatDescendingBig(
+ const char16_t* umessage,
+ const char16_t* uskeleton,
+ const char16_t* conciseSkeleton,
+ const UnlocalizedNumberFormatter& f,
+ Locale locale,
+ ...) {
va_list args;
va_start(args, locale);
UnicodeString message(TRUE, umessage, -1);
UnicodeString actual3 = l3.formatDouble(d, status).toString(status);
assertEquals(message + ": Skeleton Path: '" + normalized + "': " + d, expecteds[i], actual3);
}
+ // Concise skeletons should have same output, and usually round-trip to the normalized skeleton.
+ // If the concise skeleton starts with '~', disable the round-trip check.
+ bool shouldRoundTrip = true;
+ if (conciseSkeleton[0] == u'~') {
+ conciseSkeleton++;
+ shouldRoundTrip = false;
+ }
+ LocalizedNumberFormatter l4 = NumberFormatter::forSkeleton(conciseSkeleton, status).locale(locale);
+ if (shouldRoundTrip) {
+ assertEquals(message + ": Concise Skeleton:", normalized, l4.toSkeleton(status));
+ }
+ for (int32_t i = 0; i < 9; i++) {
+ double d = inputs[i];
+ UnicodeString actual4 = l4.formatDouble(d, status).toString(status);
+ assertEquals(message + ": Concise Skeleton Path: '" + normalized + "': " + d, expecteds[i], actual4);
+ }
} else {
assertUndefinedSkeleton(f);
}
}
FormattedNumber
-NumberFormatterApiTest::assertFormatSingle(const char16_t* umessage, const char16_t* uskeleton,
- const UnlocalizedNumberFormatter& f, Locale locale,
- double input, const UnicodeString& expected) {
+NumberFormatterApiTest::assertFormatSingle(
+ const char16_t* umessage,
+ const char16_t* uskeleton,
+ const char16_t* conciseSkeleton,
+ const UnlocalizedNumberFormatter& f,
+ Locale locale,
+ double input,
+ const UnicodeString& expected) {
UnicodeString message(TRUE, umessage, -1);
const LocalizedNumberFormatter l1 = f.threshold(0).locale(locale); // no self-regulation
const LocalizedNumberFormatter l2 = f.threshold(1).locale(locale); // all self-regulation
LocalizedNumberFormatter l3 = NumberFormatter::forSkeleton(normalized, status).locale(locale);
UnicodeString actual3 = l3.formatDouble(input, status).toString(status);
assertEquals(message + ": Skeleton Path: '" + normalized + "': " + input, expected, actual3);
+ // Concise skeletons should have same output, and usually round-trip to the normalized skeleton.
+ // If the concise skeleton starts with '~', disable the round-trip check.
+ bool shouldRoundTrip = true;
+ if (conciseSkeleton[0] == u'~') {
+ conciseSkeleton++;
+ shouldRoundTrip = false;
+ }
+ LocalizedNumberFormatter l4 = NumberFormatter::forSkeleton(conciseSkeleton, status).locale(locale);
+ if (shouldRoundTrip) {
+ assertEquals(message + ": Concise Skeleton:", normalized, l4.toSkeleton(status));
+ }
+ UnicodeString actual4 = l4.formatDouble(input, status).toString(status);
+ assertEquals(message + ": Concise Skeleton Path: '" + normalized + "': " + input, expected, actual4);
} else {
assertUndefinedSkeleton(f);
}
}
void NumberFormatterApiTest::assertNumberFieldPositions(
- const char16_t* message, const FormattedNumber& formattedNumber,
- const UFieldPosition* expectedFieldPositions, int32_t length) {
+ const char16_t* message,
+ const FormattedNumber& formattedNumber,
+ const UFieldPosition* expectedFieldPositions,
+ int32_t length) {
IcuTestErrorCode status(*this, "assertNumberFieldPositions");
// Check FormattedValue functions