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"
|
|
|
|
|
2018-04-23 23:02:26 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2017-09-27 00:25:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-04-05 23:43:19 +00:00
|
|
|
#include "formatted_string_builder.h"
|
2017-09-27 00:25:20 +00:00
|
|
|
#include "intltest.h"
|
2018-11-15 07:38:54 +00:00
|
|
|
#include "itformat.h"
|
2017-09-27 00:25:20 +00:00
|
|
|
#include "number_affixutils.h"
|
2019-04-05 23:43:19 +00:00
|
|
|
#include "string_segment.h"
|
2018-10-19 23:19:24 +00:00
|
|
|
#include "numrange_impl.h"
|
2018-02-06 07:52:58 +00:00
|
|
|
#include "unicode/locid.h"
|
2018-08-29 08:22:21 +00:00
|
|
|
#include "unicode/numberformatter.h"
|
|
|
|
#include "unicode/numberrangeformatter.h"
|
2017-09-27 00:25:20 +00:00
|
|
|
|
|
|
|
using namespace icu::number;
|
|
|
|
using namespace icu::number::impl;
|
2018-02-06 07:52:58 +00:00
|
|
|
using namespace icu::numparse;
|
|
|
|
using namespace icu::numparse::impl;
|
2017-09-27 00:25:20 +00:00
|
|
|
|
2017-09-27 03:02:02 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// INSTRUCTIONS: //
|
|
|
|
// To add new NumberFormat unit test classes, create a new class like the ones below, //
|
|
|
|
// and then add it as a switch statement in NumberTest at the bottom of this file. /////////
|
|
|
|
// To add new methods to existing unit test classes, add the method to the class declaration //
|
|
|
|
// below, and also add it to the class's implementation of runIndexedTest(). //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
private:
|
|
|
|
UnicodeString unescapeWithDefaults(const SymbolProvider &defaultProvider, UnicodeString input,
|
|
|
|
UErrorCode &status);
|
|
|
|
};
|
|
|
|
|
2018-11-15 07:38:54 +00:00
|
|
|
class NumberFormatterApiTest : public IntlTestWithFieldPosition {
|
2017-09-27 02:16:44 +00:00
|
|
|
public:
|
|
|
|
NumberFormatterApiTest();
|
|
|
|
NumberFormatterApiTest(UErrorCode &status);
|
|
|
|
|
|
|
|
void notationSimple();
|
|
|
|
void notationScientific();
|
|
|
|
void notationCompact();
|
|
|
|
void unitMeasure();
|
2017-12-22 00:02:01 +00:00
|
|
|
void unitCompoundMeasure();
|
2017-09-27 02:16:44 +00:00
|
|
|
void unitCurrency();
|
|
|
|
void unitPercent();
|
2019-02-15 04:20:20 +00:00
|
|
|
void percentParity();
|
2017-09-27 02:16:44 +00:00
|
|
|
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();
|
2019-07-23 04:41:43 +00:00
|
|
|
void signCoverage();
|
2017-09-27 02:16:44 +00:00
|
|
|
void decimal();
|
2018-04-14 09:45:39 +00:00
|
|
|
void scale();
|
2017-09-27 02:16:44 +00:00
|
|
|
void locale();
|
2019-03-08 07:00:04 +00:00
|
|
|
void skeletonUserGuideExamples();
|
2017-09-27 22:31:07 +00:00
|
|
|
void formatTypes();
|
2018-11-07 01:07:49 +00:00
|
|
|
void fieldPositionLogic();
|
2018-11-14 05:42:27 +00:00
|
|
|
void fieldPositionCoverage();
|
2018-05-15 00:05:04 +00:00
|
|
|
void toFormat();
|
2017-09-27 02:16:44 +00:00
|
|
|
void errors();
|
2018-02-08 06:06:08 +00:00
|
|
|
void validRanges();
|
2018-03-17 07:24:02 +00:00
|
|
|
void copyMove();
|
2018-04-18 09:42:05 +00:00
|
|
|
void localPointerCAPI();
|
2019-01-11 21:47:33 +00:00
|
|
|
void toObject();
|
2019-08-14 22:47:41 +00:00
|
|
|
void toDecimalNumber();
|
2017-09-27 02:16:44 +00:00
|
|
|
|
|
|
|
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
|
|
|
|
|
|
|
|
private:
|
|
|
|
CurrencyUnit USD;
|
|
|
|
CurrencyUnit GBP;
|
|
|
|
CurrencyUnit CZK;
|
|
|
|
CurrencyUnit CAD;
|
2018-02-06 03:08:17 +00:00
|
|
|
CurrencyUnit ESP;
|
|
|
|
CurrencyUnit PTE;
|
2019-03-13 23:08:09 +00:00
|
|
|
CurrencyUnit RON;
|
2017-09-27 02:16:44 +00:00
|
|
|
|
|
|
|
MeasureUnit METER;
|
|
|
|
MeasureUnit DAY;
|
|
|
|
MeasureUnit SQUARE_METER;
|
|
|
|
MeasureUnit FAHRENHEIT;
|
2017-12-22 00:02:01 +00:00
|
|
|
MeasureUnit SECOND;
|
|
|
|
MeasureUnit POUND;
|
|
|
|
MeasureUnit SQUARE_MILE;
|
|
|
|
MeasureUnit JOULE;
|
|
|
|
MeasureUnit FURLONG;
|
2018-01-10 02:44:23 +00:00
|
|
|
MeasureUnit KELVIN;
|
2017-09-27 02:16:44 +00:00
|
|
|
|
|
|
|
NumberingSystem MATHSANB;
|
|
|
|
NumberingSystem LATN;
|
|
|
|
|
|
|
|
DecimalFormatSymbols FRENCH_SYMBOLS;
|
|
|
|
DecimalFormatSymbols SWISS_SYMBOLS;
|
|
|
|
DecimalFormatSymbols MYANMAR_SYMBOLS;
|
|
|
|
|
2018-03-24 07:36:18 +00:00
|
|
|
void assertFormatDescending(const char16_t* message, const char16_t* skeleton,
|
|
|
|
const UnlocalizedNumberFormatter& f, Locale locale, ...);
|
2017-09-27 02:16:44 +00:00
|
|
|
|
2018-03-24 07:36:18 +00:00
|
|
|
void assertFormatDescendingBig(const char16_t* message, const char16_t* skeleton,
|
|
|
|
const UnlocalizedNumberFormatter& f, Locale locale, ...);
|
2017-09-27 02:16:44 +00:00
|
|
|
|
2018-11-07 01:07:49 +00:00
|
|
|
FormattedNumber
|
|
|
|
assertFormatSingle(const char16_t* message, const char16_t* skeleton,
|
|
|
|
const UnlocalizedNumberFormatter& f, Locale locale, double input,
|
|
|
|
const UnicodeString& expected);
|
2018-03-24 07:36:18 +00:00
|
|
|
|
|
|
|
void assertUndefinedSkeleton(const UnlocalizedNumberFormatter& f);
|
2018-11-07 01:07:49 +00:00
|
|
|
|
2018-11-15 07:38:54 +00:00
|
|
|
void assertNumberFieldPositions(
|
|
|
|
const char16_t* message,
|
|
|
|
const FormattedNumber& formattedNumber,
|
|
|
|
const UFieldPosition* expectedFieldPositions,
|
|
|
|
int32_t length);
|
2017-09-27 02:16:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DecimalQuantityTest : public IntlTest {
|
|
|
|
public:
|
|
|
|
void testDecimalQuantityBehaviorStandalone();
|
|
|
|
void testSwitchStorage();
|
2018-04-07 08:49:11 +00:00
|
|
|
void testCopyMove();
|
2017-09-27 02:16:44 +00:00
|
|
|
void testAppend();
|
|
|
|
void testConvertToAccurateDouble();
|
|
|
|
void testUseApproximateDoubleWhenAble();
|
2018-02-16 01:25:43 +00:00
|
|
|
void testHardDoubleConversion();
|
2018-03-30 07:12:25 +00:00
|
|
|
void testToDouble();
|
2018-04-17 01:36:18 +00:00
|
|
|
void testMaxDigits();
|
2018-10-26 00:50:10 +00:00
|
|
|
void testNickelRounding();
|
2017-09-27 02:16:44 +00:00
|
|
|
|
|
|
|
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
|
|
|
|
|
|
|
|
private:
|
2017-09-27 22:31:07 +00:00
|
|
|
void assertDoubleEquals(UnicodeString message, double a, double b);
|
2017-09-27 02:16:44 +00:00
|
|
|
void assertHealth(const DecimalQuantity &fq);
|
|
|
|
void assertToStringAndHealth(const DecimalQuantity &fq, const UnicodeString &expected);
|
|
|
|
void checkDoubleBehavior(double d, bool explicitRequired);
|
|
|
|
};
|
|
|
|
|
2018-02-16 01:25:43 +00:00
|
|
|
class DoubleConversionTest : public IntlTest {
|
|
|
|
public:
|
|
|
|
void testDoubleConversionApi();
|
|
|
|
|
|
|
|
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
|
|
|
|
};
|
|
|
|
|
2017-09-27 02:16:44 +00:00
|
|
|
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);
|
|
|
|
|
2019-04-05 23:43:19 +00:00
|
|
|
void assertModifierEquals(const Modifier &mod, FormattedStringBuilder &sb, int32_t expectedPrefixLength,
|
2017-09-27 02:16:44 +00:00
|
|
|
bool expectedStrong, UnicodeString expectedChars,
|
|
|
|
UnicodeString expectedFields, UErrorCode &status);
|
|
|
|
};
|
|
|
|
|
|
|
|
class PatternModifierTest : public IntlTest {
|
|
|
|
public:
|
|
|
|
void testBasic();
|
2018-02-06 03:08:17 +00:00
|
|
|
void testPatternWithNoPlaceholder();
|
2017-09-27 02:16:44 +00:00
|
|
|
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:
|
2018-03-14 10:41:27 +00:00
|
|
|
void testLocalized();
|
2017-09-27 02:16:44 +00:00
|
|
|
void testToPatternSimple();
|
|
|
|
void testExceptionOnInvalid();
|
|
|
|
void testBug13117();
|
|
|
|
|
|
|
|
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
|
|
|
|
|
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
2018-02-08 08:49:50 +00:00
|
|
|
class NumberParserTest : public IntlTest {
|
|
|
|
public:
|
|
|
|
void testBasic();
|
|
|
|
void testLocaleFi();
|
|
|
|
void testSeriesMatcher();
|
2018-03-31 05:18:51 +00:00
|
|
|
void testCombinedCurrencyMatcher();
|
2018-02-10 10:01:46 +00:00
|
|
|
void testAffixPatternMatcher();
|
2018-02-08 08:49:50 +00:00
|
|
|
void testGroupingDisabled();
|
2018-03-31 05:18:51 +00:00
|
|
|
void testCaseFolding();
|
2019-02-06 22:38:36 +00:00
|
|
|
void test20360_BidiOverflow();
|
|
|
|
void testInfiniteRecursion();
|
2018-02-08 08:49:50 +00:00
|
|
|
|
|
|
|
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
|
|
|
|
};
|
|
|
|
|
2018-03-24 05:46:28 +00:00
|
|
|
class NumberSkeletonTest : public IntlTest {
|
|
|
|
public:
|
|
|
|
void validTokens();
|
|
|
|
void invalidTokens();
|
|
|
|
void unknownTokens();
|
|
|
|
void unexpectedTokens();
|
|
|
|
void duplicateValues();
|
|
|
|
void stemsRequiringOption();
|
|
|
|
void defaultTokens();
|
|
|
|
void flexibleSeparators();
|
|
|
|
|
|
|
|
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void expectedErrorSkeleton(const char16_t** cases, int32_t casesLen);
|
|
|
|
};
|
|
|
|
|
2018-11-15 07:38:54 +00:00
|
|
|
class NumberRangeFormatterTest : public IntlTestWithFieldPosition {
|
2018-08-29 08:22:21 +00:00
|
|
|
public:
|
2018-09-06 04:46:37 +00:00
|
|
|
NumberRangeFormatterTest();
|
|
|
|
NumberRangeFormatterTest(UErrorCode &status);
|
|
|
|
|
2018-08-29 08:22:21 +00:00
|
|
|
void testSanity();
|
|
|
|
void testBasic();
|
2018-09-06 06:04:32 +00:00
|
|
|
void testCollapse();
|
|
|
|
void testIdentity();
|
|
|
|
void testDifferentFormatters();
|
2018-09-14 23:33:22 +00:00
|
|
|
void testPlurals();
|
2018-11-15 07:38:54 +00:00
|
|
|
void testFieldPositions();
|
2018-09-18 09:14:24 +00:00
|
|
|
void testCopyMove();
|
2019-01-11 21:47:33 +00:00
|
|
|
void toObject();
|
2018-08-29 08:22:21 +00:00
|
|
|
|
|
|
|
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
|
|
|
|
|
|
|
|
private:
|
2018-09-06 04:46:37 +00:00
|
|
|
CurrencyUnit USD;
|
|
|
|
CurrencyUnit GBP;
|
|
|
|
CurrencyUnit PTE;
|
|
|
|
|
|
|
|
MeasureUnit METER;
|
|
|
|
MeasureUnit KILOMETER;
|
|
|
|
MeasureUnit FAHRENHEIT;
|
|
|
|
MeasureUnit KELVIN;
|
|
|
|
|
2018-08-29 08:22:21 +00:00
|
|
|
void assertFormatRange(
|
|
|
|
const char16_t* message,
|
|
|
|
const UnlocalizedNumberRangeFormatter& f,
|
|
|
|
Locale locale,
|
|
|
|
const char16_t* expected_10_50,
|
|
|
|
const char16_t* expected_49_51,
|
|
|
|
const char16_t* expected_50_50,
|
|
|
|
const char16_t* expected_00_30,
|
|
|
|
const char16_t* expected_00_00,
|
|
|
|
const char16_t* expected_30_3K,
|
|
|
|
const char16_t* expected_30K_50K,
|
|
|
|
const char16_t* expected_49K_51K,
|
|
|
|
const char16_t* expected_50K_50K,
|
|
|
|
const char16_t* expected_50K_50M);
|
|
|
|
|
2018-11-15 07:38:54 +00:00
|
|
|
FormattedNumberRange assertFormattedRangeEquals(
|
2018-08-29 08:22:21 +00:00
|
|
|
const char16_t* message,
|
|
|
|
const LocalizedNumberRangeFormatter& l,
|
|
|
|
double first,
|
|
|
|
double second,
|
|
|
|
const char16_t* expected);
|
|
|
|
};
|
|
|
|
|
2019-08-13 04:16:25 +00:00
|
|
|
class NumberPermutationTest : public IntlTest {
|
|
|
|
public:
|
|
|
|
void testPermutations();
|
|
|
|
|
|
|
|
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0);
|
|
|
|
};
|
|
|
|
|
2017-09-27 03:02:02 +00:00
|
|
|
|
|
|
|
// NOTE: This macro is identical to the one in itformat.cpp
|
|
|
|
#define TESTCLASS(id, TestClass) \
|
|
|
|
case id: \
|
|
|
|
name = #TestClass; \
|
|
|
|
if (exec) { \
|
|
|
|
logln(#TestClass " test---"); \
|
|
|
|
logln((UnicodeString)""); \
|
|
|
|
TestClass test; \
|
|
|
|
callTest(test, par); \
|
|
|
|
} \
|
|
|
|
break
|
|
|
|
|
|
|
|
class NumberTest : public IntlTest {
|
|
|
|
public:
|
|
|
|
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0) {
|
|
|
|
if (exec) {
|
|
|
|
logln("TestSuite NumberTest: ");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
TESTCLASS(0, AffixUtilsTest);
|
|
|
|
TESTCLASS(1, NumberFormatterApiTest);
|
|
|
|
TESTCLASS(2, DecimalQuantityTest);
|
|
|
|
TESTCLASS(3, ModifiersTest);
|
|
|
|
TESTCLASS(4, PatternModifierTest);
|
|
|
|
TESTCLASS(5, PatternStringTest);
|
2019-04-05 23:43:19 +00:00
|
|
|
TESTCLASS(6, DoubleConversionTest);
|
|
|
|
TESTCLASS(7, NumberParserTest);
|
|
|
|
TESTCLASS(8, NumberSkeletonTest);
|
|
|
|
TESTCLASS(9, NumberRangeFormatterTest);
|
2019-08-13 04:16:25 +00:00
|
|
|
TESTCLASS(10, NumberPermutationTest);
|
2017-09-27 03:02:02 +00:00
|
|
|
default: name = ""; break; // needed to end loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-09-27 05:31:57 +00:00
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|