mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 15:42:14 +00:00
parent
75874eb0eb
commit
b1a685a676
3 changed files with 92 additions and 0 deletions
|
@ -1719,6 +1719,43 @@ void NumberFormatterApiTest::unitUsage() {
|
|||
30500,
|
||||
u"350 m");
|
||||
|
||||
// Test calling `.usage("")` should unset the existing usage.
|
||||
// First: without usage
|
||||
assertFormatSingle(u"Rounding Mode propagates: rounding up",
|
||||
u"measure-unit/length-centimeter rounding-mode-ceiling",
|
||||
u"unit/centimeter rounding-mode-ceiling",
|
||||
NumberFormatter::with()
|
||||
.unit(MeasureUnit::forIdentifier("centimeter", status))
|
||||
.roundingMode(UNUM_ROUND_CEILING),
|
||||
Locale("en-US"), //
|
||||
3048, //
|
||||
u"3,048 cm");
|
||||
|
||||
// Second: with "road" usage
|
||||
assertFormatSingle(u"Rounding Mode propagates: rounding up",
|
||||
u"usage/road measure-unit/length-centimeter rounding-mode-ceiling",
|
||||
u"usage/road unit/centimeter rounding-mode-ceiling",
|
||||
NumberFormatter::with()
|
||||
.unit(MeasureUnit::forIdentifier("centimeter", status))
|
||||
.usage("road")
|
||||
.roundingMode(UNUM_ROUND_CEILING),
|
||||
Locale("en-US"), //
|
||||
3048, //
|
||||
u"100 ft");
|
||||
|
||||
// Third: with "road" usage, then the usage unsetted by calling .usage("")
|
||||
assertFormatSingle(u"Rounding Mode propagates: rounding up",
|
||||
u"measure-unit/length-centimeter rounding-mode-ceiling",
|
||||
u"unit/centimeter rounding-mode-ceiling",
|
||||
NumberFormatter::with()
|
||||
.unit(MeasureUnit::forIdentifier("centimeter", status))
|
||||
.usage("road")
|
||||
.roundingMode(UNUM_ROUND_CEILING)
|
||||
.usage(""), // unset
|
||||
Locale("en-US"), //
|
||||
3048, //
|
||||
u"3,048 cm");
|
||||
|
||||
// TODO(icu-units#38): improve unit testing coverage. E.g. add vehicle-fuel
|
||||
// triggering inversion conversion code. Test with 0 too, to see
|
||||
// divide-by-zero behaviour.
|
||||
|
|
|
@ -545,6 +545,10 @@ public abstract class NumberFormatterSettings<T extends NumberFormatterSettings<
|
|||
* @draft ICU 68
|
||||
*/
|
||||
public T usage(String usage) {
|
||||
if (usage != null && usage.isEmpty()) {
|
||||
return create(KEY_USAGE, null);
|
||||
}
|
||||
|
||||
return create(KEY_USAGE, usage);
|
||||
}
|
||||
|
||||
|
|
|
@ -1653,6 +1653,57 @@ public class NumberFormatterApiTest extends TestFmwk {
|
|||
30500,
|
||||
"350 m");
|
||||
|
||||
// Test calling .usage("") or .usage(null) should unset the existing usage.
|
||||
// First: without usage
|
||||
assertFormatSingle("Rounding Mode propagates: rounding up",
|
||||
"measure-unit/length-centimeter rounding-mode-ceiling",
|
||||
"unit/centimeter rounding-mode-ceiling",
|
||||
NumberFormatter.with()
|
||||
.unit(MeasureUnit.forIdentifier("centimeter"))
|
||||
.roundingMode(RoundingMode.CEILING),
|
||||
new ULocale("en-US"),
|
||||
3048,
|
||||
"3,048 cm");
|
||||
|
||||
// Second: with "road" usage
|
||||
assertFormatSingle("Rounding Mode propagates: rounding up",
|
||||
"usage/road measure-unit/length-centimeter rounding-mode-ceiling",
|
||||
"usage/road unit/centimeter rounding-mode-ceiling",
|
||||
NumberFormatter.with()
|
||||
.unit(MeasureUnit.forIdentifier("centimeter"))
|
||||
.usage("road")
|
||||
.roundingMode(RoundingMode.CEILING),
|
||||
new ULocale("en-US"),
|
||||
3048,
|
||||
"100 ft");
|
||||
|
||||
// Third: with "road" usage, then the usage unsetted by calling .usage("")
|
||||
assertFormatSingle("Rounding Mode propagates: rounding up",
|
||||
"measure-unit/length-centimeter rounding-mode-ceiling",
|
||||
"unit/centimeter rounding-mode-ceiling",
|
||||
NumberFormatter.with()
|
||||
.unit(MeasureUnit.forIdentifier("centimeter"))
|
||||
.usage("road")
|
||||
.roundingMode(RoundingMode.CEILING)
|
||||
.usage(""), // unset
|
||||
new ULocale("en-US"),
|
||||
3048,
|
||||
"3,048 cm");
|
||||
|
||||
// Fourth: with "road" usage, then the usage unsetted by calling .usage(nul)
|
||||
assertFormatSingle("Rounding Mode propagates: rounding up",
|
||||
"measure-unit/length-centimeter rounding-mode-ceiling",
|
||||
"unit/centimeter rounding-mode-ceiling",
|
||||
NumberFormatter.with()
|
||||
.unit(MeasureUnit.forIdentifier("centimeter"))
|
||||
.usage("road")
|
||||
.roundingMode(RoundingMode.CEILING)
|
||||
.usage(null), // unset
|
||||
new ULocale("en-US"),
|
||||
3048,
|
||||
"3,048 cm");
|
||||
|
||||
|
||||
// TODO(icu-units#38): improve unit testing coverage. E.g. add
|
||||
// vehicle-fuel triggering inversion conversion code. Test with 0 too,
|
||||
// to see divide-by-zero behaviour.
|
||||
|
|
Loading…
Add table
Reference in a new issue