Annotation of embedaddon/php/ext/intl/tests/formatter_get_set_text_attribute.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: numfmt_get/set_text_attribute()
3: --SKIPIF--
4: <?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5: --FILE--
6: <?php
7:
8: /*
9: * Get/set text attribute.
10: */
11:
12:
13: function ut_main()
14: {
15: // Array with data for testing
16: $long_str = str_repeat('blah', 100);
17: $attributes = array(
18: 'POSITIVE_PREFIX' => array( NumberFormatter::POSITIVE_PREFIX, '_+_', 12345.1234 ),
19: 'POSITIVE_SUFFIX' => array( NumberFormatter::POSITIVE_SUFFIX, '_+_', 12345.1234 ),
20: 'NEGATIVE_PREFIX' => array( NumberFormatter::NEGATIVE_PREFIX, '_-_', -12345.1234 ),
21: 'NEGATIVE_SUFFIX' => array( NumberFormatter::NEGATIVE_SUFFIX, '_-_', -12345.1234 ),
22: 'PADDING_CHARACTER' => array( NumberFormatter::PADDING_CHARACTER, '^', 12345.1234 ),
23: 'POSITIVE_PREFIX-2' => array( NumberFormatter::POSITIVE_PREFIX, $long_str, 12345.1234 ),
24: // 'CURRENCY_CODE' => array( NumberFormatter::CURRENCY_CODE, '_C_', 12345.1234 )
25: // 'DEFAULT_RULESET' => array( NumberFormatter::DEFAULT_RULESET, '_DR_', 12345.1234 ),
26: // 'PUBLIC_RULESETS' => array( NumberFormatter::PUBLIC_RULESETS, '_PR_', 12345.1234 )
27: );
28:
29: $res_str = '';
30:
31: $fmt = ut_nfmt_create( "en_US", NumberFormatter::DECIMAL );
32:
33: foreach( $attributes as $attr_name => $data )
34: {
35: list( $attr, $new_val, $test_number ) = $data;
36: $res_str .= "\nAttribute $attr_name\n";
37:
38: if( $attr == NumberFormatter::PADDING_CHARACTER )
39: ut_nfmt_set_attribute( $fmt, NumberFormatter::FORMAT_WIDTH, 21 );
40:
41: // Get default attribute's value
42: $def_val = ut_nfmt_get_text_attribute( $fmt, $attr );
43: if( $def_val === false )
44: $res_str .= "get_text_attribute() error: " . ut_nfmt_get_error_message( $fmt ) . "\n";
45:
46: $res_str .= "Default value: [$def_val]\n";
47: $res_str .= "Formatting number with default value: " . ut_nfmt_format( $fmt, $test_number ) . "\n";
48:
49: // Set new attribute's value and see if it works out.
50: $res_val = ut_nfmt_set_text_attribute( $fmt, $attr, $new_val );
51: if( !$res_val )
52: $res_str .= "set_text_attribute() error: " . ut_nfmt_get_error_message( $fmt ) . "\n";
53:
54: // Get attribute value back.
55: $new_val_check = ut_nfmt_get_text_attribute( $fmt, $attr );
56: $res_str .= "New value: [$new_val_check]\n";
57: $res_str .= "Formatting number with new value: " . ut_nfmt_format( $fmt, $test_number ) . "\n";
58:
59: // Check if the new value has been set.
60: if( $new_val !== $new_val_check )
61: $res_str .= "ERROR: New $attr_name symbol value has not been set correctly.\n";
62:
63: // Restore attribute's value to default
64: ut_nfmt_set_text_attribute( $fmt, $attr, $def_val );
65:
66: if( $attr == NumberFormatter::PADDING_CHARACTER )
67: ut_nfmt_set_attribute( $fmt, NumberFormatter::FORMAT_WIDTH, 0 );
68: }
69:
70: //
71: $fmt = ut_nfmt_create( "uk_UA", NumberFormatter::CURRENCY );
72: $res_str .= sprintf( "\nCurrency ISO-code for locale 'uk_UA' is: %s\n",
73: ut_nfmt_get_text_attribute( $fmt, NumberFormatter::CURRENCY_CODE ) );
74:
75: return $res_str;
76: }
77:
78: include_once( 'ut_common.inc' );
79: ut_run();
80:
81: ?>
82: --EXPECT--
83: Attribute POSITIVE_PREFIX
84: Default value: []
85: Formatting number with default value: 12,345.123
86: New value: [_+_]
87: Formatting number with new value: _+_12,345.123
88:
89: Attribute POSITIVE_SUFFIX
90: Default value: []
91: Formatting number with default value: 12,345.123
92: New value: [_+_]
93: Formatting number with new value: 12,345.123_+_
94:
95: Attribute NEGATIVE_PREFIX
96: Default value: [-]
97: Formatting number with default value: -12,345.123
98: New value: [_-_]
99: Formatting number with new value: _-_12,345.123
100:
101: Attribute NEGATIVE_SUFFIX
102: Default value: []
103: Formatting number with default value: -12,345.123
104: New value: [_-_]
105: Formatting number with new value: -12,345.123_-_
106:
107: Attribute PADDING_CHARACTER
108: Default value: [*]
109: Formatting number with default value: ***********12,345.123
110: New value: [^]
111: Formatting number with new value: ^^^^^^^^^^^12,345.123
112:
113: Attribute POSITIVE_PREFIX-2
114: Default value: []
115: Formatting number with default value: 12,345.123
116: New value: [blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah]
117: Formatting number with new value: blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah12,345.123
118:
119: Currency ISO-code for locale 'uk_UA' is: UAH
120:
121:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>