Skip to content

Commit

Permalink
Prepare tests for ICU 62.1
Browse files Browse the repository at this point in the history
  • Loading branch information
weltling committed Jun 25, 2018
1 parent 701460b commit 5af0db8
Show file tree
Hide file tree
Showing 12 changed files with 356 additions and 5 deletions.
1 change: 1 addition & 0 deletions ext/intl/tests/bug62070_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Bug #62070: Collator::getSortKey() returns garbage
--SKIPIF--
<?php if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '53.1') < 0) die('skip for ICU >= 53.1'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '62.1') >= 0) die('skip for ICU < 62.1'); ?>
--FILE--
<?php
$s1 = 'Hello';
Expand Down
15 changes: 15 additions & 0 deletions ext/intl/tests/bug62070_3.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Bug #62070: Collator::getSortKey() returns garbage
--SKIPIF--
<?php if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '62.1') < 0) die('skip for ICU >= 62.1'); ?>
--FILE--
<?php
$s1 = 'Hello';

$coll = collator_create('en_US');
$res = collator_get_sort_key($coll, $s1);

echo urlencode($res);
--EXPECT--
82%40%40F%01%09%01%DC%08
1 change: 1 addition & 0 deletions ext/intl/tests/collator_get_sort_key_variant6.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ collator_get_sort_key() icu >= 56.1
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
<?php if (version_compare(INTL_ICU_VERSION, '56.1') < 0) die('skip for ICU >= 56.1'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '62.1') >= 0) die('skip for ICU < 62.1'); ?>
--FILE--
<?php

Expand Down
98 changes: 98 additions & 0 deletions ext/intl/tests/collator_get_sort_key_variant7.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
--TEST--
collator_get_sort_key() icu >= 62.1
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
<?php if (version_compare(INTL_ICU_VERSION, '62.1') < 0) die('skip for ICU >= 62.1'); ?>
--FILE--
<?php

/*
* Get sort keys using various locales
*/
function sort_arrays( $locale, $data )
{
$res_str = '';

$coll = ut_coll_create( $locale );

foreach($data as $value) {
$res_val = ut_coll_get_sort_key( $coll, $value );
$res_str .= "source: ".$value."\n".
"key: ".bin2hex($res_val)."\n";
}

return $res_str;
}


function ut_main()
{
$res_str = '';

// Regular strings keys
$test_params = array(
'abc', 'abd', 'aaa',
'аа', 'а', 'z',
'', null , '3',
'y' , 'i' , 'k'
);

$res_str .= sort_arrays( 'en_US', $test_params );

// Sort a non-ASCII array using ru_RU locale.
$test_params = array(
'абг', 'абв', 'жжж', 'эюя'
);

$res_str .= sort_arrays( 'ru_RU', $test_params );

// Sort an array using Lithuanian locale.
$res_str .= sort_arrays( 'lt_LT', $test_params );

return $res_str . "\n";
}

include_once( 'ut_common.inc' );
ut_run();
?>
--EXPECT--
source: abc
key: 2a2c2e01070107
source: abd
key: 2a2c3001070107
source: aaa
key: 2a2a2a01070107
source: аа
key: 61060601060106
source: а
key: 610601050105
source: z
key: 5c01050105
source:
key: 0101
source:
key: 0101
source: 3
key: 1901050105
source: y
key: 5a01050105
source: i
key: 3a01050105
source: k
key: 3e01050105
source: абг
key: 27060c1001070107
source: абв
key: 27060c0e01070107
source: жжж
key: 272c2c2c01070107
source: эюя
key: 27eef0f401070107
source: абг
key: 61060c1001070107
source: абв
key: 61060c0e01070107
source: жжж
key: 612c2c2c01070107
source: эюя
key: 61eef0f401070107
3 changes: 2 additions & 1 deletion ext/intl/tests/formatter_format7.phpt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
--TEST--
numfmt_format() icu >= 61.1
numfmt_format() icu >= 61.1 && < 62.1
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
<?php if (version_compare(INTL_ICU_VERSION, '61.1') < 0) die('skip for ICU >= 61.1'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '62.1') >= 0) die('skip for ICU < 62.1'); ?>
--FILE--
<?php

Expand Down
130 changes: 130 additions & 0 deletions ext/intl/tests/formatter_format8.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
--TEST--
numfmt_format() icu >= 62.1
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
<?php if (version_compare(INTL_ICU_VERSION, '62.1') < 0) die('skip for ICU >= 62.1'); ?>
--FILE--
<?php

/*
* Format a number using misc locales/patterns.
*/

/*
* TODO: doesn't pass on ICU 3.6 because 'ru' and 'de' locales changed
* currency and percent formatting.
*/

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
);

$integer = array(
NumberFormatter::ORDINAL => '',
NumberFormatter::DURATION => '',
);
$locales = array(
'en_US',
'ru_UA',
'de',
'fr',
'en_UK'
);

$str_res = '';
$number = 1234567.891234567890000;

