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

1.1     ! misho       1: --TEST--
        !             2: numfmt_get/set_symbol()
        !             3: --SKIPIF--
        !             4: <?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
        !             5: --FILE--
        !             6: <?php
        !             7: 
        !             8: /*
        !             9:  * Get/set symbol.
        !            10:  */
        !            11: 
        !            12: 
        !            13: function ut_main()
        !            14: {
        !            15:        $longstr = str_repeat("blah", 10);
        !            16:     $symbols = array(
        !            17:         'DECIMAL_SEPARATOR_SYMBOL' => array( NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, '_._', 12345.123456, NumberFormatter::DECIMAL ),
        !            18:         'GROUPING_SEPARATOR_SYMBOL' => array( NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '_,_', 12345.123456, NumberFormatter::DECIMAL ),
        !            19:         'PATTERN_SEPARATOR_SYMBOL' => array( NumberFormatter::PATTERN_SEPARATOR_SYMBOL, '_;_', 12345.123456, NumberFormatter::DECIMAL ),
        !            20:         'PERCENT_SYMBOL' => array( NumberFormatter::PERCENT_SYMBOL, '_%_', 12345.123456, NumberFormatter::PERCENT ),
        !            21:         'ZERO_DIGIT_SYMBOL' => array( NumberFormatter::ZERO_DIGIT_SYMBOL, '_ZD_', 12345.123456, NumberFormatter::DECIMAL ),
        !            22:         'DIGIT_SYMBOL' => array( NumberFormatter::DIGIT_SYMBOL, '_DS_', 12345.123456, NumberFormatter::DECIMAL ),
        !            23:         'MINUS_SIGN_SYMBOL' => array( NumberFormatter::MINUS_SIGN_SYMBOL, '_-_', -12345.123456, NumberFormatter::DECIMAL ),
        !            24:         'PLUS_SIGN_SYMBOL' => array( NumberFormatter::PLUS_SIGN_SYMBOL, '_+_', 12345.123456, NumberFormatter::SCIENTIFIC ),
        !            25:         'CURRENCY_SYMBOL' => array( NumberFormatter::CURRENCY_SYMBOL, '_$_', 12345.123456, NumberFormatter::CURRENCY ),
        !            26:         'INTL_CURRENCY_SYMBOL' => array( NumberFormatter::INTL_CURRENCY_SYMBOL, '_$_', 12345.123456, NumberFormatter::CURRENCY ),
        !            27:         'MONETARY_SEPARATOR_SYMBOL' => array( NumberFormatter::MONETARY_SEPARATOR_SYMBOL, '_MS_', 12345.123456, NumberFormatter::CURRENCY ),
        !            28:         'EXPONENTIAL_SYMBOL' => array( NumberFormatter::EXPONENTIAL_SYMBOL, '_E_', 12345.123456, NumberFormatter::SCIENTIFIC ),
        !            29:         'PERMILL_SYMBOL' => array( NumberFormatter::PERMILL_SYMBOL, '_PS_', 12345.123456, NumberFormatter::DECIMAL ),
        !            30:         'PAD_ESCAPE_SYMBOL' => array( NumberFormatter::PAD_ESCAPE_SYMBOL, '_PE_', 12345.123456, NumberFormatter::DECIMAL ),
        !            31:         'INFINITY_SYMBOL' => array( NumberFormatter::INFINITY_SYMBOL, '_IS_', 12345.123456, NumberFormatter::DECIMAL ),
        !            32:         'NAN_SYMBOL' => array( NumberFormatter::NAN_SYMBOL, '_N_', 12345.123456, NumberFormatter::DECIMAL ),
        !            33:         'SIGNIFICANT_DIGIT_SYMBOL' => array( NumberFormatter::SIGNIFICANT_DIGIT_SYMBOL, '_SD_', 12345.123456, NumberFormatter::DECIMAL ),
        !            34:         'MONETARY_GROUPING_SEPARATOR_SYMBOL' => array( NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, '_MG_', 12345.123456, NumberFormatter::CURRENCY ),
        !            35:        'MONETARY_GROUPING_SEPARATOR_SYMBOL-2' => array( NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, "&nbsp;", 12345.123456, NumberFormatter::CURRENCY ),
        !            36:        'MONETARY_GROUPING_SEPARATOR_SYMBOL-3' => array( NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, $longstr, 12345.123456, NumberFormatter::CURRENCY ),
        !            37:     );
        !            38: 
        !            39:     $res_str = '';
        !            40: 
        !            41:     foreach( $symbols as $symb_name => $data )
        !            42:     {
        !            43:         list( $symb, $new_val, $number, $attr ) = $data;
        !            44: 
        !            45:         $fmt = ut_nfmt_create( 'en_US', $attr);
        !            46: 
        !            47:         $res_str .= "\nSymbol '$symb_name'\n";
        !            48: 
        !            49:         // Get original symbol value.
        !            50:         $orig_val = ut_nfmt_get_symbol( $fmt, $symb );
        !            51:         $res_str .= "Default symbol: [$orig_val]\n";
        !            52: 
        !            53:         // Set a new symbol value.
        !            54:         $res_val = ut_nfmt_set_symbol( $fmt, $symb, $new_val );
        !            55:         if( !$res_val )
        !            56:             $res_str .= "set_symbol() error: " . ut_nfmt_get_error_message( $fmt ) . "\n";
        !            57: 
        !            58:         // Get the symbol value back.
        !            59:         $new_val_check = ut_nfmt_get_symbol( $fmt, $symb );
        !            60:         if( !$new_val_check )
        !            61:             $res_str .= "get_symbol() error: " . ut_nfmt_get_error_message( $fmt ) . "\n";
        !            62: 
        !            63:         $res_str .= "New symbol: [$new_val_check]\n";
        !            64: 
        !            65:         // Check if the new value has been set.
        !            66:         if( $new_val_check !== $new_val )
        !            67:             $res_str .= "ERROR: New $symb_name symbol value has not been set correctly.\n";
        !            68: 
        !            69:         // Format the number using the new value.
        !            70:         $s = ut_nfmt_format( $fmt, $number );
        !            71:         $res_str .= "A number formatted with the new symbol: $s\n";
        !            72: 
        !            73:         // Restore attribute's symbol.
        !            74:         ut_nfmt_set_symbol( $fmt, $symb, $orig_val );
        !            75:     }
        !            76:     $badvals = array(2147483648, -2147483648, -1, 4294901761);
        !            77:     foreach($badvals as $badval) {
        !            78:            if(ut_nfmt_get_symbol( $fmt, 2147483648 ))  {
        !            79:                $res_str .= "Bad value $badval should return false!\n";
        !            80:            }
        !            81:     }
        !            82:     return $res_str;
        !            83: }
        !            84: 
        !            85: include_once( 'ut_common.inc' );
        !            86: ut_run();
        !            87: 
        !            88: ?>
        !            89: --EXPECT--
        !            90: Symbol 'DECIMAL_SEPARATOR_SYMBOL'
        !            91: Default symbol: [.]
        !            92: New symbol: [_._]
        !            93: A number formatted with the new symbol: 12,345_._123
        !            94: 
        !            95: Symbol 'GROUPING_SEPARATOR_SYMBOL'
        !            96: Default symbol: [,]
        !            97: New symbol: [_,_]
        !            98: A number formatted with the new symbol: 12_,_345.123
        !            99: 
        !           100: Symbol 'PATTERN_SEPARATOR_SYMBOL'
        !           101: Default symbol: [;]
        !           102: New symbol: [_;_]
        !           103: A number formatted with the new symbol: 12,345.123
        !           104: 
        !           105: Symbol 'PERCENT_SYMBOL'
        !           106: Default symbol: [%]
        !           107: New symbol: [_%_]
        !           108: A number formatted with the new symbol: 1,234,512_%_
        !           109: 
        !           110: Symbol 'ZERO_DIGIT_SYMBOL'
        !           111: Default symbol: [0]
        !           112: New symbol: [_ZD_]
        !           113: A number formatted with the new symbol: `a,bcd.`ab
        !           114: 
        !           115: Symbol 'DIGIT_SYMBOL'
        !           116: Default symbol: [#]
        !           117: New symbol: [_DS_]
        !           118: A number formatted with the new symbol: 12,345.123
        !           119: 
        !           120: Symbol 'MINUS_SIGN_SYMBOL'
        !           121: Default symbol: [-]
        !           122: New symbol: [_-_]
        !           123: A number formatted with the new symbol: _-_12,345.123
        !           124: 
        !           125: Symbol 'PLUS_SIGN_SYMBOL'
        !           126: Default symbol: [+]
        !           127: New symbol: [_+_]
        !           128: A number formatted with the new symbol: 1.2345123456E4
        !           129: 
        !           130: Symbol 'CURRENCY_SYMBOL'
        !           131: Default symbol: [$]
        !           132: New symbol: [_$_]
        !           133: A number formatted with the new symbol: _$_12,345.12
        !           134: 
        !           135: Symbol 'INTL_CURRENCY_SYMBOL'
        !           136: Default symbol: [USD]
        !           137: New symbol: [_$_]
        !           138: A number formatted with the new symbol: $12,345.12
        !           139: 
        !           140: Symbol 'MONETARY_SEPARATOR_SYMBOL'
        !           141: Default symbol: [.]
        !           142: New symbol: [_MS_]
        !           143: A number formatted with the new symbol: $12,345_MS_12
        !           144: 
        !           145: Symbol 'EXPONENTIAL_SYMBOL'
        !           146: Default symbol: [E]
        !           147: New symbol: [_E_]
        !           148: A number formatted with the new symbol: 1.2345123456_E_4
        !           149: 
        !           150: Symbol 'PERMILL_SYMBOL'
        !           151: Default symbol: [‰]
        !           152: New symbol: [_PS_]
        !           153: A number formatted with the new symbol: 12,345.123
        !           154: 
        !           155: Symbol 'PAD_ESCAPE_SYMBOL'
        !           156: Default symbol: [*]
        !           157: New symbol: [_PE_]
        !           158: A number formatted with the new symbol: 12,345.123
        !           159: 
        !           160: Symbol 'INFINITY_SYMBOL'
        !           161: Default symbol: [∞]
        !           162: New symbol: [_IS_]
        !           163: A number formatted with the new symbol: 12,345.123
        !           164: 
        !           165: Symbol 'NAN_SYMBOL'
        !           166: Default symbol: [NaN]
        !           167: New symbol: [_N_]
        !           168: A number formatted with the new symbol: 12,345.123
        !           169: 
        !           170: Symbol 'SIGNIFICANT_DIGIT_SYMBOL'
        !           171: Default symbol: [@]
        !           172: New symbol: [_SD_]
        !           173: A number formatted with the new symbol: 12,345.123
        !           174: 
        !           175: Symbol 'MONETARY_GROUPING_SEPARATOR_SYMBOL'
        !           176: Default symbol: [,]
        !           177: New symbol: [_MG_]
        !           178: A number formatted with the new symbol: $12_MG_345.12
        !           179: 
        !           180: Symbol 'MONETARY_GROUPING_SEPARATOR_SYMBOL-2'
        !           181: Default symbol: [,]
        !           182: New symbol: [&nbsp;]
        !           183: A number formatted with the new symbol: $12&nbsp;345.12
        !           184: 
        !           185: Symbol 'MONETARY_GROUPING_SEPARATOR_SYMBOL-3'
        !           186: Default symbol: [,]
        !           187: New symbol: [blahblahblahblahblahblahblahblahblahblah]
        !           188: A number formatted with the new symbol: $12blahblahblahblahblahblahblahblahblahblah345.12
        !           189: 

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