1--TEST--
2msgfmt_format() with named subpatterns
3--SKIPIF--
4<?php
5if (!extension_loaded('intl'))
6    die('skip intl extension not enabled');
7--FILE--
8<?php
9
10/*
11 * Format a number using misc locales/patterns.
12 */
13
14
15function ut_main()
16{
17
18$pattern=<<<_MSG_
19{gender_of_host, select,
20  female {{num_guests, plural, offset:1
21      =0 {{host} does not give a party.}
22      =1 {{host} invites {guest} to her party.}
23      =2 {{host} invites {guest} and one other person to her party.}
24     other {{host} invites {guest} as one of the # people invited to her party.}}}
25  male   {{num_guests, plural, offset:1
26      =0 {{host} does not give a party.}
27      =1 {{host} invites {guest} to his party.}
28      =2 {{host} invites {guest} and one other person to his party.}
29     other {{host} invites {guest} as one of the # people invited to his party.}}}
30  other {{num_guests, plural, offset:1
31      =0 {{host} does not give a party.}
32      =1 {{host} invites {guest} to their party.}
33      =2 {{host} invites {guest} and one other person to their party.}
34     other {{host} invites {guest} as one of the # people invited to their party.}}}}
35_MSG_;
36
37
38$args = array(
39      array('gender_of_host' => 'female', 'num_guests' => 0, 'host' => 'Alice', 'guest' => 'Bob'),
40      array('gender_of_host' => 'male', 'num_guests' => 1, 'host' => 'Alice', 'guest' => 'Bob'),
41      array('gender_of_host' => 'none', 'num_guests' => 2, 'host' => 'Alice', 'guest' => 'Bob'),
42      array('gender_of_host' => 'female', 'num_guests' => 27, 'host' => 'Alice', 'guest' => 'Bob'),
43);
44
45$str_res = '';
46
47        $fmt = ut_msgfmt_create( 'en_US', $pattern );
48        if(!$fmt) {
49            $str_res .= dump(intl_get_error_message())."\n";
50            return $str_res;
51        }
52        foreach ($args as $arg) {
53            $str_res .= dump( ut_msgfmt_format($fmt, $arg) ). "\n";
54            $str_res .= dump( ut_msgfmt_format_message('en_US', $pattern, $arg) ) . "\n";
55    }
56    return $str_res;
57}
58
59include_once( 'ut_common.inc' );
60
61// Run the test
62ut_run();
63
64?>
65--EXPECT--
66'Alice does not give a party.'
67'Alice does not give a party.'
68'Alice invites Bob to his party.'
69'Alice invites Bob to his party.'
70'Alice invites Bob and one other person to their party.'
71'Alice invites Bob and one other person to their party.'
72'Alice invites Bob as one of the 26 people invited to her party.'
73'Alice invites Bob as one of the 26 people invited to her party.'
74