| 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 class Person { |
| 17 String firstName, lastName; |
| 18 Person(this.firstName, this.lastName); |
| 19 } |
| 20 |
| 16 main() { | 21 main() { |
| 22 Intl intl = new Intl(); |
| 23 |
| 17 test('Trivial Message', () { | 24 test('Trivial Message', () { |
| 18 msg_format() => new IntlMessage('Hello, world!', | 25 hello() => intl.message('Hello, world!', |
| 19 desc: 'hello world string'); | 26 desc: 'hello world string'); |
| 27 expect(hello(), equals('Hello, world!')); |
| 20 }); | 28 }); |
| 21 //expect(msg_format(), 'Hello, world!'); | |
| 22 | 29 |
| 23 test('One num', () { | 30 test('Message with one parameter', () { |
| 24 msg_format(number) => new IntlMessage('Your lucky number is $number', | 31 lucky(number) => intl.message('Your lucky number is $number', |
| 25 desc: 'number str', examples: {'number': 2}); | 32 desc: 'number str', examples: {'number': 2}); |
| 33 expect(lucky(3), equals('Your lucky number is 3')); |
| 26 }); | 34 }); |
| 27 //expect(msg_format(3), 'Your lucky number is 3'); | |
| 28 | 35 |
| 29 test('Message formatting', () { | 36 test('Message with multiple plural cases (whole message)', () { |
| 30 msg_format(number) => new IntlMessage( | 37 emails(number) => intl.message( |
| 31 Intl.plural(number, | 38 Intl.plural(number, |
| 32 {'0': 'There are no emails left.', | 39 {'0': 'There are no emails left.', |
| 33 '1': 'There is one email left.', | 40 '1': 'There is one email left.', |
| 34 'other': 'There are $number emails left.'}), | 41 'other': 'There are $number emails left.'}), |
| 35 desc: 'Message telling user how many emails will be sent.', | 42 desc: 'Message telling user how many emails will be sent.', |
| 36 examples: {'number': 32}); | 43 examples: {'number': 32}); |
| 44 expect(emails(5), equals('There are 5 emails left.')); |
| 45 expect(emails(0), equals('There are no emails left.')); |
| 46 expect(emails(1), equals('There is one email left.')); |
| 37 }); | 47 }); |
| 38 // TODO(efortuna): Uncomment when functioning correctly. | 48 |
| 39 //expect(msg_format(5), '5 emails will be sent.'); | 49 test('Message with multiple plural cases (partial message)', () { |
| 40 | 50 emails(number) => intl.message( |
| 41 test('Message formatting with dictionary', () { | 51 "There ${Intl.plural(number, |
| 42 msg_format(dict) => new IntlMessage( | 52 {'0': 'are', |
| 53 '1': 'is', |
| 54 'other': 'are'})} $number messages left.", |
| 55 desc: 'Message telling user how many emails will be sent.', |
| 56 examples: {'number': 32}); |
| 57 expect(emails(5), equals('There are 5 messages left.')); |
| 58 expect(emails(0), equals('There are 0 messages left.')); |
| 59 expect(emails(1), equals('There is 1 messages left.')); |
| 60 }); |
| 61 |
| 62 test('Message with dictionary parameter', () { |
| 63 hello(dict) => intl.message( |
| 43 "Hello, my name is ${dict['first']} ${dict['last']}", | 64 "Hello, my name is ${dict['first']} ${dict['last']}", |
| 44 desc: "States a person's name.", | 65 desc: "States a person's name.", |
| 45 examples: {'first': 'Ford', 'last': 'Prefect'}); | 66 examples: {'first': 'Ford', 'last': 'Prefect'}); |
| 67 expect(hello({'first' : 'Ford', 'last' : 'Prefect'}), |
| 68 equals('Hello, my name is Ford Prefect')); |
| 46 }); | 69 }); |
| 47 //expect(msg_format({'first' : 'Ford', 'last' : 'Prefect'), | 70 |
| 48 // 'Hello, my name is Ford Prefect'); | 71 test('Message with object parameter', () { |
| 72 hello(person) => intl.message( |
| 73 "Hello, my name is ${person.firstName} ${person.lastName}.", |
| 74 desc: "States a person's name.", |
| 75 examples: {'first': 'Ford', 'last' : 'Prefect'}); |
| 76 var ford = new Person('Ford', 'Prefect'); |
| 77 expect(hello(ford), equals('Hello, my name is Ford Prefect.')); |
| 78 }); |
| 49 } | 79 } |
| OLD | NEW |