1--TEST--
2numfmt_get/set_pattern()
3--SKIPIF--
4<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5<?php if (version_compare(INTL_ICU_VERSION, '62.1') < 0) die('skip for ICU >= 62.1'); ?>
6--FILE--
7<?php
8
9/*
10 * Get/set pattern.
11 */
12
13
14function ut_main()
15{
16    $res_str = '';
17    $test_value = 12345.123456;
18    $fmt = ut_nfmt_create( "en_US", NumberFormatter::PATTERN_DECIMAL );
19
20    // Get default patten.
21    $res_str .= "Default pattern: '" . ut_nfmt_get_pattern( $fmt ) . "'\n";
22    $res_str .= "Formatting result: " . ut_nfmt_format( $fmt, $test_value ) . "\n";
23
24    // Set a new pattern.
25    $res = ut_nfmt_set_pattern( $fmt, "0.0" );
26    if( $res === false )
27        $res_str .= ut_nfmt_get_error_message( $fmt ) . " (" . ut_nfmt_get_error_code( $fmt ) . ")\n";
28
29    // Check if the pattern has been changed.
30    $res = ut_nfmt_get_pattern( $fmt );
31    if( $res === false )
32        $res_str .= ut_nfmt_get_error_message( $fmt ) . " (" . ut_nfmt_get_error_code( $fmt ) . ")\n";
33    $res_str .= "New pattern: '" . ut_nfmt_get_pattern( $fmt ) . "'\n";
34    $res_str .= "Formatted number: " . ut_nfmt_format( $fmt, $test_value ) . "\n";
35
36    ut_nfmt_set_pattern($fmt, str_repeat('@', 200));
37    $res_str .= "New pattern: '" . ut_nfmt_get_pattern( $fmt ) . "'\n";
38    $res_str .= "Formatted number: " . ut_nfmt_format( $fmt, $test_value ) . "\n";
39
40    return $res_str;
41}
42
43include_once( 'ut_common.inc' );
44ut_run();
45
46?>
47--EXPECT--
48Default pattern: '#'
49Formatting result: 12345.123456
50New pattern: '0.0'
51Formatted number: 12345.1
52New pattern: '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
53Formatted number: 12345.123456000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
54