U_NAMESPACE_BEGIN
+// Forward declaration:
+namespace number {
+namespace impl {
+class SimpleModifier;
+}
+}
+
/**
* Formats simple patterns like "{1} was born in {0}".
* Minimal subset of MessageFormat; fast, simple, minimal dependencies.
return getTextWithNoArguments(compiledPattern.getBuffer(), compiledPattern.length());
}
- /**
- * Gets the internal compiled pattern string.
- * @internal
- * @deprecated ICU 60 This API is ICU internal only.
- */
- UnicodeString getCompiledPattern() const {
- return compiledPattern;
- }
-
private:
/**
* Binary representation of the compiled pattern.
UnicodeString &result, const UnicodeString *resultCopy, UBool forbidResultAsValue,
int32_t *offsets, int32_t offsetsLength,
UErrorCode &errorCode);
+
+ // Give access to internals to SimpleModifier for number formatting
+ friend class number::impl::SimpleModifier;
};
U_NAMESPACE_END
}
SimpleModifier::SimpleModifier(const SimpleFormatter &simpleFormatter, Field field, bool strong)
- : fCompiledPattern(simpleFormatter.getCompiledPattern()), fField(field), fStrong(strong) {
+ : fCompiledPattern(simpleFormatter.compiledPattern), fField(field), fStrong(strong) {
U_ASSERT(1 ==
- SimpleFormatter::getArgumentLimit(compiledPattern.getBuffer(), compiledPattern.length()));
+ SimpleFormatter::getArgumentLimit(fCompiledPattern.getBuffer(), fCompiledPattern.length()));
if (fCompiledPattern.charAt(1) != 0) {
fPrefixLength = fCompiledPattern.charAt(1) - ARG_NUM_LIMIT;
fSuffixOffset = 3 + fPrefixLength;
}
void MutablePatternModifier::exitCharSequenceMode() {
- U_ASSERT(inCharSequenceMode)
+ U_ASSERT(inCharSequenceMode);
inCharSequenceMode = false;
}
reldatefmttest.o simpleformattertest.o measfmttest.o numfmtspectest.o unifiedcachetest.o quantityformattertest.o \
scientificnumberformattertest.o datadrivennumberformattestsuite.o \
numberformattesttuple.o numberformat2test.o pluralmaptest.o \
-numbertest_affixutils.o numbertest_stringbuilder.o
-# FIXME
-#numbertest_api.o numbertest_decimalquantity.o \
-#numbertest_modifiers.o numbertest_patternmodifier.o numbertest_patternstring.o \
+numbertest_affixutils.o numbertest_api.o numbertest_decimalquantity.o \
+numbertest_modifiers.o numbertest_patternmodifier.o numbertest_patternstring.o \
+numbertest_stringbuilder.o
DEPS = $(OBJECTS:.o=.d)
callTest(*test, par);
}
break;
- case 50:
+ case 50:
name = "NumberFormat2Test";
if (exec) {
logln("NumberFormat2Test test---");
LocalPointer<IntlTest> test(createNumberFormat2Test());
callTest(*test, par);
}
- break;
+ break;
TESTCLASS(51,AffixUtilsTest);
- TESTCLASS(52,NumberStringBuilderTest);
+ TESTCLASS(52,NumberFormatterApiTest);
+ TESTCLASS(53,DecimalQuantityTest);
+ TESTCLASS(54,ModifiersTest);
+ TESTCLASS(55,PatternModifierTest);
+ TESTCLASS(56,PatternStringTest);
+ TESTCLASS(57,NumberStringBuilderTest);
default: name = ""; break; //needed to end loop
}
if (exec) {
class AffixUtilsTest : public IntlTest {
public:
void testEscape();
-
void testUnescape();
-
void testContainsReplaceType();
-
void testInvalid();
-
void testUnescapeWithSymbolProvider();
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
UErrorCode &status);
};
+class NumberFormatterApiTest : public IntlTest {
+ public:
+ NumberFormatterApiTest();
+ NumberFormatterApiTest(UErrorCode &status);
+
+ void notationSimple();
+ void notationScientific();
+ void notationCompact();
+ void unitMeasure();
+ void unitCurrency();
+ void unitPercent();
+ void roundingFraction();
+ void roundingFigures();
+ void roundingFractionFigures();
+ void roundingOther();
+ void grouping();
+ void padding();
+ void integerWidth();
+ void symbols();
+ // TODO: Add this method if currency symbols override support is added.
+ //void symbolsOverride();
+ void sign();
+ void decimal();
+ void locale();
+ void errors();
+
+ void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
+
+ private:
+ CurrencyUnit USD;
+ CurrencyUnit GBP;
+ CurrencyUnit CZK;
+ CurrencyUnit CAD;
+
+ MeasureUnit METER;
+ MeasureUnit DAY;
+ MeasureUnit SQUARE_METER;
+ MeasureUnit FAHRENHEIT;
+
+ NumberingSystem MATHSANB;
+ NumberingSystem LATN;
+
+ DecimalFormatSymbols FRENCH_SYMBOLS;
+ DecimalFormatSymbols SWISS_SYMBOLS;
+ DecimalFormatSymbols MYANMAR_SYMBOLS;
+
+ void assertFormatDescending(const UnicodeString &message, const UnlocalizedNumberFormatter &f,
+ Locale locale, ...);
+
+ void assertFormatDescendingBig(const UnicodeString &message, const UnlocalizedNumberFormatter &f,
+ Locale locale, ...);
+
+ void assertFormatSingle(const UnicodeString &message, const UnlocalizedNumberFormatter &f,
+ Locale locale, double input, const UnicodeString &expected);
+};
+
+class DecimalQuantityTest : public IntlTest {
+ public:
+ void testDecimalQuantityBehaviorStandalone();
+ void testSwitchStorage();
+ void testAppend();
+ void testConvertToAccurateDouble();
+ void testUseApproximateDoubleWhenAble();
+
+ void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
+
+ private:
+ void assertDoubleEquals(const char *message, double a, double b);
+ void assertHealth(const DecimalQuantity &fq);
+ void assertToStringAndHealth(const DecimalQuantity &fq, const UnicodeString &expected);
+ void checkDoubleBehavior(double d, bool explicitRequired);
+};
+
+class ModifiersTest : public IntlTest {
+ public:
+ void testConstantAffixModifier();
+ void testConstantMultiFieldModifier();
+ void testSimpleModifier();
+ void testCurrencySpacingEnabledModifier();
+
+ void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
+
+ private:
+ void assertModifierEquals(const Modifier &mod, int32_t expectedPrefixLength, bool expectedStrong,
+ UnicodeString expectedChars, UnicodeString expectedFields,
+ UErrorCode &status);
+
+ void assertModifierEquals(const Modifier &mod, NumberStringBuilder &sb, int32_t expectedPrefixLength,
+ bool expectedStrong, UnicodeString expectedChars,
+ UnicodeString expectedFields, UErrorCode &status);
+};
+
+class PatternModifierTest : public IntlTest {
+ public:
+ void testBasic();
+ void testMutableEqualsImmutable();
+
+ void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
+
+ private:
+ UnicodeString getPrefix(const MutablePatternModifier &mod, UErrorCode &status);
+ UnicodeString getSuffix(const MutablePatternModifier &mod, UErrorCode &status);
+};
+
+class PatternStringTest : public IntlTest {
+ public:
+ void testToPatternSimple();
+ void testExceptionOnInvalid();
+ void testBug13117();
+
+ void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
+
+ private:
+};
+
class NumberStringBuilderTest : public IntlTest {
public:
void testInsertAppendUnicodeString();
-
void testInsertAppendCodePoint();
-
void testCopy();
-
void testFields();
-
void testUnlimitedCapacity();
-
void testCodePoints();
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
#include <charstr.h>
#include <cstdarg>
-#include <unicode/unum.h>
-#include <unicode/uclean.h>
-#include "temp_test_helpers.h"
+#include "unicode/unum.h"
#include "unicode/numberformatter.h"
#include "number_types.h"
+#include "numbertest.h"
-#include <iostream>
-#include "unicode/ustream.h"
-
-using namespace icu;
-using namespace icu::number;
-using namespace icu::number::impl;
-
-class numbertest_api {
- public:
- explicit numbertest_api(UErrorCode &status) : USD(u"USD", status), GBP(u"GBP", status),
- CZK(u"CZK", status), CAD(u"CAD", status),
- FRENCH_SYMBOLS(Locale::getFrench(), status),
- SWISS_SYMBOLS(Locale("de-CH"), status),
- MYANMAR_SYMBOLS(Locale("my"), status) {
- MeasureUnit *unit = MeasureUnit::createMeter(status);
- METER = *unit;
- delete unit;
- unit = MeasureUnit::createDay(status);
- DAY = *unit;
- delete unit;
- unit = MeasureUnit::createSquareMeter(status);
- SQUARE_METER = *unit;
- delete unit;
- unit = MeasureUnit::createFahrenheit(status);
- FAHRENHEIT = *unit;
- delete unit;
-
- NumberingSystem *ns = NumberingSystem::createInstanceByName("mathsanb", status);
- MATHSANB = *ns;
- delete ns;
- ns = NumberingSystem::createInstanceByName("latn", status);
- LATN = *ns;
- delete ns;
- }
-
- void notationSimple();
-
- void notationScientific();
-
- void notationCompact();
-
- void unitMeasure();
-
- void unitCurrency();
-
- void unitPercent();
-
- void roundingFraction();
-
- void roundingFigures();
-
- void roundingFractionFigures();
-
- void roundingOther();
-
- void grouping();
-
- void padding();
-
- void integerWidth();
-
- void symbols();
-
- // TODO: Add this method if currency symbols override support is added.
- //void symbolsOverride();
+// Horrible workaround for the lack of a status code in the constructor...
+UErrorCode globalNumberFormatterApiTestStatus = U_ZERO_ERROR;
- void sign();
-
- void decimal();
-
- void locale();
-
- void errors();
-
- private:
- CurrencyUnit USD;
- CurrencyUnit GBP;
- CurrencyUnit CZK;
- CurrencyUnit CAD;
-
- MeasureUnit METER;
- MeasureUnit DAY;
- MeasureUnit SQUARE_METER;
- MeasureUnit FAHRENHEIT;
-
- NumberingSystem MATHSANB;
- NumberingSystem LATN;
-
- DecimalFormatSymbols FRENCH_SYMBOLS;
- DecimalFormatSymbols SWISS_SYMBOLS;
- DecimalFormatSymbols MYANMAR_SYMBOLS;
-
- void assertFormatDescending(const UnicodeString &message, const UnlocalizedNumberFormatter &f,
- const Locale &locale, ...);
+NumberFormatterApiTest::NumberFormatterApiTest()
+ : NumberFormatterApiTest(globalNumberFormatterApiTestStatus) {
+ U_ASSERT(U_SUCCESS(globalNumberFormatterApiTestStatus));
+}
- void assertFormatDescendingBig(const UnicodeString &message, const UnlocalizedNumberFormatter &f,
- const Locale &locale, ...);
+NumberFormatterApiTest::NumberFormatterApiTest(UErrorCode &status)
+ : USD(u"USD", status), GBP(u"GBP", status),
+ CZK(u"CZK", status), CAD(u"CAD", status),
+ FRENCH_SYMBOLS(Locale::getFrench(), status),
+ SWISS_SYMBOLS(Locale("de-CH"), status),
+ MYANMAR_SYMBOLS(Locale("my"), status) {
+
+ MeasureUnit *unit = MeasureUnit::createMeter(status);
+ METER = *unit;
+ delete unit;
+ unit = MeasureUnit::createDay(status);
+ DAY = *unit;
+ delete unit;
+ unit = MeasureUnit::createSquareMeter(status);
+ SQUARE_METER = *unit;
+ delete unit;
+ unit = MeasureUnit::createFahrenheit(status);
+ FAHRENHEIT = *unit;
+ delete unit;
+
+ NumberingSystem *ns = NumberingSystem::createInstanceByName("mathsanb", status);
+ MATHSANB = *ns;
+ delete ns;
+ ns = NumberingSystem::createInstanceByName("latn", status);
+ LATN = *ns;
+ delete ns;
+}
- void assertFormatSingle(const UnicodeString &message, const UnlocalizedNumberFormatter &f,
- const Locale &locale, double input, const UnicodeString &expected);
-};
+void NumberFormatterApiTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *) {
+ if (exec) {
+ logln("TestSuite NumberFormatterApiTest: ");
+ }
+ TESTCASE_AUTO_BEGIN;
+ TESTCASE_AUTO(notationSimple);
+ TESTCASE_AUTO(notationScientific);
+ TESTCASE_AUTO(notationCompact);
+ TESTCASE_AUTO(unitMeasure);
+ 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);
+ TESTCASE_AUTO(locale);
+ TESTCASE_AUTO(errors);
+ TESTCASE_AUTO_END;
+}
-void numbertest_api::notationSimple() {
+void NumberFormatterApiTest::notationSimple() {
assertFormatDescending(
u"Basic",
NumberFormatter::with(),
}
-void numbertest_api::notationScientific() {
+void NumberFormatterApiTest::notationScientific() {
assertFormatDescending(
u"Scientific",
NumberFormatter::with().notation(Notation::scientific()),
u"-1E6");
}
-void numbertest_api::notationCompact() {
+void NumberFormatterApiTest::notationCompact() {
assertFormatDescending(
u"Compact Short",
NumberFormatter::with().notation(Notation::compactShort()),
u"10M");
}
-void numbertest_api::unitMeasure() {
+void NumberFormatterApiTest::unitMeasure() {
assertFormatDescending(
u"Meters Short",
NumberFormatter::with().adoptUnit(new MeasureUnit(METER)),
u"5.43 °F");
}
-void numbertest_api::unitCurrency() {
+void NumberFormatterApiTest::unitCurrency() {
assertFormatDescending(
u"Currency",
NumberFormatter::with().unit(GBP),
u"-£9,876,543.21");
}
-void numbertest_api::unitPercent() {
+void NumberFormatterApiTest::unitPercent() {
assertFormatDescending(
u"Percent",
NumberFormatter::with().unit(NoUnit::percent()),
u"-98.765432%");
}
-void numbertest_api::roundingFraction() {
+void NumberFormatterApiTest::roundingFraction() {
assertFormatDescending(
u"Integer",
NumberFormatter::with().rounding(Rounder::integer()),
u"0.0");
}
-void numbertest_api::roundingFigures() {
+void NumberFormatterApiTest::roundingFigures() {
assertFormatSingle(
u"Fixed Significant",
NumberFormatter::with().rounding(Rounder::fixedDigits(3)),
u"10.0");
}
-void numbertest_api::roundingFractionFigures() {
+void NumberFormatterApiTest::roundingFractionFigures() {
assertFormatDescending(
u"Basic Significant", // for comparison
NumberFormatter::with().rounding(Rounder::maxDigits(2)),
u"0.00");
}
-void numbertest_api::roundingOther() {
+void NumberFormatterApiTest::roundingOther() {
assertFormatDescending(
u"Rounding None",
NumberFormatter::with().rounding(Rounder::unlimited()),
u"0");
}
-void numbertest_api::grouping() {
+void NumberFormatterApiTest::grouping() {
assertFormatDescendingBig(
u"Western Grouping",
NumberFormatter::with().grouping(Grouper::defaults()),
u"0");
}
-void numbertest_api::padding() {
+void NumberFormatterApiTest::padding() {
assertFormatDescending(
u"Padding",
NumberFormatter::with().padding(Padder::none()),
u"GBP 000514.23"); // TODO: This is broken; it renders too wide (13 instead of 12).
}
-void numbertest_api::integerWidth() {
+void NumberFormatterApiTest::integerWidth() {
assertFormatDescending(
u"Integer Width Default",
NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(1)),
u"00");
}
-void numbertest_api::symbols() {
+void NumberFormatterApiTest::symbols() {
assertFormatDescending(
u"French Symbols with Japanese Data 1",
NumberFormatter::with().symbols(FRENCH_SYMBOLS),
// u"@ 12.30");
//}
-void numbertest_api::sign() {
+void NumberFormatterApiTest::sign() {
assertFormatSingle(
u"Sign Auto Positive",
NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_AUTO),
u"(444,444.00)");
}
-void numbertest_api::decimal() {
+void NumberFormatterApiTest::decimal() {
assertFormatDescending(
u"Decimal Default",
NumberFormatter::with().decimal(UNumberDecimalSeparatorDisplay::UNUM_DECIMAL_SEPARATOR_AUTO),
u"0.");
}
-void numbertest_api::locale() {
+void NumberFormatterApiTest::locale() {
// Coverage for the locale setters.
UErrorCode status = U_ZERO_ERROR;
UnicodeString actual = NumberFormatter::withLocale(Locale::getFrench()).formatInt(1234, status)
assertEquals("Locale withLocale()", u"1 234", actual);
}
-void numbertest_api::errors() {
+void NumberFormatterApiTest::errors() {
LocalizedNumberFormatter lnf = NumberFormatter::withLocale(Locale::getEnglish()).rounding(
Rounder::fixedFraction(
-1));
}
-void numbertest_api::assertFormatDescending(const UnicodeString &message,
+void NumberFormatterApiTest::assertFormatDescending(const UnicodeString &message,
const UnlocalizedNumberFormatter &f,
- const Locale &locale, ...) {
+ Locale locale, ...) {
va_list args;
- // TODO: Fix this? "warning: 'va_start' has undefined behavior with reference types [-Wvarargs]"
va_start(args, locale);
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
}
}
-void numbertest_api::assertFormatDescendingBig(const UnicodeString &message,
+void NumberFormatterApiTest::assertFormatDescendingBig(const UnicodeString &message,
const UnlocalizedNumberFormatter &f,
- const Locale &locale, ...) {
+ Locale locale, ...) {
va_list args;
- // TODO: Fix this? "warning: 'va_start' has undefined behavior with reference types [-Wvarargs]"
va_start(args, locale);
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
}
}
-void numbertest_api::assertFormatSingle(const UnicodeString &message,
- const UnlocalizedNumberFormatter &f, const Locale &locale,
+void NumberFormatterApiTest::assertFormatSingle(const UnicodeString &message,
+ const UnlocalizedNumberFormatter &f, Locale locale,
double input, const UnicodeString &expected) {
const LocalizedNumberFormatter l1 = f.threshold(0).locale(locale); // no self-regulation
const LocalizedNumberFormatter l2 = f.threshold(1).locale(locale); // all self-regulation
assertSuccess(message + u": Safe Path", status);
assertEquals(message + u": Safe Path", expected, actual2);
}
-
-int main() {
- UErrorCode status = U_ZERO_ERROR;
- numbertest_api test(status);
- test.notationSimple();
- test.notationScientific();
- test.notationCompact();
- test.unitMeasure();
- test.unitCurrency();
- test.unitPercent();
- test.roundingFraction();
- test.roundingFigures();
- test.roundingFractionFigures();
- test.roundingOther();
- test.grouping();
- test.padding();
- test.integerWidth();
- test.symbols();
- test.sign();
- test.decimal();
- test.locale();
- test.errors();
-
- u_cleanup();
-}
#include "number_decimalquantity.h"
#include "math.h"
#include <cmath>
-
-using namespace icu::number::impl;
-
-class DecimalQuantityTest : public IntlTest {
- public:
- void testDecimalQuantityBehaviorStandalone();
-
- void testSwitchStorage();
-
- void testAppend();
-
- void testConvertToAccurateDouble();
-
- void testUseApproximateDoubleWhenAble();
-
- void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
-
- private:
- void assertDoubleEquals(const char *message, double a, double b);
-
- void assertHealth(const DecimalQuantity &fq);
-
- void assertToStringAndHealth(const DecimalQuantity &fq, const UnicodeString &expected);
-
- void checkDoubleBehavior(double d, bool explicitRequired);
-};
+#include "numbertest.h"
void DecimalQuantityTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *) {
if (exec) {
logln("TestSuite DecimalQuantityTest: ");
}
TESTCASE_AUTO_BEGIN;
- TESTCASE_AUTO(testDecimalQuantityBehaviorStandalone);
- TESTCASE_AUTO(testSwitchStorage);
- TESTCASE_AUTO(testAppend);
- TESTCASE_AUTO(testConvertToAccurateDouble);
- TESTCASE_AUTO(testUseApproximateDoubleWhenAble);
+ TESTCASE_AUTO(testDecimalQuantityBehaviorStandalone);
+ TESTCASE_AUTO(testSwitchStorage);
+ TESTCASE_AUTO(testAppend);
+ TESTCASE_AUTO(testConvertToAccurateDouble);
+ TESTCASE_AUTO(testUseApproximateDoubleWhenAble);
TESTCASE_AUTO_END;
}
assertToStringAndHealth(fq, "<DecimalQuantity 5:2:-3:-6 long 987654321E-6>");
fq.roundToInfinity();
assertToStringAndHealth(fq, "<DecimalQuantity 5:2:-3:-6 long 987654321E-6>");
- fq.roundToIncrement(0.005, RoundingMode::kRoundHalfEven, status);
+ fq.roundToIncrement(0.005, RoundingMode::UNUM_ROUND_HALFEVEN, status);
assertSuccess("Rounding to increment", status);
assertToStringAndHealth(fq, "<DecimalQuantity 5:2:-3:-6 long 987655E-3>");
- fq.roundToMagnitude(-2, RoundingMode::kRoundHalfEven, status);
+ fq.roundToMagnitude(-2, RoundingMode::UNUM_ROUND_HALFEVEN, status);
assertSuccess("Rounding to magnitude", status);
assertToStringAndHealth(fq, "<DecimalQuantity 5:2:-3:-6 long 98766E-2>");
}
assertEquals("Failed on multiply", "12341234123412345E0", fq.toNumberString());
assertHealth(fq);
// Bytes -> Long
- fq.roundToMagnitude(5, RoundingMode::kRoundHalfEven, status);
+ fq.roundToMagnitude(5, RoundingMode::UNUM_ROUND_HALFEVEN, status);
assertSuccess("Rounding to magnitude", status);
assertFalse("Should not be using byte array", fq.isUsingBytes());
assertEquals("Failed on round", "123412341234E5", fq.toNumberString());
int32_t maxFrac;
RoundingMode roundingMode;
bool usesExact;
- } cases[] = {{1.2345678, 1, RoundingMode::kRoundHalfEven, false},
- {1.2345678, 7, RoundingMode::kRoundHalfEven, false},
- {1.2345678, 12, RoundingMode::kRoundHalfEven, false},
- {1.2345678, 13, RoundingMode::kRoundHalfEven, true},
- {1.235, 1, RoundingMode::kRoundHalfEven, false},
- {1.235, 2, RoundingMode::kRoundHalfEven, true},
- {1.235, 3, RoundingMode::kRoundHalfEven, false},
- {1.000000000000001, 0, RoundingMode::kRoundHalfEven, false},
- {1.000000000000001, 0, RoundingMode::kRoundCeiling, true},
- {1.235, 1, RoundingMode::kRoundCeiling, false},
- {1.235, 2, RoundingMode::kRoundCeiling, false},
- {1.235, 3, RoundingMode::kRoundCeiling, true}};
+ } cases[] = {{1.2345678, 1, RoundingMode::UNUM_ROUND_HALFEVEN, false},
+ {1.2345678, 7, RoundingMode::UNUM_ROUND_HALFEVEN, false},
+ {1.2345678, 12, RoundingMode::UNUM_ROUND_HALFEVEN, false},
+ {1.2345678, 13, RoundingMode::UNUM_ROUND_HALFEVEN, true},
+ {1.235, 1, RoundingMode::UNUM_ROUND_HALFEVEN, false},
+ {1.235, 2, RoundingMode::UNUM_ROUND_HALFEVEN, true},
+ {1.235, 3, RoundingMode::UNUM_ROUND_HALFEVEN, false},
+ {1.000000000000001, 0, RoundingMode::UNUM_ROUND_HALFEVEN, false},
+ {1.000000000000001, 0, RoundingMode::UNUM_ROUND_CEILING, true},
+ {1.235, 1, RoundingMode::UNUM_ROUND_CEILING, false},
+ {1.235, 2, RoundingMode::UNUM_ROUND_CEILING, false},
+ {1.235, 3, RoundingMode::UNUM_ROUND_CEILING, true}};
UErrorCode status = U_ZERO_ERROR;
for (TestCase cas : cases) {
#include "intltest.h"
#include "number_stringbuilder.h"
#include "number_modifiers.h"
-
-using namespace icu::number::impl;
-
-class ModifiersTest : public IntlTest {
- public:
- void testConstantAffixModifier();
-
- void testConstantMultiFieldModifier();
-
- void testSimpleModifier();
-
- void testCurrencySpacingEnabledModifier();
-
- void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
-
- private:
- void assertModifierEquals(const Modifier &mod, int32_t expectedPrefixLength, bool expectedStrong,
- UnicodeString expectedChars, UnicodeString expectedFields,
- UErrorCode &status);
-
- void assertModifierEquals(const Modifier &mod, NumberStringBuilder &sb, int32_t expectedPrefixLength,
- bool expectedStrong, UnicodeString expectedChars,
- UnicodeString expectedFields, UErrorCode &status);
-};
+#include "numbertest.h"
void ModifiersTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *) {
if (exec) {
// © 2017 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
-#include "intltest.h"
+#include "numbertest.h"
+#include "number_patternmodifier.h"
-class PatternStringTest : public IntlTest {
- public:
- testBasic();
- testMutableEqualsImmutable();
-
- private:
- static UnicodeString getPrefix(const MutablePatternModifier &mod, UErrorCode &status);
- static UnicodeString getSuffix(const MutablePatternModifier &mod, UErrorCode &status);
-};
+void PatternModifierTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *) {
+ if (exec) {
+ logln("TestSuite PatternModifierTest: ");
+ }
+ TESTCASE_AUTO_BEGIN;
+ TESTCASE_AUTO(testBasic);
+ TESTCASE_AUTO(testMutableEqualsImmutable);
+ TESTCASE_AUTO_END;
+}
-void PatternStringTest::testBasic() {
+void PatternModifierTest::testBasic() {
UErrorCode status = U_ZERO_ERROR;
MutablePatternModifier mod(false);
ParsedPatternInfo patternInfo;
assertSuccess("Spot 5", status);
}
-void PatternStringTest::testMutableEqualsImmutable() {
+void PatternModifierTest::testMutableEqualsImmutable() {
UErrorCode status = U_ZERO_ERROR;
MutablePatternModifier mod(false);
ParsedPatternInfo patternInfo;
assertFalse(nsb1.toUnicodeString() + " vs " + nsb3.toUnicodeString(), nsb1.contentEquals(nsb3));
}
-static UnicodeString PatternStringTest::getPrefix(const MutablePatternModifier &mod, UErrorCode &status) {
+UnicodeString PatternModifierTest::getPrefix(const MutablePatternModifier &mod, UErrorCode &status) {
NumberStringBuilder nsb;
mod.apply(nsb, 0, 0, status);
int32_t prefixLength = mod.getPrefixLength(status);
return UnicodeString(nsb.toUnicodeString(), 0, prefixLength);
}
-static UnicodeString PatternStringTest::getSuffix(const MutablePatternModifier &mod, UErrorCode &status) {
+UnicodeString PatternModifierTest::getSuffix(const MutablePatternModifier &mod, UErrorCode &status) {
NumberStringBuilder nsb;
mod.apply(nsb, 0, 0, status);
int32_t prefixLength = mod.getPrefixLength(status);
// © 2017 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
-void testToPatternSimple() {
+#include "numbertest.h"
+#include "number_patternstring.h"
+
+void PatternStringTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *) {
+ if (exec) {
+ logln("TestSuite PatternStringTest: ");
+ }
+ TESTCASE_AUTO_BEGIN;
+ TESTCASE_AUTO(testToPatternSimple);
+ TESTCASE_AUTO(testExceptionOnInvalid);
+ TESTCASE_AUTO(testBug13117);
+ TESTCASE_AUTO_END;
+}
+
+void PatternStringTest::testToPatternSimple() {
const char16_t *cases[][2] = {{u"#", u"0"},
{u"0", u"0"},
{u"#0", u"0"},
}
}
-void testExceptionOnInvalid() {
+void PatternStringTest::testExceptionOnInvalid() {
static const char16_t *invalidPatterns[] = {
u"#.#.#",
u"0#",
}
}
-void testBug13117() {
+void PatternStringTest::testBug13117() {
UErrorCode status = U_ZERO_ERROR;
DecimalFormatProperties expected = PatternParser::parseToProperties(
u"0",