1 /********************************************************************
3 * Copyright (c) 2007-2010, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 #include "unicode/utypes.h"
9 #if !UCONFIG_NO_FORMATTING
14 #include "unicode/plurrule.h"
15 #include "unicode/plurfmt.h"
18 #define PLURAL_PATTERN_DATA 4
19 #define PLURAL_TEST_ARRAY_SIZE 256
21 #define PLURAL_SYNTAX_DATA 8
23 // The value must be same as PLKeywordLookups[] order.
31 void PluralFormatTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
33 if (exec
) logln("TestSuite PluralFormat");
35 TESTCASE(0, pluralFormatBasicTest
);
36 TESTCASE(1, pluralFormatUnitTest
);
37 TESTCASE(2, pluralFormatLocaleTest
);
44 * Test various generic API methods of PluralFormat for Basic usage.
46 void PluralFormatTest::pluralFormatBasicTest(/*char *par*/)
49 PluralFormat
* plFmt
[8];
50 Locale locale
= Locale::getDefault();
51 UnicodeString otherPattern
= UnicodeString("other{#}");
52 UnicodeString message
=UnicodeString("ERROR: PluralFormat basic test");
54 // ========= Test constructors
55 logln(" Testing PluralFormat constructors ...");
56 status
[0] = U_ZERO_ERROR
;
57 PluralRules
* plRules
= PluralRules::createDefaultRules(status
[0]);
59 status
[0] = U_ZERO_ERROR
;
60 NumberFormat
*numFmt
= NumberFormat::createInstance(status
[0]);
61 if (U_FAILURE(status
[0])) {
62 dataerrln("ERROR: Could not create NumberFormat instance with default locale ");
65 for (int32_t i
=0; i
< 8; ++i
) {
66 status
[i
] = U_ZERO_ERROR
;
68 plFmt
[0] = new PluralFormat(status
[0]);
69 plFmt
[1] = new PluralFormat(*plRules
, status
[1]);
70 plFmt
[2] = new PluralFormat(locale
, status
[2]);
71 plFmt
[3] = new PluralFormat(locale
, *plRules
, status
[3]);
72 plFmt
[4] = new PluralFormat(otherPattern
, status
[4]);
73 plFmt
[5] = new PluralFormat(*plRules
, otherPattern
, status
[5]);
74 plFmt
[6] = new PluralFormat(locale
, otherPattern
, status
[6]);
75 plFmt
[7] = new PluralFormat(locale
, *plRules
, otherPattern
, status
[7]);
77 for (int32_t i
=0; i
< 8; ++i
) {
78 if (U_SUCCESS(status
[i
])) {
79 numberFormatTest(plFmt
[i
], numFmt
, 1, 12, NULL
, NULL
, FALSE
, &message
);
80 numberFormatTest(plFmt
[i
], numFmt
, 100, 112, NULL
, NULL
, FALSE
, &message
);
83 dataerrln("ERROR: PluralFormat constructor failed!");
87 // ======= Test clone, assignment operator && == operator.
88 plFmt
[0]= new PluralFormat(status
[0]);
89 plFmt
[0]->setNumberFormat(numFmt
,status
[0]);
90 UnicodeString us
= UnicodeString("");
91 plFmt
[0]->toPattern(us
);
92 plFmt
[1]= new PluralFormat(locale
, status
[1]);
93 if ( U_SUCCESS(status
[0]) && U_SUCCESS(status
[1]) ) {
94 *plFmt
[1] = *plFmt
[0];
96 if ( *plFmt
[1] != *plFmt
[0] ) {
97 errln("ERROR: clone plural format test failed!");
102 dataerrln("ERROR: PluralFormat constructor failed! - [0]%s [1]%s", u_errorName(status
[0]), u_errorName(status
[1]));
106 status
[0] = U_ZERO_ERROR
;
107 plFmt
[0]= new PluralFormat(locale
, status
[0]);
108 if ( U_SUCCESS(status
[0]) ) {
109 *plFmt
[1] = *plFmt
[0];
110 if (plFmt
[1]!=NULL
) {
111 if ( *plFmt
[1] != *plFmt
[0] ) {
112 errln("ERROR: assignment operator test failed!");
117 dataerrln("ERROR: PluralFormat constructor failed! - %s", u_errorName(status
[1]));
120 if ( U_SUCCESS(status
[1]) ) {
121 plFmt
[2] = (PluralFormat
*) plFmt
[1]->clone();
123 if (plFmt
[1]!=NULL
) {
124 if ( *plFmt
[1] != *plFmt
[2] ) {
125 errln("ERROR: clone function test failed!");
132 dataerrln("ERROR: PluralFormat clone failed! - %s", u_errorName(status
[1]));
140 UErrorCode stat
= U_ZERO_ERROR
;
141 PluralFormat
*pf
= new PluralFormat(stat
);
142 Formattable
*f
= new Formattable();
143 ParsePosition
*pp
= new ParsePosition();
144 pf
->parseObject((UnicodeString
)"",*f
,*pp
);
145 if(U_FAILURE(stat
)) {
146 dataerrln("ERROR: PluralFormat::parseObject: %s", u_errorName(stat
));
154 * Unit tests of PluralFormat class.
156 void PluralFormatTest::pluralFormatUnitTest(/*char *par*/)
158 UnicodeString patternTestData
[PLURAL_PATTERN_DATA
] = {
159 UNICODE_STRING_SIMPLE("odd {# is odd.} other{# is even.}"),
160 UNICODE_STRING_SIMPLE("other{# is odd or even.}"),
161 UNICODE_STRING_SIMPLE("odd{The number {0, number, #.#0} is odd.}other{The number {0, number, #.#0} is even.}"),
162 UNICODE_STRING_SIMPLE("odd{The number {#} is odd.}other{The number {#} is even.}"),
164 UnicodeString patternOddTestResult
[PLURAL_PATTERN_DATA
] = {
165 UNICODE_STRING_SIMPLE(" is odd."),
166 UNICODE_STRING_SIMPLE(" is odd or even."),
167 UNICODE_STRING_SIMPLE("The number {0, number, #.#0} is odd."),
168 UNICODE_STRING_SIMPLE("The number {#} is odd."),
170 UnicodeString patternEvenTestResult
[PLURAL_PATTERN_DATA
] = {
171 UNICODE_STRING_SIMPLE(" is even."),
172 UNICODE_STRING_SIMPLE(" is odd or even."),
173 UNICODE_STRING_SIMPLE("The number {0, number, #.#0} is even."),
174 UNICODE_STRING_SIMPLE("The number {#} is even."),
176 UnicodeString checkSyntaxtData
[PLURAL_SYNTAX_DATA
] = {
177 UNICODE_STRING_SIMPLE("odd{foo} odd{bar} other{foobar}"),
178 UNICODE_STRING_SIMPLE("odd{foo} other{bar} other{foobar}"),
179 UNICODE_STRING_SIMPLE("odd{foo}"),
180 UNICODE_STRING_SIMPLE("otto{foo} other{bar}"),
181 UNICODE_STRING_SIMPLE("1odd{foo} other{bar}"),
182 UNICODE_STRING_SIMPLE("odd{foo},other{bar}"),
183 UNICODE_STRING_SIMPLE("od d{foo} other{bar}"),
184 UNICODE_STRING_SIMPLE("odd{foo}{foobar}other{foo}"),
187 UErrorCode status
= U_ZERO_ERROR
;
188 UnicodeString oddAndEvenRule
= UNICODE_STRING_SIMPLE("odd: n mod 2 is 1");
189 PluralRules
* plRules
= PluralRules::createRules(oddAndEvenRule
, status
);
190 if (U_FAILURE(status
)) {
191 dataerrln("ERROR: create PluralRules instance failed in unit tests.- exitting");
195 // ======= Test PluralRules pattern syntax.
196 logln("Testing PluralRules pattern syntax.");
197 for (int32_t i
=0; i
<PLURAL_SYNTAX_DATA
; ++i
) {
198 status
= U_ZERO_ERROR
;
200 PluralFormat plFmt
=PluralFormat(*plRules
, status
);
201 if (U_FAILURE(status
)) {
202 dataerrln("ERROR: PluralFormat constructor failed in unit tests.- exitting");
205 plFmt
.applyPattern(checkSyntaxtData
[i
], status
);
206 if (U_SUCCESS(status
)) {
207 errln("ERROR: PluralFormat failed to detect syntax error with pattern: "+checkSyntaxtData
[i
]);
213 // ======= Test applying various pattern
214 logln("Testing various patterns");
215 status
= U_ZERO_ERROR
;
216 UBool overwrite
[PLURAL_PATTERN_DATA
] = {FALSE
, FALSE
, TRUE
, TRUE
};
218 NumberFormat
*numFmt
= NumberFormat::createInstance(status
);
219 UnicodeString message
=UnicodeString("ERROR: PluralFormat tests various pattern ...");
220 if (U_FAILURE(status
)) {
221 dataerrln("ERROR: Could not create NumberFormat instance with default locale ");
223 for(int32_t i
=0; i
<PLURAL_PATTERN_DATA
; ++i
) {
224 status
= U_ZERO_ERROR
;
225 PluralFormat plFmt
=PluralFormat(*plRules
, status
);
226 if (U_FAILURE(status
)) {
227 dataerrln("ERROR: PluralFormat constructor failed in unit tests.- exitting");
230 plFmt
.applyPattern(patternTestData
[i
], status
);
231 if (U_FAILURE(status
)) {
232 errln("ERROR: PluralFormat failed to apply pattern- "+patternTestData
[i
]);
235 numberFormatTest(&plFmt
, numFmt
, 1, 10, (UnicodeString
*)&patternOddTestResult
[i
],
236 (UnicodeString
*)&patternEvenTestResult
[i
], overwrite
[i
], &message
);
241 // ======= Test set locale
242 status
= U_ZERO_ERROR
;
243 plRules
= PluralRules::createRules(UNICODE_STRING_SIMPLE("odd: n mod 2 is 1"), status
);
244 PluralFormat pluralFmt
= PluralFormat(*plRules
, status
);
245 if (U_FAILURE(status
)) {
246 dataerrln("ERROR: Could not create PluralFormat instance in setLocale() test - exitting. ");
250 pluralFmt
.applyPattern(UNICODE_STRING_SIMPLE("odd{odd} other{even}"), status
);
251 pluralFmt
.setLocale(Locale::getEnglish(), status
);
252 if (U_FAILURE(status
)) {
253 dataerrln("ERROR: Could not setLocale() with English locale ");
257 message
= UNICODE_STRING_SIMPLE("Error set locale: pattern is not reset!");
259 // Check that pattern gets deleted.
260 logln("\n Test setLocale() ..\n");
261 numFmt
= NumberFormat::createInstance(Locale::getEnglish(), status
);
262 if (U_FAILURE(status
)) {
263 dataerrln("ERROR: Could not create NumberFormat instance with English locale ");
265 numberFormatTest(&pluralFmt
, numFmt
, 5, 5, NULL
, NULL
, FALSE
, &message
);
266 pluralFmt
.applyPattern(UNICODE_STRING_SIMPLE("odd__{odd} other{even}"), status
);
267 if (U_SUCCESS(status
)) {
268 errln("SetLocale should reset rules but did not.");
270 status
= U_ZERO_ERROR
;
271 pluralFmt
.applyPattern(UNICODE_STRING_SIMPLE("one{one} other{not one}"), status
);
272 if (U_FAILURE(status
)) {
273 errln("SetLocale should reset rules but did not.");
275 UnicodeString one
= UNICODE_STRING_SIMPLE("one");
276 UnicodeString notOne
= UNICODE_STRING_SIMPLE("not one");
277 UnicodeString plResult
, numResult
;
278 for (int32_t i
=0; i
<20; ++i
) {
279 plResult
= pluralFmt
.format(i
, status
);
286 if ( numResult
!= plResult
) {
287 errln("Wrong ruleset loaded by setLocale() - got:"+plResult
+ UnicodeString(" expecting:")+numResult
);
291 // =========== Test copy constructor
292 logln("Test copy constructor and == operator of PluralFormat");
293 PluralFormat dupPFmt
= PluralFormat(pluralFmt
);
294 if (pluralFmt
!= dupPFmt
) {
295 errln("Failed in PluralFormat copy constructor or == operator");
305 * Test locale data used in PluralFormat class.
308 PluralFormatTest::pluralFormatLocaleTest(/*char *par*/)
310 int8_t pluralResults
[PLURAL_TEST_ARRAY_SIZE
]; // 0: is for default
312 // ======= Test DefaultRule
313 logln("Testing PluralRules with no rule.");
314 const char* oneRuleLocales
[4] = {"ja", "ko", "tr", "vi"};
315 UnicodeString testPattern
= UNICODE_STRING_SIMPLE("other{other}");
316 uprv_memset(pluralResults
, -1, sizeof(pluralResults
));
317 pluralResults
[0]= PFT_OTHER
; // other
318 helperTestRusults(oneRuleLocales
, 4, testPattern
, pluralResults
);
320 // ====== Test Singular1 locales.
321 logln("Testing singular1 locales.");
322 const char* singular1Locales
[52] = {"bem","da","de","el","en","eo","es","et","fi",
323 "fo","gl","he","it","nb","nl","nn","no","pt","pt_PT","sv","af","bg","bn","ca","eu","fur","fy",
324 "gu","ha","is","ku","lb","ml","mr","nah","ne","om","or","pa","pap","ps","so","sq","sw","ta",
325 "te","tk","ur","zu","mn","gsw","rm"};
326 testPattern
= UNICODE_STRING_SIMPLE("one{one} other{other}");
327 uprv_memset(pluralResults
, -1, sizeof(pluralResults
));
328 pluralResults
[0]= PFT_OTHER
;
329 pluralResults
[1]= PFT_ONE
;
330 pluralResults
[2]= PFT_OTHER
;
331 helperTestRusults(singular1Locales
, 52, testPattern
, pluralResults
);
333 // ======== Test Singular01 locales.
334 logln("Testing singular1 locales.");
335 const char* singular01Locales
[3] = {"ff","fr","kab"};
336 testPattern
= UNICODE_STRING_SIMPLE("one{one} other{other}");
337 uprv_memset(pluralResults
, -1, sizeof(pluralResults
));
338 pluralResults
[0]= PFT_ONE
;
339 pluralResults
[2]= PFT_OTHER
;
340 helperTestRusults(singular01Locales
, 3, testPattern
, pluralResults
);
342 // ======== Test ZeroSingular locales.
343 logln("Testing singular1 locales.");
344 const char* zeroSingularLocales
[1] = {"lv"};
345 testPattern
= UNICODE_STRING_SIMPLE("zero{zero} one{one} other{other}");
346 uprv_memset(pluralResults
, -1, sizeof(pluralResults
));
347 pluralResults
[0]= PFT_ZERO
;
348 pluralResults
[1]= PFT_ONE
;
349 pluralResults
[2]= PFT_OTHER
;
350 for (int32_t i
=2; i
<20; ++i
) {
352 pluralResults
[i
*10+1] = PFT_ONE
;
353 pluralResults
[i
*10+2] = PFT_OTHER
;
355 helperTestRusults(zeroSingularLocales
, 1, testPattern
, pluralResults
);
357 // ======== Test singular dual locales.
358 logln("Testing singular1 locales.");
359 const char* singularDualLocales
[1] = {"ga"};
360 testPattern
= UNICODE_STRING_SIMPLE("one{one} two{two} other{other}");
361 uprv_memset(pluralResults
, -1, sizeof(pluralResults
));
362 pluralResults
[0]= PFT_OTHER
;
363 pluralResults
[1]= PFT_ONE
;
364 pluralResults
[2]= PFT_TWO
;
365 pluralResults
[3]= PFT_OTHER
;
366 helperTestRusults(singularDualLocales
, 1, testPattern
, pluralResults
);
368 // ======== Test Singular Zero Some locales.
369 logln("Testing singular1 locales.");
370 const char* singularZeroSomeLocales
[1] = {"ro"};
371 testPattern
= UNICODE_STRING_SIMPLE("few{few} one{one} other{other}");
372 uprv_memset(pluralResults
, -1, sizeof(pluralResults
));
373 pluralResults
[0]= PFT_FEW
;
374 for (int32_t i
=1; i
<20; ++i
) {
376 pluralResults
[i
] = PFT_FEW
;
377 pluralResults
[100+i
] = PFT_FEW
;
379 pluralResults
[1]= PFT_ONE
;
380 helperTestRusults(singularZeroSomeLocales
, 1, testPattern
, pluralResults
);
382 // ======== Test Special 12/19.
383 logln("Testing special 12 and 19.");
384 const char* special12_19Locales
[1] = {"lt"};
385 testPattern
= UNICODE_STRING_SIMPLE("one{one} few{few} other{other}");
386 uprv_memset(pluralResults
, -1, sizeof(pluralResults
));
387 pluralResults
[0]= PFT_OTHER
;
388 pluralResults
[1]= PFT_ONE
;
389 pluralResults
[2]= PFT_FEW
;
390 pluralResults
[10]= PFT_OTHER
;
391 for (int32_t i
=2; i
<20; ++i
) {
393 pluralResults
[i
*10+1] = PFT_ONE
;
394 pluralResults
[i
*10+2] = PFT_FEW
;
395 pluralResults
[(i
+1)*10] = PFT_OTHER
;
397 helperTestRusults(special12_19Locales
, 1, testPattern
, pluralResults
);
399 // ======== Test Paucal Except 11 14.
400 logln("Testing Paucal Except 11 and 14.");
401 const char* paucal01Locales
[4] = {"hr","ru","sr","uk"};
402 testPattern
= UNICODE_STRING_SIMPLE("one{one} many{many} few{few} other{other}");
403 uprv_memset(pluralResults
, -1, sizeof(pluralResults
));
404 pluralResults
[0]= PFT_MANY
;
405 pluralResults
[1]= PFT_ONE
;
406 pluralResults
[2]= PFT_FEW
;
407 pluralResults
[5]= PFT_MANY
;
408 pluralResults
[6]= PFT_MANY
;
409 pluralResults
[7]= PFT_MANY
;
410 pluralResults
[8]= PFT_MANY
;
411 pluralResults
[9]= PFT_MANY
;
412 for (int32_t i
=2; i
<20; ++i
) {
414 pluralResults
[i
*10+1] = PFT_ONE
;
415 pluralResults
[i
*10+2] = PFT_FEW
;
416 pluralResults
[i
*10+5] = PFT_MANY
;
417 pluralResults
[i
*10+6] = PFT_MANY
;
418 pluralResults
[i
*10+7] = PFT_MANY
;
419 pluralResults
[i
*10+8] = PFT_MANY
;
420 pluralResults
[i
*10+9] = PFT_MANY
;
422 helperTestRusults(paucal01Locales
, 4, testPattern
, pluralResults
);
424 // ======== Test Singular Paucal.
425 logln("Testing Singular Paucal.");
426 const char* singularPaucalLocales
[2] = {"cs","sk"};
427 testPattern
= UNICODE_STRING_SIMPLE("one{one} few{few} other{other}");
428 uprv_memset(pluralResults
, -1, sizeof(pluralResults
));
429 pluralResults
[0]= PFT_OTHER
;
430 pluralResults
[1]= PFT_ONE
;
431 pluralResults
[2]= PFT_FEW
;
432 pluralResults
[5]= PFT_OTHER
;
433 helperTestRusults(singularPaucalLocales
, 2, testPattern
, pluralResults
);
435 // ======== Test Paucal (1), (2,3,4).
436 logln("Testing Paucal (1), (2,3,4).");
437 const char* paucal02Locales
[1] = {"pl"};
438 testPattern
= UNICODE_STRING_SIMPLE("one{one} few{few} other{other}");
439 uprv_memset(pluralResults
, -1, sizeof(pluralResults
));
440 pluralResults
[0]= PFT_OTHER
;
441 pluralResults
[1]= PFT_ONE
;
442 pluralResults
[5]= PFT_OTHER
;
443 for (int32_t i
=0; i
<20; ++i
) {
444 if ((i
==1)||(i
==11)) {
445 pluralResults
[i
*10+2] = PFT_OTHER
;
446 pluralResults
[i
*10+3] = PFT_OTHER
;
447 pluralResults
[i
*10+4] = PFT_OTHER
;
450 pluralResults
[i
*10+2] = PFT_FEW
;
451 pluralResults
[i
*10+3] = PFT_FEW
;
452 pluralResults
[i
*10+4] = PFT_FEW
;
453 pluralResults
[i
*10+5] = PFT_OTHER
;
456 helperTestRusults(paucal02Locales
, 1, testPattern
, pluralResults
);
458 // ======== Test Paucal (1), (2), (3,4).
459 logln("Testing Paucal (1), (2), (3,4).");
460 const char* paucal03Locales
[1] = {"sl"};
461 testPattern
= UNICODE_STRING_SIMPLE("one{one} two{two} few{few} other{other}");
462 uprv_memset(pluralResults
, -1, sizeof(pluralResults
));
463 pluralResults
[0]= PFT_OTHER
;
464 pluralResults
[1]= PFT_ONE
;
465 pluralResults
[2]= PFT_TWO
;
466 pluralResults
[3]= PFT_FEW
;
467 pluralResults
[5]= PFT_OTHER
;
468 pluralResults
[101]= PFT_ONE
;
469 pluralResults
[102]= PFT_TWO
;
470 pluralResults
[103]= PFT_FEW
;
471 pluralResults
[105]= PFT_OTHER
;
472 helperTestRusults(paucal03Locales
, 1, testPattern
, pluralResults
);
474 // TODO: move this test to Unit Test after CLDR 1.6 is final and we support float
475 // ======= Test French "WITHIN rule
476 logln("Testing PluralRules with fr rule.");
477 testPattern
= UNICODE_STRING_SIMPLE("one{one} other{other}");
478 Locale
ulocale((const char *)"fr");
479 UErrorCode status
= U_ZERO_ERROR
;
480 PluralFormat
plFmt(ulocale
, testPattern
, status
);
481 if (U_FAILURE(status
)) {
482 dataerrln("Failed to apply pattern to fr locale - %s", u_errorName(status
));
485 status
= U_ZERO_ERROR
;
486 UnicodeString plResult
= plFmt
.format(0.0, status
); // retrun ONE
487 plResult
= plFmt
.format(0.5, status
); // retrun ONE
488 plResult
= plFmt
.format(1.0, status
); // retrun ONE
489 plResult
= plFmt
.format(1.9, status
); // retrun ONE
490 plResult
= plFmt
.format(2.0, status
); // retrun OTHER
495 PluralFormatTest::numberFormatTest(PluralFormat
* plFmt
,
496 NumberFormat
*numFmt
,
499 UnicodeString
*numOddAppendStr
,
500 UnicodeString
*numEvenAppendStr
,
501 UBool overwrite
, // overwrite the numberFormat.format result
502 UnicodeString
*message
) {
503 UErrorCode status
= U_ZERO_ERROR
;
505 if ( (plFmt
==NULL
) || (numFmt
==NULL
) ) {
506 dataerrln("ERROR: Could not create PluralFormat or NumberFormat - exitting");
509 UnicodeString plResult
, numResult
;
511 for (int32_t i
=start
; i
<= end
; ++i
) {
513 numResult
= numFmt
->format(i
, numResult
);
514 plResult
= plFmt
->format(i
, status
);
515 if ((numOddAppendStr
!= NULL
)&&(numEvenAppendStr
!=NULL
)) {
518 numResult
= *numOddAppendStr
;
521 numResult
= *numEvenAppendStr
;
524 else { // Append the string
526 numResult
+= *numOddAppendStr
;
529 numResult
+= *numEvenAppendStr
;
533 if ( (numResult
!=plResult
) || U_FAILURE(status
) ) {
534 if ( message
== NULL
) {
535 errln("ERROR: Unexpected plural format - got:"+plResult
+ UnicodeString(" expecting:")+numResult
);
538 errln( *message
+UnicodeString(" got:")+plResult
+UnicodeString(" expecting:")+numResult
);
548 PluralFormatTest::helperTestRusults(const char** localeArray
,
549 int32_t capacityOfArray
,
550 UnicodeString
& testPattern
,
551 int8_t *expResults
) {
553 UnicodeString plResult
;
554 const UnicodeString PLKeywordLookups
[6] = {
555 UNICODE_STRING_SIMPLE("zero"),
556 UNICODE_STRING_SIMPLE("one"),
557 UNICODE_STRING_SIMPLE("two"),
558 UNICODE_STRING_SIMPLE("few"),
559 UNICODE_STRING_SIMPLE("many"),
560 UNICODE_STRING_SIMPLE("other"),
563 for (int32_t i
=0; i
<capacityOfArray
; ++i
) {
564 const char *locale
= localeArray
[i
];
565 Locale
ulocale((const char *)locale
);
566 status
= U_ZERO_ERROR
;
567 PluralFormat
plFmt(ulocale
, testPattern
, status
);
568 if (U_FAILURE(status
)) {
569 dataerrln("Failed to apply pattern to locale:"+UnicodeString(localeArray
[i
]) + " - " + u_errorName(status
));
572 for (int32_t n
=0; n
<PLURAL_TEST_ARRAY_SIZE
; ++n
) {
573 if (expResults
[n
]!=-1) {
574 status
= U_ZERO_ERROR
;
575 plResult
= plFmt
.format(n
, status
);
576 if (U_FAILURE(status
)) {
577 errln("ERROR: Failed to format number in locale data tests with locale: "+
578 UnicodeString(localeArray
[i
]));
580 if (plResult
!= PLKeywordLookups
[expResults
[n
]]){
581 plResult
= plFmt
.format(n
, status
);
582 errln("ERROR: Unexpected format result in locale: "+UnicodeString(localeArray
[i
])+
583 UnicodeString(" got:")+plResult
+ UnicodeString(" expecting:")+
584 PLKeywordLookups
[expResults
[n
]]);
591 #endif /* #if !UCONFIG_NO_FORMATTING */