Chromium Code Reviews| Index: tests/lib/i18n/message_format_test.dart |
| diff --git a/tests/lib/i18n/message_format_test.dart b/tests/lib/i18n/message_format_test.dart |
| index f75532df710aedf7c2b265dba8ddad8a23187e09..98e49a5e4d7109a837a71062f7ed51468173504d 100644 |
| --- a/tests/lib/i18n/message_format_test.dart |
| +++ b/tests/lib/i18n/message_format_test.dart |
| @@ -7,22 +7,78 @@ |
| #library('message_format_test'); |
| #import('../../../lib/i18n/message_format.dart'); |
| +#import('../../../lib/i18n/intl.dart'); |
| #import('../../../lib/unittest/unittest.dart'); |
| + |
| /** |
| * Tests the MessageFormat library in dart. |
| */ |
| main() { |
| - test('Message formatting', () { |
| - var msg_format = new MessageFormat( |
| - 'Message telling user how many emails will be sent.', |
| - '''{NUM_EMAILS_TO_SEND, plural, |
| - =0 {unused plural form} |
| - =1 {One email will be sent.} |
| - other {# emails will be sent.}}'''); |
| - // TODO(efortuna): Uncomment when functioning correctly. |
| - //Expect.stringEquals('5 emails will be sent.', |
| - // msg_formatter.format({'NUM_EMAILS_TO_SEND' : 5})); |
| + |
| + test('Trivial message', () { |
| + intl_helloWorld() |
| + //@desc Hello world, doesn't get much simpler than this. |
| + => "Hello World"; |
| + var msg_format = new MessageFormat(); |
| + var result = msg_format.formatMessage(intl_helloWorld,null); |
| + Expect.stringEquals(result,"Hello World"); |
| + }); |
| + |
| + |
|
Emily Fortuna
2012/06/07 21:33:36
remove extra line of whitespace
Alan Knight
2012/06/07 21:58:53
Done.
|
| + test('Message with one numeric', () { |
| + intl_oneNumeric(num) |
| + //@desc Tell the user about their lucky number. |
| + => "Your lucky number is $num"; |
| + var msg_format = new MessageFormat(); |
| + var result = msg_format.formatMessage(intl_oneNumeric,42); |
| + Expect.stringEquals(result,"Your lucky number is 42"); |
| + }); |
| + |
| + /** |
| + * Test for the simple error of evaluating the message function before |
| + * passing it in. |
| + */ |
| + |
| + test('Evaluate the function by mistake', () { |
| + intl_oopsie() |
| + //@desc Doesn't matter |
| + => "You want to pass the formatter the function, not the string"; |
| + var msg_format = new MessageFormat(); |
| + expectThrow(()=>msg_format.formatMessage(intl_oopsie(),null)); |
| }); |
| + |
| + |
|
Emily Fortuna
2012/06/07 21:33:36
extra whitespace.
Alan Knight
2012/06/07 21:58:53
Done.
|
| + test('Complex message with plural', () { |
| + var intl = new Intl(); |
| + var df = intl.date; |
| + intl_howManyPeopleAreHere (NUM) => |
| + //@desc Lists how many people are here |
| + "There ${intl.plural(NUM,{'0': 'are', '1': 'is', 'other': 'are'})} " |
| + "$NUM other ${intl.plural(NUM, {'1':'person', 'other': 'people'})} here."; |
| + var msg_format = new MessageFormat(); |
| + Expect.stringEquals( |
| + msg_format.formatMessage(intl_howManyPeopleAreHere,0), |
| + "There are 0 other people here."); |
| + Expect.stringEquals( |
| + msg_format.formatMessage(intl_howManyPeopleAreHere,1), |
| + "There is 1 other person here."); |
| + Expect.stringEquals( |
| + msg_format.formatMessage(intl_howManyPeopleAreHere,2), |
| + "There are 2 other people here."); |
| + }); |
| + |
| + |
|
Emily Fortuna
2012/06/07 21:33:36
whitespace
Alan Knight
2012/06/07 21:58:53
Done.
|
| + test('MessageFormat with message', () { |
| + intl_mapArgument (dict) |
| + // @desc Lists person's name |
| + => "Hello, my name is ${dict['firstName']} ${dict['lastName']}"; |
| + var msg_format = new MessageFormat(intl_mapArgument); |
| + var person = {'firstName' : 'Ford', 'lastName': 'Prefect'}; |
| + Expect.stringEquals( |
| + msg_format.format(person), |
| + "Hello, my name is Ford Prefect"); |
| + }); |
| + |
| } |