foreach( $locales as $locale )
{
$str_res .= "\nLocale is: $locale\n";
foreach( $styles as $style => $pattern )
{
$fmt = ut_nfmt_create( $locale, $style, $pattern );

if(!$fmt) {
$str_res .= "Bad formatter!\n";
continue;
}
$str_res .= dump( isset($integer[$style])?ut_nfmt_format( $fmt, $number, NumberFormatter::TYPE_INT32):ut_nfmt_format( $fmt, $number ) ) . "\n";
}
}
return $str_res;
}

include_once( 'ut_common.inc' );

// Run the test
ut_run();

?>
--EXPECTREGEX--
Locale is: en_US
'1234567.8912345\d+'
'1,234,567.891'
'\$1,234,567.89'
'123,456,789%'
'1.2345678912345\d+E6'
'one million,? two hundred (and )?thirty-four thousand,? five hundred (and )?sixty-seven point eight nine one two three four five( six)? seven( nine)?'
'1,234,567(th|ᵗʰ)'
'342:56:07'
'#####.###'
'USD 1,234,567.89'

Locale is: ru_UA
'1234567.8912345\d+'
'1 234 567,891'
'1 234 567,89 ?(грн\.|₴)'
'123 456 789 ?%'
'1.2345678912345\d+E6'
'один миллион двести тридцать четыре тысячи пятьсот шестьдесят семь целых восемьдесят девять миллионов сто двадцать три тысячи четыреста пятьдесят семь стомиллионных'
'1 234 567.?'
'1 234 567'
'#####.###'
'1 234 567,89 UAH'

Locale is: de
'1234567.8912345\d+'
'1.234.567,891'
'1.234.567,89 XXX'
'123\.456\.789 %'
'1.2345678912345\d+E6'
'eine Million zwei­hundert­vier­und­dreißig­tausend­fünf­hundert­sieben­und­sechzig Komma acht neun eins zwei drei vier fünf( sechs)? sieben( neun)?'
'1.234.567.?'
'1.234.567'
'#####.###'
'1.234.567,89 XXX'

Locale is: fr
'1234567.8912345\d+'
'1 234 567,891'
'1 234 567,89 XXX'
'123 456 789 ?%'
'1.2345678912345\d+E6'
'un million deux cent trente-quatre mille cinq cent soixante-sept virgule huit neuf un deux trois quatre cinq( six)? sept( neuf)?'
'1 234 567e'
'1 234 567'
'#####.###'
'1 234 567,89 XXX'

Locale is: en_UK
'1234567.8912345\d+'
'1,234,567.891'
'XXX 1,234,567.89'
'123,456,789%'
'1.2345678912345\d+E6'
'one million,? two hundred (and )?thirty-four thousand,? five hundred (and )?sixty-seven point eight nine one two three four five( six)? seven( nine)?'
'1,234,567(th|ᵗʰ)'
'342:56:07'
'#####.###'
'XXX 1,234,567.89'
4 changes: 2 additions & 2 deletions ext/intl/tests/formatter_format_currency2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ include_once( 'ut_common.inc' );
ut_run();

?>
--EXPECT--
--EXPECTF--
en_UK: '£1,234,567.89'
en_US: '$1,234,567.89'
ru: '1 234 567,89 р.'
uk: '1 234 567,89 ₴'
en: 'UAH1,234,567.89'
en: 'UAH%A1,234,567.89'
1 change: 1 addition & 0 deletions ext/intl/tests/formatter_get_locale_variant3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ numfmt_get_locale()
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
<?php if (version_compare(INTL_ICU_VERSION, '58.1') < 0) die('skip for ICU >= 58.1'); ?>
<?php if (version_compare(INTL_ICU_VERSION, '62.1') >= 0) die('skip for ICU < 62.1'); ?>
--FILE--
<?php

Expand Down
50 changes: 50 additions & 0 deletions ext/intl/tests/formatter_get_locale_variant4.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--TEST--
numfmt_get_locale()
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
<?php if (version_compare(INTL_ICU_VERSION, '62.1') < 0) die('skip for ICU >= 62.1'); ?>
--FILE--
<?php

/*
* Get locale.
*/

function ut_main()
{
$locales = array(
'en_UK',
'en_US',
'fr_CA',
);

$loc_types = array(
Locale::ACTUAL_LOCALE => 'actual',
Locale::VALID_LOCALE => 'valid',
);

$res_str = '';

foreach( $locales as $locale )
{
$fmt = ut_nfmt_create( $locale, NumberFormatter::DECIMAL );
$res_str .= "$locale: ";
foreach( $loc_types as $loc_type => $loc_type_name )
$res_str .= sprintf( " %s=%s",
$loc_type_name,
dump( ut_nfmt_get_locale( $fmt, $loc_type ) ) );
$res_str .= "\n";
}

return $res_str;
}

include_once( 'ut_common.inc' );

// Run the test
ut_run();
?>
--EXPECT--
en_UK: actual='en' valid='en'
en_US: actual='en_US' valid='en_US'
fr_CA: actual='fr_CA' valid='fr_CA'
1 change: 1 addition & 0 deletions ext/intl/tests/formatter_get_set_pattern.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
numfmt_get/set_pattern()
--SKIPIF--
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
<?php if (version_compare(INTL_ICU_VERSION, '62.1') >= 0) die('skip for ICU < 62.1'); ?>
--FILE--
<?php

Expand Down

0 comments on commit 5af0db8

Please sign in to comment.