1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
|
// © 2017 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
#pragma once
#include "formatted_string_builder.h"
#include "intltest.h"
#include "itformat.h"
#include "number_affixutils.h"
#include "string_segment.h"
#include "numrange_impl.h"
#include "unicode/locid.h"
#include "unicode/numberformatter.h"
#include "unicode/numberrangeformatter.h"
// ICU-20241 Solaris #defines ESP in sys/regset.h
#ifdef ESP
# undef ESP
#endif
using namespace icu::number;
using namespace icu::number::impl;
using namespace icu::numparse;
using namespace icu::numparse::impl;
////////////////////////////////////////////////////////////////////////////////////////
// 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(). //
///////////////////////////////////////////////////////////////////////////////////////////////
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 = nullptr) override;
private:
UnicodeString unescapeWithDefaults(const SymbolProvider &defaultProvider, UnicodeString input,
UErrorCode &status);
};
class NumberFormatterApiTest : public IntlTestWithFieldPosition {
public:
NumberFormatterApiTest();
NumberFormatterApiTest(UErrorCode &status);
void notationSimple();
void notationScientific();
void notationCompact();
void unitMeasure();
void unitCompoundMeasure();
void unitArbitraryMeasureUnits();
void unitSkeletons();
void unitUsage();
void unitUsageErrorCodes();
void unitUsageSkeletons();
void unitCurrency();
void unitInflections();
void unitNounClass();
void unitGender();
void unitNotConvertible();
void unitPercent();
void unitLocaleTags();
void percentParity();
void roundingFraction();
void roundingFigures();
void roundingFractionFigures();
void roundingOther();
void roundingIncrementRegressionTest();
void roundingPriorityCoverageTest();
void grouping();
void padding();
void integerWidth();
void symbols();
// TODO: Add this method if currency symbols override support is added.
//void symbolsOverride();
void sign();
void signNearZero();
void signCoverage();
void decimal();
void scale();
void locale();
void skeletonUserGuideExamples();
void formatTypes();
void fieldPositionLogic();
void fieldPositionCoverage();
void toFormat();
void errors();
void validRanges();
void copyMove();
void localPointerCAPI();
void toObject();
void toDecimalNumber();
void microPropsInternals();
void formatUnitsAliases();
void formatArbitraryConstant();
void TestPortionFormat();
void testIssue22378();
void runIndexedTest(int32_t index, UBool exec, const char*& name, char* par = nullptr) override;
private:
CurrencyUnit USD;
CurrencyUnit GBP;
CurrencyUnit CZK;
CurrencyUnit CAD;
CurrencyUnit ESP;
CurrencyUnit PTE;
CurrencyUnit RON;
CurrencyUnit TWD;
CurrencyUnit TRY;
CurrencyUnit CNY;
MeasureUnit METER;
MeasureUnit METER_PER_SECOND;
MeasureUnit DAY;
MeasureUnit SQUARE_METER;
MeasureUnit FAHRENHEIT;
MeasureUnit SECOND;
MeasureUnit POUND;
MeasureUnit POUND_FORCE;
MeasureUnit SQUARE_MILE;
MeasureUnit SQUARE_INCH;
MeasureUnit JOULE;
MeasureUnit FURLONG;
MeasureUnit KELVIN;
NumberingSystem MATHSANB;
NumberingSystem LATN;
DecimalFormatSymbols FRENCH_SYMBOLS;
DecimalFormatSymbols SWISS_SYMBOLS;
DecimalFormatSymbols MYANMAR_SYMBOLS;
/**
* skeleton is the full length skeleton, which must round-trip.
*
* conciseSkeleton should be the shortest available skeleton.
* The concise skeleton can be read but not printed.
*/
void assertFormatDescending(
const char16_t* message,
const char16_t* skeleton,
const char16_t* conciseSkeleton,
const UnlocalizedNumberFormatter& f,
Locale locale,
...);
/** See notes above regarding skeleton vs conciseSkeleton */
void assertFormatDescendingBig(
const char16_t* message,
const char16_t* skeleton,
const char16_t* conciseSkeleton,
const UnlocalizedNumberFormatter& f,
Locale locale,
...);
/** See notes above regarding skeleton vs conciseSkeleton */
FormattedNumber assertFormatSingle(
const char16_t* message,
const char16_t* skeleton,
const char16_t* conciseSkeleton,
const UnlocalizedNumberFormatter& f,
Locale locale,
double input,
const UnicodeString& expected);
void assertUndefinedSkeleton(const UnlocalizedNumberFormatter& f);
void assertNumberFieldPositions(
const char16_t* message,
const FormattedNumber& formattedNumber,
const UFieldPosition* expectedFieldPositions,
int32_t length);
struct UnitInflectionTestCase {
const char *unitIdentifier;
const char *locale;
const char *unitDisplayCase;
double value;
const char16_t *expected;
};
void runUnitInflectionsTestCases(UnlocalizedNumberFormatter unf,
UnicodeString skeleton,
const UnitInflectionTestCase *cases,
int32_t numCases,
IcuTestErrorCode &status);
};
class DecimalQuantityTest : public IntlTest {
public:
void testDecimalQuantityBehaviorStandalone();
void testSwitchStorage();
void testCopyMove();
void testAppend();
void testConvertToAccurateDouble();
void testUseApproximateDoubleWhenAble();
void testHardDoubleConversion();
void testFitsInLong();
void testToDouble();
void testMaxDigits();
void testNickelRounding();
void testScientificAndCompactSuppressedExponent();
void testSuppressedExponentUnchangedByInitialScaling();
void testDecimalQuantityParseFormatRoundTrip();
void runIndexedTest(int32_t index, UBool exec, const char*& name, char* par = nullptr) override;
private:
void assertDoubleEquals(UnicodeString 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 DoubleConversionTest : public IntlTest {
public:
void testDoubleConversionApi();
void runIndexedTest(int32_t index, UBool exec, const char*& name, char* par = nullptr) override;
};
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 = nullptr) override;
private:
void assertModifierEquals(const Modifier &mod, int32_t expectedPrefixLength, bool expectedStrong,
UnicodeString expectedChars, UnicodeString expectedFields,
UErrorCode &status);
void assertModifierEquals(const Modifier &mod, FormattedStringBuilder &sb, int32_t expectedPrefixLength,
bool expectedStrong, UnicodeString expectedChars,
UnicodeString expectedFields, UErrorCode &status);
};
class PatternModifierTest : public IntlTest {
public:
void testBasic();
void testPatternWithNoPlaceholder();
void testMutableEqualsImmutable();
void runIndexedTest(int32_t index, UBool exec, const char*& name, char* par = nullptr) override;
private:
UnicodeString getPrefix(const MutablePatternModifier &mod, UErrorCode &status);
UnicodeString getSuffix(const MutablePatternModifier &mod, UErrorCode &status);
};
class PatternStringTest : public IntlTestWithFieldPosition {
public:
void testLocalized();
void testToPatternSimple();
void testExceptionOnInvalid();
void testBug13117();
void testCurrencyDecimal();
void runIndexedTest(int32_t index, UBool exec, const char*& name, char* par = nullptr) override;
private:
};
class NumberParserTest : public IntlTest {
public:
void testBasic();
void testLocaleFi();
void testSeriesMatcher();
void testCombinedCurrencyMatcher();
void testAffixPatternMatcher();
void testGroupingDisabled();
void testCaseFolding();
void test20360_BidiOverflow();
void testInfiniteRecursion();
void runIndexedTest(int32_t index, UBool exec, const char*& name, char* par = nullptr) override;
};
class NumberSkeletonTest : public IntlTest {
public:
void validTokens();
void invalidTokens();
void unknownTokens();
void unexpectedTokens();
void duplicateValues();
void stemsRequiringOption();
void defaultTokens();
void flexibleSeparators();
void wildcardCharacters();
void perUnitInArabic();
void perUnitToSkeleton();
void measurementSystemOverride();
void runIndexedTest(int32_t index, UBool exec, const char*& name, char* par = nullptr) override;
private:
void expectedErrorSkeleton(const char16_t** cases, int32_t casesLen);
};
class NumberRangeFormatterTest : public IntlTestWithFieldPosition {
public:
NumberRangeFormatterTest();
NumberRangeFormatterTest(UErrorCode &status);
void testSanity();
void testBasic();
void testCollapse();
void testIdentity();
void testDifferentFormatters();
void testNaNInfinity();
void testPlurals();
void testFieldPositions();
void testCopyMove();
void toObject();
void locale();
void testGetDecimalNumbers();
void test21684_Performance();
void test21358_SignPosition();
void test21683_StateLeak();
void testCreateLNRFFromNumberingSystemInSkeleton();
void test22288_DifferentStartEndSettings();
void test23110_PercentApproximately();
void runIndexedTest(int32_t index, UBool exec, const char*& name, char* par = nullptr) override;
private:
CurrencyUnit USD;
CurrencyUnit CHF;
CurrencyUnit GBP;
CurrencyUnit PTE;
MeasureUnit METER;
MeasureUnit KILOMETER;
MeasureUnit FAHRENHEIT;
MeasureUnit KELVIN;
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);
FormattedNumberRange assertFormattedRangeEquals(
const char16_t* message,
const LocalizedNumberRangeFormatter& l,
UnicodeString locale,
double first,
double second,
const char16_t* expected);
};
class SimpleNumberFormatterTest : public IntlTestWithFieldPosition {
public:
void testBasic();
void testWithOptions();
void testDigits();
void testSymbols();
void testSign();
void testCopyMove();
void testCAPI();
void runIndexedTest(int32_t index, UBool exec, const char*& name, char* par = nullptr) override;
};
class NumberPermutationTest : public IntlTest {
public:
void testPermutations();
void runIndexedTest(int32_t index, UBool exec, const char*& name, char* par = nullptr) override;
};
// 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 = nullptr) override {
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);
TESTCLASS(6, DoubleConversionTest);
TESTCLASS(7, NumberParserTest);
TESTCLASS(8, NumberSkeletonTest);
TESTCLASS(9, NumberRangeFormatterTest);
TESTCLASS(10, SimpleNumberFormatterTest);
TESTCLASS(11, NumberPermutationTest);
default: name = ""; break; // needed to end loop
}
}
};
#endif /* #if !UCONFIG_NO_FORMATTING */
|