]> granicus.if.org Git - php/commitdiff
Prepare tests for ICU 62.1
authorAnatol Belski <ab@php.net>
Mon, 25 Jun 2018 09:30:14 +0000 (11:30 +0200)
committerAnatol Belski <ab@php.net>
Mon, 25 Jun 2018 09:30:14 +0000 (11:30 +0200)
12 files changed:
ext/intl/tests/bug62070_2.phpt
ext/intl/tests/bug62070_3.phpt [new file with mode: 0644]
ext/intl/tests/collator_get_sort_key_variant6.phpt
ext/intl/tests/collator_get_sort_key_variant7.phpt [new file with mode: 0644]
ext/intl/tests/formatter_format7.phpt
ext/intl/tests/formatter_format8.phpt [new file with mode: 0644]
ext/intl/tests/formatter_format_currency2.phpt
ext/intl/tests/formatter_get_locale_variant3.phpt
ext/intl/tests/formatter_get_locale_variant4.phpt [new file with mode: 0644]
ext/intl/tests/formatter_get_set_pattern.phpt
ext/intl/tests/formatter_get_set_pattern2.phpt [new file with mode: 0644]
ext/intl/tests/formatter_get_set_symbol2.phpt

index 63f510793b13ee9f9e3f81983c85ae73b900c73f..c632b569cc7d5bcfcbad85af46bfc196f5785af0 100644 (file)
@@ -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';
diff --git a/ext/intl/tests/bug62070_3.phpt b/ext/intl/tests/bug62070_3.phpt
new file mode 100644 (file)
index 0000000..5510798
--- /dev/null
@@ -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
index d8105d76d4cee3c7a27f9debc274551082ebc862..78c74f546a4c0fe95ee6e9330738138f804ae640 100644 (file)
@@ -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
 
diff --git a/ext/intl/tests/collator_get_sort_key_variant7.phpt b/ext/intl/tests/collator_get_sort_key_variant7.phpt
new file mode 100644 (file)
index 0000000..e009d0e
--- /dev/null
@@ -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
index 088c526c70224790990986b857d646494092a2c2..13d58bdd51139616ea16e55b466bee2d7b422c83 100644 (file)
@@ -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
 
diff --git a/ext/intl/tests/formatter_format8.phpt b/ext/intl/tests/formatter_format8.phpt
new file mode 100644 (file)
index 0000000..55b10ff
--- /dev/null
@@ -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'
index d9277f3e9801dfffd3075e26e3295dde07424eb5..16a421018cfa265c874efb1c58e070a34384ba18 100644 (file)
@@ -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'
index 901e2353b4e802f470a324158d94a27322c937b3..8f3ea8edc715314f62dd620aee10bed3820fc57c 100644 (file)
@@ -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
 
diff --git a/ext/intl/tests/formatter_get_locale_variant4.phpt b/ext/intl/tests/formatter_get_locale_variant4.phpt
new file mode 100644 (file)
index 0000000..a37c271
--- /dev/null
@@ -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'
index 0ae5b308b28484317f2485adf243118880fcd4e6..7f33254e2cdbc12046adf7732d557c8220eb5093 100644 (file)
@@ -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
 
diff --git a/ext/intl/tests/formatter_get_set_pattern2.phpt b/ext/intl/tests/formatter_get_set_pattern2.phpt
new file mode 100644 (file)
index 0000000..7bf98ae
--- /dev/null
@@ -0,0 +1,53 @@
+--TEST--
+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
+
+/*
+ * Get/set pattern.
+ */
+
+
+function ut_main()
+{
+    $res_str = '';
+    $test_value = 12345.123456;
+    $fmt = ut_nfmt_create( "en_US", NumberFormatter::PATTERN_DECIMAL );
+
+    // Get default patten.
+    $res_str .= "Default pattern: '" . ut_nfmt_get_pattern( $fmt ) . "'\n";
+    $res_str .= "Formatting result: " . ut_nfmt_format( $fmt, $test_value ) . "\n";
+
+    // Set a new pattern.
+    $res = ut_nfmt_set_pattern( $fmt, "0.0" );
+    if( $res === false )
+        $res_str .= ut_nfmt_get_error_message( $fmt ) . " (" . ut_nfmt_get_error_code( $fmt ) . ")\n";
+
+    // Check if the pattern has been changed.
+    $res = ut_nfmt_get_pattern( $fmt );
+    if( $res === false )
+        $res_str .= ut_nfmt_get_error_message( $fmt ) . " (" . ut_nfmt_get_error_code( $fmt ) . ")\n";
+    $res_str .= "New pattern: '" . ut_nfmt_get_pattern( $fmt ) . "'\n";
+    $res_str .= "Formatted number: " . ut_nfmt_format( $fmt, $test_value ) . "\n";
+
+       ut_nfmt_set_pattern($fmt, str_repeat('@', 200));        
+       $res_str .= "New pattern: '" . ut_nfmt_get_pattern( $fmt ) . "'\n";
+    $res_str .= "Formatted number: " . ut_nfmt_format( $fmt, $test_value ) . "\n";
+
+    return $res_str;
+}
+
+include_once( 'ut_common.inc' );
+ut_run();
+
+?>
+--EXPECT--
+Default pattern: '#'
+Formatting result: 12345.123456
+New pattern: '0.0'
+Formatted number: 12345.1
+New pattern: '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
+Formatted number: 12345.123456000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
index 3f982cd0631c044a1110d2a598c233a003374489..8e762f350f1d6cd8d4087374390307114bb70c8d 100644 (file)
@@ -88,7 +88,7 @@ include_once( 'ut_common.inc' );
 ut_run();
 
 ?>
---EXPECT--
+--EXPECTF--
 Symbol 'DECIMAL_SEPARATOR_SYMBOL'
 Default symbol: [.]
 New symbol: [_._]
@@ -132,7 +132,7 @@ A number formatted with the new symbol: 1.2345123456E4
 Symbol 'CURRENCY_SYMBOL'
 Default symbol: [$]
 New symbol: [_$_]
-A number formatted with the new symbol: _$_12,345.12
+A number formatted with the new symbol: _$_%A12,345.12
 
 Symbol 'INTL_CURRENCY_SYMBOL'
 Default symbol: [USD]