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

1.1     ! misho       1: --TEST--
        !             2: numfmt_get/set_attribute() icu >= 4.8
        !             3: --SKIPIF--
        !             4: <?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
        !             5: <?php if(version_compare(INTL_ICU_VERSION, '4.8') < 0) print 'skip'; ?>
        !             6: --FILE--
        !             7: <?php
        !             8: 
        !             9: /*
        !            10:  * Get/set various number formatting attributes.
        !            11:  */
        !            12: 
        !            13: 
        !            14: function ut_main()
        !            15: {
        !            16:     // attr_name => array( attr, value )
        !            17:     $attributes = array(
        !            18:         'PARSE_INT_ONLY' => array( NumberFormatter::PARSE_INT_ONLY, 1, 12345.123456 ),
        !            19:         'GROUPING_USED' => array( NumberFormatter::GROUPING_USED, 0, 12345.123456 ),
        !            20:         'DECIMAL_ALWAYS_SHOWN' => array( NumberFormatter::DECIMAL_ALWAYS_SHOWN, 1, 12345 ),
        !            21:         'MAX_INTEGER_DIGITS' => array( NumberFormatter::MAX_INTEGER_DIGITS, 2, 12345.123456 ),
        !            22:         'MIN_INTEGER_DIGITS' => array( NumberFormatter::MIN_INTEGER_DIGITS, 20, 12345.123456 ),
        !            23:         'INTEGER_DIGITS' => array( NumberFormatter::INTEGER_DIGITS, 7, 12345.123456 ),
        !            24:         'MAX_FRACTION_DIGITS' => array( NumberFormatter::MAX_FRACTION_DIGITS, 2, 12345.123456 ),
        !            25:         'MIN_FRACTION_DIGITS' => array( NumberFormatter::MIN_FRACTION_DIGITS, 20, 12345.123456 ),
        !            26:         'FRACTION_DIGITS' => array( NumberFormatter::FRACTION_DIGITS, 5, 12345.123456 ),
        !            27:         'MULTIPLIER' => array( NumberFormatter::MULTIPLIER, 2, 12345.123456 ),
        !            28:         'GROUPING_SIZE' => array( NumberFormatter::GROUPING_SIZE, 2, 12345.123456 ),
        !            29:         'ROUNDING_MODE' => array( NumberFormatter::ROUNDING_MODE, 1, 12345.123456 ),
        !            30:         'ROUNDING_INCREMENT' => array( NumberFormatter::ROUNDING_INCREMENT, (float)2, 12345.123456 ),
        !            31:         'FORMAT_WIDTH' => array( NumberFormatter::FORMAT_WIDTH, 27, 12345.123456 ),
        !            32:         'PADDING_POSITION' => array( NumberFormatter::PADDING_POSITION, 21, 12345.123456 ),
        !            33:         'SECONDARY_GROUPING_SIZE' => array( NumberFormatter::SECONDARY_GROUPING_SIZE, 2, 12345.123456 ),
        !            34:         'SIGNIFICANT_DIGITS_USED' => array( NumberFormatter::SIGNIFICANT_DIGITS_USED, 1, 12345.123456 ),
        !            35:         'MIN_SIGNIFICANT_DIGITS' => array( NumberFormatter::MIN_SIGNIFICANT_DIGITS, 3, 1 ),
        !            36:         'MAX_SIGNIFICANT_DIGITS' => array( NumberFormatter::MAX_SIGNIFICANT_DIGITS, 4, 12345.123456 ),
        !            37:         // 'LENIENT_PARSE' => array( NumberFormatter::LENIENT_PARSE, 2, 12345.123456 )
        !            38:     );
        !            39: 
        !            40:     $res_str = '';
        !            41: 
        !            42:     $fmt = ut_nfmt_create( "en_US", NumberFormatter::DECIMAL );
        !            43: 
        !            44:     foreach( $attributes as $attr_name => $args )
        !            45:     {
        !            46:         list( $attr, $new_val, $number ) = $args;
        !            47:         $res_str .= "\nAttribute $attr_name\n";
        !            48: 
        !            49:         // Get original value of the attribute.
        !            50:         $orig_val = ut_nfmt_get_attribute( $fmt, $attr );
        !            51: 
        !            52:         // Format the number using the original attribute value.
        !            53:         $rc = ut_nfmt_format( $fmt, $number );
        !            54: 
        !            55:         $ps = ut_nfmt_parse( $fmt, $rc );
        !            56: 
        !            57:         $res_str .= sprintf( "Old attribute value: %s ;  Format result: %s ; Parse result: %s\n",
        !            58:                              dump( $orig_val ),
        !            59:                              dump( $rc ),
        !            60:                              dump( $ps ) );
        !            61: 
        !            62:         // Set new attribute value.
        !            63:         $rc = ut_nfmt_set_attribute( $fmt, $attr, $new_val );
        !            64:         if( $rc )
        !            65:             $res_str .= "Setting attribute: ok\n";
        !            66:         else
        !            67:             $res_str .= sprintf( "Setting attribute failed: %s\n", ut_nfmt_get_error_message( $fmt ) );
        !            68: 
        !            69:         // Format the number using the new value.
        !            70:         $rc = ut_nfmt_format( $fmt, $number );
        !            71: 
        !            72:         // Get current value of the attribute and check if it equals $new_val.
        !            73:         $attr_val_check = ut_nfmt_get_attribute( $fmt, $attr );
        !            74:         if( $attr_val_check !== $new_val )
        !            75:             $res_str .= "ERROR: New $attr_name attribute value has not been set correctly.\n";
        !            76: 
        !            77:         $ps = ut_nfmt_parse( $fmt, $rc );
        !            78: 
        !            79:         $res_str .= sprintf( "New attribute value: %s ;  Format result: %s ; Parse result: %s\n",
        !            80:                              dump( $new_val ),
        !            81:                              dump( $rc ),
        !            82:                              dump( $ps ) );
        !            83: 
        !            84: 
        !            85:         // Restore original attribute of the  value
        !            86:         if( $attr != NumberFormatter::INTEGER_DIGITS && $attr != NumberFormatter::FRACTION_DIGITS
        !            87:              && $attr != NumberFormatter::FORMAT_WIDTH && $attr != NumberFormatter::SIGNIFICANT_DIGITS_USED )
        !            88:             ut_nfmt_set_attribute( $fmt, $attr, $orig_val );
        !            89:     }
        !            90: 
        !            91:     return $res_str;
        !            92: }
        !            93: 
        !            94: include_once( 'ut_common.inc' );
        !            95: 
        !            96: // Run the test
        !            97: ut_run();
        !            98: 
        !            99: ?>
        !           100: --EXPECT--
        !           101: Attribute PARSE_INT_ONLY
        !           102: Old attribute value: 0 ;  Format result: '12,345.123' ; Parse result: 12345.123
        !           103: Setting attribute: ok
        !           104: New attribute value: 1 ;  Format result: '12,345.123' ; Parse result: 12345
        !           105: 
        !           106: Attribute GROUPING_USED
        !           107: Old attribute value: 1 ;  Format result: '12,345.123' ; Parse result: 12345.123
        !           108: Setting attribute: ok
        !           109: New attribute value: 0 ;  Format result: '12345.123' ; Parse result: 12345.123
        !           110: 
        !           111: Attribute DECIMAL_ALWAYS_SHOWN
        !           112: Old attribute value: 0 ;  Format result: '12,345' ; Parse result: 12345
        !           113: Setting attribute: ok
        !           114: New attribute value: 1 ;  Format result: '12,345.' ; Parse result: 12345
        !           115: 
        !           116: Attribute MAX_INTEGER_DIGITS
        !           117: Old attribute value: 309 ;  Format result: '12,345.123' ; Parse result: 12345.123
        !           118: Setting attribute: ok
        !           119: New attribute value: 2 ;  Format result: '45.123' ; Parse result: 45.123
        !           120: 
        !           121: Attribute MIN_INTEGER_DIGITS
        !           122: Old attribute value: 1 ;  Format result: '12,345.123' ; Parse result: 12345.123
        !           123: Setting attribute: ok
        !           124: New attribute value: 20 ;  Format result: '00,000,000,000,000,012,345.123' ; Parse result: 12345.123
        !           125: 
        !           126: Attribute INTEGER_DIGITS
        !           127: Old attribute value: 1 ;  Format result: '12,345.123' ; Parse result: 12345.123
        !           128: Setting attribute: ok
        !           129: New attribute value: 7 ;  Format result: '0,012,345.123' ; Parse result: 12345.123
        !           130: 
        !           131: Attribute MAX_FRACTION_DIGITS
        !           132: Old attribute value: 3 ;  Format result: '0,012,345.123' ; Parse result: 12345.123
        !           133: Setting attribute: ok
        !           134: New attribute value: 2 ;  Format result: '0,012,345.12' ; Parse result: 12345.12
        !           135: 
        !           136: Attribute MIN_FRACTION_DIGITS
        !           137: Old attribute value: 0 ;  Format result: '0,012,345.123' ; Parse result: 12345.123
        !           138: Setting attribute: ok
        !           139: New attribute value: 20 ;  Format result: '0,012,345.12345600000000000000' ; Parse result: 12345.123456
        !           140: 
        !           141: Attribute FRACTION_DIGITS
        !           142: Old attribute value: 0 ;  Format result: '0,012,345.123456' ; Parse result: 12345.123456
        !           143: Setting attribute: ok
        !           144: New attribute value: 5 ;  Format result: '0,012,345.12346' ; Parse result: 12345.12346
        !           145: 
        !           146: Attribute MULTIPLIER
        !           147: Old attribute value: 1 ;  Format result: '0,012,345.12346' ; Parse result: 12345.12346
        !           148: Setting attribute: ok
        !           149: New attribute value: 2 ;  Format result: '0,024,690.24691' ; Parse result: 12345.123455
        !           150: 
        !           151: Attribute GROUPING_SIZE
        !           152: Old attribute value: 3 ;  Format result: '0,012,345.12346' ; Parse result: 12345.12346
        !           153: Setting attribute: ok
        !           154: New attribute value: 2 ;  Format result: '0,01,23,45.12346' ; Parse result: 12345.12346
        !           155: 
        !           156: Attribute ROUNDING_MODE
        !           157: Old attribute value: 4 ;  Format result: '0,012,345.12346' ; Parse result: 12345.12346
        !           158: Setting attribute: ok
        !           159: New attribute value: 1 ;  Format result: '0,012,345.12345' ; Parse result: 12345.12345
        !           160: 
        !           161: Attribute ROUNDING_INCREMENT
        !           162: Old attribute value: 0 ;  Format result: '0,012,345.12346' ; Parse result: 12345.12346
        !           163: Setting attribute: ok
        !           164: New attribute value: 2 ;  Format result: '0,012,346.00000' ; Parse result: 12346
        !           165: 
        !           166: Attribute FORMAT_WIDTH
        !           167: Old attribute value: 0 ;  Format result: '0,012,345.12346' ; Parse result: 12345.12346
        !           168: Setting attribute: ok
        !           169: New attribute value: 27 ;  Format result: '************0,012,345.12346' ; Parse result: 12345.12346
        !           170: 
        !           171: Attribute PADDING_POSITION
        !           172: Old attribute value: 0 ;  Format result: '************0,012,345.12346' ; Parse result: 12345.12346
        !           173: Setting attribute: ok
        !           174: New attribute value: 21 ;  Format result: '0,012,345.12346' ; Parse result: 12345.12346
        !           175: 
        !           176: Attribute SECONDARY_GROUPING_SIZE
        !           177: Old attribute value: 0 ;  Format result: '************0,012,345.12346' ; Parse result: 12345.12346
        !           178: Setting attribute: ok
        !           179: New attribute value: 2 ;  Format result: '************00,12,345.12346' ; Parse result: 12345.12346
        !           180: 
        !           181: Attribute SIGNIFICANT_DIGITS_USED
        !           182: Old attribute value: 0 ;  Format result: '************0,012,345.12346' ; Parse result: 12345.12346
        !           183: Setting attribute: ok
        !           184: New attribute value: 1 ;  Format result: '*******************12,345.1' ; Parse result: 12345.1
        !           185: 
        !           186: Attribute MIN_SIGNIFICANT_DIGITS
        !           187: Old attribute value: 1 ;  Format result: '**************************1' ; Parse result: 1
        !           188: Setting attribute: ok
        !           189: New attribute value: 3 ;  Format result: '***********************1.00' ; Parse result: 1
        !           190: 
        !           191: Attribute MAX_SIGNIFICANT_DIGITS
        !           192: Old attribute value: 6 ;  Format result: '*******************12,345.1' ; Parse result: 12345.1
        !           193: Setting attribute: ok
        !           194: New attribute value: 4 ;  Format result: '*********************12,350' ; Parse result: 12350

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