php-src/ext/intl/tests/formatter_format.phpt

129 lines
3.0 KiB
Plaintext
Raw Normal View History

2008-07-07 22:51:04 +00:00
--TEST--
numfmt_format()
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
--FILE--
<?php
/*
* Format a number using misc locales/patterns.
*/
2008-09-04 19:59:37 +00:00
/*
* TODO: doesn't pass on ICU 3.6 because 'ru' and 'de' locales changed
* currency and percent formatting.
*/
2008-07-07 22:51:04 +00:00
function ut_main()
{
$styles = array(
NumberFormatter::PATTERN_DECIMAL => '##.#####################',
NumberFormatter::DECIMAL => '',
NumberFormatter::CURRENCY => '',
NumberFormatter::PERCENT => '',
NumberFormatter::SCIENTIFIC => '',
NumberFormatter::SPELLOUT => '@@@@@@@',
NumberFormatter::ORDINAL => '',
NumberFormatter::DURATION => '',
NumberFormatter::PATTERN_RULEBASED => '#####.###',
1234999, // bad one
);
2008-09-04 19:59:37 +00:00
$integer = array(
NumberFormatter::ORDINAL => '',
NumberFormatter::DURATION => '',
);
2008-07-07 22:51:04 +00:00
$locales = array(
'en_US',
'ru_UA',
'de',
2008-09-04 19:59:37 +00:00
'fr',
2008-07-07 22:51:04 +00:00
'en_UK'
);
$str_res = '';
$number = 1234567.891234567890000;
foreach( $locales as $locale )
{
2008-09-04 19:59:37 +00:00
$str_res .= "\nLocale is: $locale\n";
2008-07-07 22:51:04 +00:00
foreach( $styles as $style => $pattern )
{
$fmt = ut_nfmt_create( $locale, $style, $pattern );
if(!$fmt) {
$str_res .= "Bad formatter!\n";
continue;
}
2008-09-04 19:59:37 +00:00
$str_res .= dump( isset($integer[$style])?ut_nfmt_format( $fmt, $number, NumberFormatter::TYPE_INT32):ut_nfmt_format( $fmt, $number ) ) . "\n";
2008-07-07 22:51:04 +00:00
}
}
return $str_res;
}
include_once( 'ut_common.inc' );
// Run the test
ut_run();
?>
--EXPECTREGEX--
2008-07-07 22:51:04 +00:00
Locale is: en_US
'1234567.89123457'
'1,234,567.891'
'\$1,234,567.89'
2008-07-07 22:51:04 +00:00
'123,456,789%'
'1.23456789123457E6'
'one million, two hundred and thirty-four thousand, five hundred and sixty-seven point eight nine one two three four five seven'
2008-09-04 19:59:37 +00:00
'1,234,567th'
'342:56:07'
2008-07-07 22:51:04 +00:00
'#####.###'
Bad formatter!
2008-09-04 19:59:37 +00:00
Locale is: ru_UA
2008-07-07 22:51:04 +00:00
'1234567,89123457'
'1 234 567,891'
'1 234 567,89 грн.'
'123 456 789 ?%'
2008-07-07 22:51:04 +00:00
'1,23456789123457E6'
'миллион два сто тридцать четыре тысяча пять сто шестьдесят восемь'
2008-09-04 19:59:37 +00:00
'1 234 567'
'1 234 567'
2008-07-07 22:51:04 +00:00
'#####.###'
Bad formatter!
2008-09-04 19:59:37 +00:00
Locale is: de
2008-07-07 22:51:04 +00:00
'1234567,89123457'
'1.234.567,891'
'(¤ )?1.234.567,89( ¤)?'
'123.456.789 ?%'
2008-07-07 22:51:04 +00:00
'1,23456789123457E6'
'eine Million zweihundertvierunddreißigtausendfünfhundertsiebenundsechzig komma acht neun eins zwei drei vier fünf sieben'
2008-09-04 19:59:37 +00:00
'1.234.567'
'1.234.567'
'#####.###'
Bad formatter!
Locale is: fr
'1234567,89123457'
'1 234 567,891'
'1 234 567,89 ¤'
'123 456 789 ?%'
2008-09-04 19:59:37 +00:00
'1,23456789123457E6'
'un million deux cents trente-quatre mille cinq cents soixante-sept virgule huit neuf un deux trois quatre cinq sept'
'1 234 567'
'1 234 567'
2008-07-07 22:51:04 +00:00
'#####.###'
Bad formatter!
2008-09-04 19:59:37 +00:00
Locale is: en_UK
2008-07-07 22:51:04 +00:00
'1234567.89123457'
'1,234,567.891'
'¤1,234,567.89'
'123,456,789%'
'1.23456789123457E6'
'one million, two hundred and thirty-four thousand, five hundred and sixty-seven point eight nine one two three four five seven'
2008-09-04 19:59:37 +00:00
'1,234,567th'
'342:56:07'
2008-07-07 22:51:04 +00:00
'#####.###'
2008-09-04 19:59:37 +00:00
Bad formatter!