php-src/ext/intl/tests/collator_compare.phpt
Nikita Popov 7485978339
Migrate SKIPIF -> EXTENSIONS (#7138)
This is an automated migration of most SKIPIF extension_loaded checks.
2021-06-11 11:57:42 +02:00

137 lines
3.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--TEST--
compare()
--EXTENSIONS--
intl
--SKIPIF--
<?php if (version_compare(INTL_ICU_VERSION, '51.2') >= 0) die('skip for ICU < 51.2'); ?>
--FILE--
<?php
/*
* Compare various string pairs using various locales.
*/
/*
* Converts comparison result to a character.
*/
function cmp_to_char( $comp_res )
{
switch( $comp_res )
{
case 0: // UCOL_EQUAL
return '=';
case 1: // UCOL_GREATER
return '>';
case -1: // UCOL_LESS
return '<';
default:
return '?';
}
}
/*
* Compare string pairs in the given array
* using specified locale.
*/
function compare_pairs( $locale, $test_array )
{
$res_str = '';
$coll = ut_coll_create( $locale );
foreach( $test_array as $test_strings )
{
list( $str1, $str2 ) = $test_strings;
// Compare strings.
$res_val = cmp_to_char( ut_coll_compare( $coll, $str1, $str2 ) );
// Concatenate result strings.
$res_str .= dump( $str1 ) .
' ' . $res_val . ' ' .
dump( $str2 ) . "\n";
}
return $res_str;
}
function ut_main()
{
$res_str = '';
// Compare strings using en_US locale.
$test_params = array(
array( 'abc', 'abc' ),
array( 'Abc', 'abc' ),
array( 'a' , 'abc' ),
array( 'a' , '' ),
array( '' , '' ),
array( 'a' , 'b' ),
array( 'ab' , 'b' ),
array( 'ab' , 'a' ),
array( 123 , 'abc' ),
array( 'ac' , null ),
array( '.' , '.' ),
// Try to compare long strings.
array( 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcde',
'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdea'),
array( null , null )
);
$res_str .= compare_pairs( 'en_US', $test_params );
// Compare strings using ru_RU locale.
$test_params = array(
array( 'а', 'б' ),
array( 'а', 'аа' ),
array( 'аб', 'ба' ),
array( 'а', ',' ),
array( 'а', 'b' ),
array( 'а', 'bb' ),
array( 'а', 'ab' ),
array( 'а', null )
);
$res_str .= compare_pairs( 'ru_RU', $test_params );
// Compare strings using lt_LT locale.
$test_params = array(
array( 'y', 'k' )
);
$res_str .= compare_pairs( 'lt_LT', $test_params );
return $res_str;
}
include_once( 'ut_common.inc' );
ut_run();
?>
--EXPECT--
'abc' = 'abc'
'Abc' > 'abc'
'a' < 'abc'
'a' > ''
'' = ''
'a' < 'b'
'ab' < 'b'
'ab' > 'a'
123 < 'abc'
'ac' > NULL
'.' = '.'
'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcde' < 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdea'
NULL = NULL
'а' < 'б'
'а' < 'аа'
'аб' < 'ба'
'а' > ','
'а' > 'b'
'а' > 'bb'
'а' > 'ab'
'а' > NULL
'y' < 'k'