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