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