Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /** | 1 /** |
| 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 * for details. All rights reserved. Use of this source code is governed by a | 3 * for details. All rights reserved. Use of this source code is governed by a |
| 4 * BSD-style license that can be found in the LICENSE file. | 4 * BSD-style license that can be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #library('message_format_test'); | 7 #library('message_format_test'); |
| 8 | 8 |
| 9 #import('../../../lib/i18n/message_format.dart'); | 9 #import('../../../lib/i18n/message_format.dart'); |
| 10 #import('../../../lib/i18n/intl.dart'); | |
| 10 #import('../../../lib/unittest/unittest.dart'); | 11 #import('../../../lib/unittest/unittest.dart'); |
| 11 | 12 |
| 13 | |
| 12 /** | 14 /** |
| 13 * Tests the MessageFormat library in dart. | 15 * Tests the MessageFormat library in dart. |
| 14 */ | 16 */ |
| 15 | 17 |
| 16 main() { | 18 main() { |
| 17 test('Message formatting', () { | 19 |
| 18 var msg_format = new MessageFormat( | 20 test('Trivial message', () { |
| 19 'Message telling user how many emails will be sent.', | 21 intl_helloWorld() |
| 20 '''{NUM_EMAILS_TO_SEND, plural, | 22 //@desc Hello world, doesn't get much simpler than this. |
| 21 =0 {unused plural form} | 23 => "Hello World"; |
| 22 =1 {One email will be sent.} | 24 var msg_format = new MessageFormat(); |
| 23 other {# emails will be sent.}}'''); | 25 var result = msg_format.formatMessage(intl_helloWorld,null); |
| 24 // TODO(efortuna): Uncomment when functioning correctly. | 26 Expect.stringEquals(result,"Hello World"); |
| 25 //Expect.stringEquals('5 emails will be sent.', | 27 }); |
|
Emily Fortuna
2012/06/02 01:19:26
this line should be indented two spaces, I believe
Alan Knight
2012/06/02 02:19:44
Done.
| |
| 26 // msg_formatter.format({'NUM_EMAILS_TO_SEND' : 5})); | 28 |
| 27 }); | 29 |
| 30 test('Message with one numeric', () { | |
| 31 intl_oneNumeric(num) | |
| 32 //@desc Tell the user about their lucky number. | |
| 33 => "Your lucky number is $num"; | |
| 34 var msg_format = new MessageFormat(); | |
| 35 var result = msg_format.formatMessage(intl_oneNumeric,42); | |
| 36 Expect.stringEquals(result,"Your lucky number is 42"); | |
| 37 }); | |
| 38 | |
| 39 /** | |
| 40 * Test for the simple error of evaluating the message function before passing i t in. | |
| 41 **/ | |
| 42 | |
| 43 test('Evaluate the function by mistake', () { | |
| 44 intl_oopsie() | |
| 45 » //@desc Doesn't matter | |
|
Emily Fortuna
2012/06/02 01:19:26
get rid of tabs ==> replace with spaces.
Alan Knight
2012/06/02 02:19:44
Done.
| |
| 46 » => "You want to pass the formatter the function, not the string"; | |
| 47 » var msg_format = new MessageFormat(); | |
| 48 » expectThrow(()=>msg_format.formatMessage(intl_oopsie(),null));» | |
| 49 }); | |
| 50 | |
| 51 | |
| 52 test('Complex message with plural', () { | |
| 53 var intl = new Intl(); | |
| 54 » var df = intl.date; | |
| 55 intl_howManyPeopleAreHere (NUM) | |
| 56 » //@desc Lists how many people are here | |
| 57 » => "There ${intl.plural(NUM,{'0': 'are', '1': 'is', 'other': 'are'})} " | |
| 58 » "$NUM other ${intl.plural(NUM, {'1':'person', 'other': 'people'})} here."; | |
| 59 » var msg_format = new MessageFormat(); | |
| 60 » Expect.stringEquals( | |
| 61 » msg_format.formatMessage(intl_howManyPeopleAreHere,0), | |
| 62 "There are 0 other people here."); | |
| 63 » Expect.stringEquals( | |
| 64 » » msg_format.formatMessage(intl_howManyPeopleAreHere,1), | |
| 65 » » "There is 1 other person here."); | |
| 66 » Expect.stringEquals( | |
| 67 » » msg_format.formatMessage(intl_howManyPeopleAreHere,2), | |
| 68 » » "There are 2 other people here."); | |
| 69 });» | |
| 70 » | |
| 71 | |
| 72 test('MessageFormat with message', () { | |
| 73 intl_mapArgument (dict) | |
| 74 // @desc Lists person's name | |
| 75 => "Hello, my name is ${dict['firstName']} ${dict['lastName']}"; | |
| 76 » | |
| 77 » var msg_format = new MessageFormat.on(intl_mapArgument); | |
| 78 » var person = {'firstName' : 'Ford', 'lastName': 'Prefect'}; | |
| 79 » Expect.stringEquals(msg_format.format(person), "Hello, my name is Ford Prefect"); | |
| 80 | |
| 81 }); | |
| 82 | |
| 28 } | 83 } |
| OLD | NEW |