Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 #library('intl_message_test'); | 6 #library('intl_message_test'); |
| 7 | 7 |
| 8 #import('../../../lib/i18n/intl.dart'); | 8 #import('../../../lib/i18n/intl.dart'); |
| 9 #import('../../../lib/i18n/intl_message.dart'); | 9 #import('../../../lib/i18n/intl_message.dart'); |
| 10 #import('../../../lib/unittest/unittest.dart'); | 10 #import('../../../lib/unittest/unittest.dart'); |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * Tests the MessageFormat library in dart. | 13 * Tests the MessageFormat library in dart. |
| 14 */ | 14 */ |
| 15 | 15 |
| 16 | |
|
Emily Fortuna
2012/06/08 21:50:37
get rid of extra whitespace, please
Alan Knight
2012/06/08 22:04:53
Done.
| |
| 17 class Person { | |
| 18 String firstName, lastName; | |
| 19 Person(this.firstName, this.lastName); | |
| 20 } | |
| 21 | |
| 16 main() { | 22 main() { |
| 23 | |
|
Emily Fortuna
2012/06/08 21:50:37
extra whitespace
Alan Knight
2012/06/08 22:04:53
I thought this was useful as being something that'
Emily Fortuna
2012/06/08 22:09:40
The problem is not the whitespace at line 25, but
Alan Knight
2012/06/08 22:14:21
Ah, ok. Done.
| |
| 24 Intl intl = new Intl(); | |
| 25 | |
| 17 test('Trivial Message', () { | 26 test('Trivial Message', () { |
| 18 msg_format() => new IntlMessage('Hello, world!', | 27 hello() => intl.message('Hello, world!', |
| 19 desc: 'hello world string'); | 28 desc: 'hello world string'); |
| 29 expect(hello(), equals('Hello, world!')); | |
| 20 }); | 30 }); |
| 21 //expect(msg_format(), 'Hello, world!'); | |
| 22 | 31 |
| 23 test('One num', () { | 32 test('Message with one parameter', () { |
| 24 msg_format(number) => new IntlMessage('Your lucky number is $number', | 33 lucky(number) => intl.message('Your lucky number is $number', |
| 25 desc: 'number str', examples: {'number': 2}); | 34 desc: 'number str', examples: {'number': 2}); |
| 35 expect(lucky(3), equals('Your lucky number is 3')); | |
| 26 }); | 36 }); |
| 27 //expect(msg_format(3), 'Your lucky number is 3'); | |
| 28 | 37 |
| 29 test('Message formatting', () { | 38 test('Message with multiple plural cases (whole message)', () { |
| 30 msg_format(number) => new IntlMessage( | 39 emails(number) => intl.message( |
| 31 Intl.plural(number, | 40 Intl.plural(number, |
| 32 {'0': 'There are no emails left.', | 41 {'0': 'There are no emails left.', |
| 33 '1': 'There is one email left.', | 42 '1': 'There is one email left.', |
| 34 'other': 'There are $number emails left.'}), | 43 'other': 'There are $number emails left.'}), |
| 35 desc: 'Message telling user how many emails will be sent.', | 44 desc: 'Message telling user how many emails will be sent.', |
| 36 examples: {'number': 32}); | 45 examples: {'number': 32}); |
| 46 expect(emails(5), equals('There are 5 emails left.')); | |
| 47 expect(emails(0), equals('There are no emails left.')); | |
| 48 expect(emails(1), equals('There is one email left.')); | |
| 37 }); | 49 }); |
| 38 // TODO(efortuna): Uncomment when functioning correctly. | 50 |
| 39 //expect(msg_format(5), '5 emails will be sent.'); | 51 test('Message with multiple plural cases (partial message)', () { |
| 40 | 52 emails(number) => intl.message( |
| 41 test('Message formatting with dictionary', () { | 53 "There ${Intl.plural(number, |
| 42 msg_format(dict) => new IntlMessage( | 54 {'0': 'are', |
| 55 '1': 'is', | |
| 56 'other': 'are'})} $number messages left.", | |
| 57 desc: 'Message telling user how many emails will be sent.', | |
| 58 examples: {'number': 32}); | |
| 59 expect(emails(5), equals('There are 5 messages left.')); | |
| 60 expect(emails(0), equals('There are 0 messages left.')); | |
| 61 expect(emails(1), equals('There is 1 messages left.')); | |
| 62 }); | |
| 63 | |
| 64 test('Message with dictionary parameter', () { | |
| 65 hello(dict) => intl.message( | |
| 43 "Hello, my name is ${dict['first']} ${dict['last']}", | 66 "Hello, my name is ${dict['first']} ${dict['last']}", |
| 44 desc: "States a person's name.", | 67 desc: "States a person's name.", |
| 45 examples: {'first': 'Ford', 'last': 'Prefect'}); | 68 examples: {'first': 'Ford', 'last': 'Prefect'}); |
| 69 expect(hello({'first' : 'Ford', 'last' : 'Prefect'}), | |
| 70 equals('Hello, my name is Ford Prefect')); | |
| 46 }); | 71 }); |
| 47 //expect(msg_format({'first' : 'Ford', 'last' : 'Prefect'), | 72 |
| 48 // 'Hello, my name is Ford Prefect'); | 73 test('Message with object parameter', () { |
| 74 hello(person) => intl.message( | |
| 75 "Hello, my name is ${person.firstName} ${person.lastName}.", | |
| 76 desc: "States a person's name.", | |
| 77 examples: {'first': 'Ford', 'last' : 'Prefect'}); | |
| 78 var ford = new Person('Ford', 'Prefect'); | |
| 79 expect(hello(ford), equals('Hello, my name is Ford Prefect.')); | |
| 80 }); | |
| 49 } | 81 } |
| OLD | NEW |