1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #include "unicode/utypes.h"
6 #if !UCONFIG_NO_FORMATTING
8 #include "numbertest.h"
9 #include "static_unicode_sets.h"
10 #include "unicode/dcfmtsym.h"
12 using icu::unisets::get
;
14 class StaticUnicodeSetsTest
: public IntlTest
{
16 void testSetCoverage();
19 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
= 0);
22 void assertInSet(const UnicodeString
& localeName
, const UnicodeString
&setName
,
23 const UnicodeSet
& set
, const UnicodeString
& str
);
24 void assertInSet(const UnicodeString
& localeName
, const UnicodeString
&setName
,
25 const UnicodeSet
& set
, UChar32 cp
);
28 extern IntlTest
*createStaticUnicodeSetsTest() {
29 return new StaticUnicodeSetsTest();
32 void StaticUnicodeSetsTest::runIndexedTest(int32_t index
, UBool exec
, const char*&name
, char*) {
34 logln("TestSuite StaticUnicodeSetsTest: ");
38 // Slow test: run in exhaustive mode only
39 TESTCASE_AUTO(testSetCoverage
);
41 TESTCASE_AUTO(testNonEmpty
);
45 void StaticUnicodeSetsTest::testSetCoverage() {
46 UErrorCode status
= U_ZERO_ERROR
;
48 // Lenient comma/period should be supersets of strict comma/period;
49 // it also makes the coverage logic cheaper.
51 "COMMA should be superset of STRICT_COMMA",
52 get(unisets::COMMA
)->containsAll(*get(unisets::STRICT_COMMA
)));
54 "PERIOD should be superset of STRICT_PERIOD",
55 get(unisets::PERIOD
)->containsAll(*get(unisets::STRICT_PERIOD
)));
58 decimals
.addAll(*get(unisets::STRICT_COMMA
));
59 decimals
.addAll(*get(unisets::STRICT_PERIOD
));
62 grouping
.addAll(decimals
);
63 grouping
.addAll(*get(unisets::OTHER_GROUPING_SEPARATORS
));
66 const UnicodeSet
&plusSign
= *get(unisets::PLUS_SIGN
);
67 const UnicodeSet
&minusSign
= *get(unisets::MINUS_SIGN
);
68 const UnicodeSet
&percent
= *get(unisets::PERCENT_SIGN
);
69 const UnicodeSet
&permille
= *get(unisets::PERMILLE_SIGN
);
70 const UnicodeSet
&infinity
= *get(unisets::INFINITY_SIGN
);
73 const Locale
* allAvailableLocales
= Locale::getAvailableLocales(localeCount
);
74 for (int32_t i
= 0; i
< localeCount
; i
++) {
75 Locale locale
= allAvailableLocales
[i
];
76 DecimalFormatSymbols
dfs(locale
, status
);
77 UnicodeString localeName
;
78 locale
.getDisplayName(localeName
);
79 assertSuccess(UnicodeString("Making DFS for ") + localeName
, status
);
81 #define ASSERT_IN_SET(name, foo) assertInSet(localeName, UnicodeString("" #name ""), name, foo)
82 ASSERT_IN_SET(decimals
, dfs
.getConstSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol
));
83 ASSERT_IN_SET(grouping
, dfs
.getConstSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol
));
84 ASSERT_IN_SET(plusSign
, dfs
.getConstSymbol(DecimalFormatSymbols::kPlusSignSymbol
));
85 ASSERT_IN_SET(minusSign
, dfs
.getConstSymbol(DecimalFormatSymbols::kMinusSignSymbol
));
86 ASSERT_IN_SET(percent
, dfs
.getConstSymbol(DecimalFormatSymbols::kPercentSymbol
));
87 ASSERT_IN_SET(permille
, dfs
.getConstSymbol(DecimalFormatSymbols::kPerMillSymbol
));
88 ASSERT_IN_SET(infinity
, dfs
.getConstSymbol(DecimalFormatSymbols::kInfinitySymbol
));
92 void StaticUnicodeSetsTest::testNonEmpty() {
93 for (int32_t i
=0; i
<unisets::UNISETS_KEY_COUNT
; i
++) {
94 if (i
== unisets::EMPTY
) {
97 const UnicodeSet
* uset
= get(static_cast<unisets::Key
>(i
));
98 // Can fail if no data:
99 assertFalse(UnicodeString("Set should not be empty: ") + i
, uset
->isEmpty(), FALSE
, TRUE
);
103 void StaticUnicodeSetsTest::assertInSet(const UnicodeString
&localeName
, const UnicodeString
&setName
,
104 const UnicodeSet
&set
, const UnicodeString
&str
) {
105 if (str
.countChar32(0, str
.length()) != 1) {
106 // Ignore locale strings with more than one code point (usually a bidi mark)
109 assertInSet(localeName
, setName
, set
, str
.char32At(0));
112 void StaticUnicodeSetsTest::assertInSet(const UnicodeString
&localeName
, const UnicodeString
&setName
,
113 const UnicodeSet
&set
, UChar32 cp
) {
114 // If this test case fails, add the specified code point to the corresponding set in
115 // UnicodeSetStaticCache.java and numparse_unisets.cpp
117 localeName
+ UnicodeString(u
" ") + UnicodeString(cp
) + UnicodeString(u
" is missing in ") +
118 setName
, set
.contains(cp
));