| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 | |
| 6 #library('intl_message_test'); | |
| 7 | |
| 8 #import('../../../pkg/i18n/intl.dart'); | |
| 9 #import('../../../lib/unittest/unittest.dart'); | |
| 10 | |
| 11 /** Tests the MessageFormat library in dart. */ | |
| 12 | |
| 13 class Person { | |
| 14 String firstName, lastName; | |
| 15 Person(this.firstName, this.lastName); | |
| 16 } | |
| 17 | |
| 18 main() { | |
| 19 test('Trivial Message', () { | |
| 20 hello() => Intl.message('Hello, world!', | |
| 21 desc: 'hello world string'); | |
| 22 expect(hello(), equals('Hello, world!')); | |
| 23 }); | |
| 24 | |
| 25 test('Message with one parameter', () { | |
| 26 lucky(number) => Intl.message('Your lucky number is $number', | |
| 27 desc: 'number str', examples: {'number': 2}); | |
| 28 expect(lucky(3), equals('Your lucky number is 3')); | |
| 29 }); | |
| 30 | |
| 31 test('Message with multiple plural cases (whole message)', () { | |
| 32 emails(number) => Intl.message( | |
| 33 Intl.plural(number, | |
| 34 {'0': 'There are no emails left.', | |
| 35 '1': 'There is one email left.', | |
| 36 'other': 'There are $number emails left.'}), | |
| 37 desc: 'Message telling user how many emails will be sent.', | |
| 38 examples: {'number': 32}); | |
| 39 expect(emails(5), equals('There are 5 emails left.')); | |
| 40 expect(emails(0), equals('There are no emails left.')); | |
| 41 expect(emails(1), equals('There is one email left.')); | |
| 42 }); | |
| 43 | |
| 44 test('Message with multiple plural cases (partial message)', () { | |
| 45 emails(number) => Intl.message( | |
| 46 "There ${Intl.plural(number, | |
| 47 {'0': 'are', | |
| 48 '1': 'is', | |
| 49 'other': 'are'})} $number messages left.", | |
| 50 desc: 'Message telling user how many emails will be sent.', | |
| 51 examples: {'number': 32}); | |
| 52 expect(emails(5), equals('There are 5 messages left.')); | |
| 53 expect(emails(0), equals('There are 0 messages left.')); | |
| 54 expect(emails(1), equals('There is 1 messages left.')); | |
| 55 }); | |
| 56 | |
| 57 test('Message with dictionary parameter', () { | |
| 58 hello(dict) => Intl.message( | |
| 59 "Hello, my name is ${dict['first']} ${dict['last']}", | |
| 60 desc: "States a person's name.", | |
| 61 examples: {'first': 'Ford', 'last': 'Prefect'}); | |
| 62 expect(hello({'first' : 'Ford', 'last' : 'Prefect'}), | |
| 63 equals('Hello, my name is Ford Prefect')); | |
| 64 }); | |
| 65 | |
| 66 test('Message with object parameter', () { | |
| 67 hello(person) => Intl.message( | |
| 68 "Hello, my name is ${person.firstName} ${person.lastName}.", | |
| 69 desc: "States a person's name.", | |
| 70 examples: {'first': 'Ford', 'last' : 'Prefect'}); | |
| 71 var ford = new Person('Ford', 'Prefect'); | |
| 72 expect(hello(ford), equals('Hello, my name is Ford Prefect.')); | |
| 73 }); | |
| 74 | |
| 75 test('WithLocale test', () { | |
| 76 hello() => Intl.message('locale=${Intl.getCurrentLocale()}', | |
| 77 desc: 'explains the locale'); | |
| 78 expect(Intl.withLocale('en-US', () => hello()), equals('locale=en-US')); | |
| 79 }); | |
| 80 | |
| 81 test('Test passing locale', () { | |
| 82 hello(a_locale) => Intl.message('locale=${Intl.getCurrentLocale()}', | |
| 83 desc: 'explains the locale', locale: a_locale); | |
| 84 expect(hello('en-US'), equals('locale=en_US')); | |
| 85 }); | |
| 86 } | |
| OLD | NEW |