xref: /PHP-5.6/ext/intl/tests/msgfmt_parse.phpt (revision 9762609c)
1--TEST--
2msgfmt_parse() tests
3--SKIPIF--
4<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5--FILE--
6<?php
7
8/*
9 * Format a number using misc locales/patterns.
10 */
11
12
13function ut_main()
14{
15    $locales = array(
16        'en_US' => "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree",
17        'ru_UA' => "{0,number,integer} мавп на {1,number,integer} деревах це {2,number} мавпи на кожному деревi",
18        'de' => "{0,number,integer} Affen über {1,number,integer} Bäume um {2,number} Affen pro Baum",
19        'en_UK' => "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree",
20	'root' => '{0,whatever} would not work!',
21	'fr' => 'C\'est {0,number,integer}',
22    );
23
24	$results = array(
25		'en_US' => "4,560 monkeys on 123 trees make 37.073 monkeys per tree",
26		'ru_UA' => "4 560 мавп на 123 деревах це 37,073 мавпи на кожному деревi",
27		'de' => "4.560 Affen über 123 Bäume um 37,073 Affen pro Baum",
28		'en_UK' => "4,560 monkeys on 123 trees make 37.073 monkeys per tree",
29		'root' => "4,560 monkeys on 123 trees make 37.073 monkeys per tree",
30		'fr' => "C'est 42",
31
32	);
33
34	$str_res = '';
35
36    foreach( $locales as $locale => $pattern )
37    {
38        $str_res .= "\nLocale is: $locale\n";
39        $fmt = ut_msgfmt_create( $locale, $pattern );
40		if(!$fmt) {
41			$str_res .= dump(intl_get_error_message())."\n";
42			continue;
43		}
44        $str_res .= dump( ut_msgfmt_parse( $fmt, $results[$locale] ) ) . "\n";
45		$str_res .= dump( ut_msgfmt_parse_message($locale, $pattern, $results[$locale])) . "\n";
46    }
47    return $str_res;
48}
49
50include_once( 'ut_common.inc' );
51
52// Run the test
53ut_run();
54
55?>
56--EXPECT--
57Locale is: en_US
58array (
59  0 => 4560,
60  1 => 123,
61  2 => 37.073,
62)
63array (
64  0 => 4560,
65  1 => 123,
66  2 => 37.073,
67)
68
69Locale is: ru_UA
70array (
71  0 => 4560,
72  1 => 123,
73  2 => 37.073,
74)
75array (
76  0 => 4560,
77  1 => 123,
78  2 => 37.073,
79)
80
81Locale is: de
82array (
83  0 => 4560,
84  1 => 123,
85  2 => 37.073,
86)
87array (
88  0 => 4560,
89  1 => 123,
90  2 => 37.073,
91)
92
93Locale is: en_UK
94array (
95  0 => 4560,
96  1 => 123,
97  2 => 37.073,
98)
99array (
100  0 => 4560,
101  1 => 123,
102  2 => 37.073,
103)
104
105Locale is: root
106'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
107
108Locale is: fr
109array (
110  0 => 42,
111)
112array (
113  0 => 42,
114)
115