Annotation of embedaddon/php/ext/intl/tests/collator_compare.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: compare()
        !             3: --SKIPIF--
        !             4: <?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
        !             5: --FILE--
        !             6: <?php
        !             7: 
        !             8: /*
        !             9:  * Compare various string pairs using various locales.
        !            10:  */
        !            11: 
        !            12: 
        !            13: /*
        !            14:  * Converts comparison result to a character.
        !            15:  */
        !            16: function cmp_to_char( $comp_res )
        !            17: {
        !            18:     switch( $comp_res )
        !            19:     {
        !            20:     case 0:            // UCOL_EQUAL
        !            21:         return '=';
        !            22:     case 1:            // UCOL_GREATER
        !            23:         return '>';
        !            24:     case -1:           // UCOL_LESS
        !            25:         return '<';
        !            26:     default:
        !            27:         return '?';
        !            28:     }
        !            29: }
        !            30: 
        !            31: /*
        !            32:  * Compare string pairs in the given array
        !            33:  * using specified locale.
        !            34:  */
        !            35: function compare_pairs( $locale, $test_array )
        !            36: {
        !            37:     $res_str = '';
        !            38: 
        !            39:     $coll = ut_coll_create( $locale );
        !            40: 
        !            41:     foreach( $test_array as $test_strings )
        !            42:     {
        !            43:         list( $str1, $str2 ) = $test_strings;
        !            44: 
        !            45:         // Compare strings.
        !            46:         $res_val = cmp_to_char( ut_coll_compare( $coll, $str1, $str2 ) );
        !            47: 
        !            48:         // Concatenate result strings.
        !            49:         $res_str .= dump( $str1 ) .
        !            50:                     ' ' . $res_val . ' ' .
        !            51:                     dump( $str2 ) . "\n";
        !            52:     }
        !            53: 
        !            54:     return $res_str;
        !            55: 
        !            56: }
        !            57: 
        !            58: function ut_main()
        !            59: {
        !            60:     $res_str = '';
        !            61: 
        !            62:     // Compare strings using en_US locale.
        !            63:     $test_params = array(
        !            64:         array( 'abc', 'abc' ),
        !            65:         array( 'Abc', 'abc' ),
        !            66:         array( 'a'  , 'abc' ),
        !            67:         array( 'a'  , ''    ),
        !            68:         array( ''  , ''     ),
        !            69:         array( 'a'  , 'b'   ),
        !            70:         array( 'ab'  , 'b'  ),
        !            71:         array( 'ab'  , 'a'  ),
        !            72:         array( 123  , 'abc' ),
        !            73:         array( 'ac' , null  ),
        !            74:         array( '.'  , '.'   ),
        !            75:         // Try to compare long strings.
        !            76:         array( 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcde',
        !            77:                'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdea'),
        !            78:         array( null , null  )
        !            79:     );
        !            80: 
        !            81:     $res_str .= compare_pairs( 'en_US', $test_params );
        !            82: 
        !            83: 
        !            84:     // Compare strings using ru_RU locale.
        !            85:     $test_params = array(
        !            86:         array( 'а',   'б' ),
        !            87:         array( 'а',   'аа' ),
        !            88:         array( 'аб', 'ба' ),
        !            89:         array( 'а',   ',' ),
        !            90:         array( 'а',   'b' ),
        !            91:         array( 'а',   'bb' ),
        !            92:         array( 'а',   'ab' ),
        !            93:         array( 'а',   null )
        !            94:     );
        !            95: 
        !            96:     $res_str .= compare_pairs( 'ru_RU', $test_params );
        !            97: 
        !            98: 
        !            99:     // Compare strings using lt_LT locale.
        !           100:     $test_params = array(
        !           101:         array( 'y', 'k' )
        !           102:     );
        !           103: 
        !           104:     $res_str .= compare_pairs( 'lt_LT', $test_params );
        !           105: 
        !           106:     return $res_str;
        !           107: }
        !           108: 
        !           109: include_once( 'ut_common.inc' );
        !           110: ut_run();
        !           111: ?>
        !           112: --EXPECT--
        !           113: 'abc' = 'abc'
        !           114: 'Abc' > 'abc'
        !           115: 'a' < 'abc'
        !           116: 'a' > ''
        !           117: '' = ''
        !           118: 'a' < 'b'
        !           119: 'ab' < 'b'
        !           120: 'ab' > 'a'
        !           121: 123 < 'abc'
        !           122: 'ac' > NULL
        !           123: '.' = '.'
        !           124: 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcde' < 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdea'
        !           125: NULL = NULL
        !           126: 'а' < 'б'
        !           127: 'а' < 'аа'
        !           128: 'аб' < 'ба'
        !           129: 'а' > ','
        !           130: 'а' > 'b'
        !           131: 'а' > 'bb'
        !           132: 'а' > 'ab'
        !           133: 'а' > NULL
        !           134: 'y' < 'k'

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>