Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: pkg/intl/test/intl_message_test.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 library intl_message_test; 5 library intl_message_test;
6 6
7 import '../lib/intl.dart'; 7 import '../lib/intl.dart';
8 import '../../../pkg/unittest/lib/unittest.dart'; 8 import '../../../pkg/unittest/lib/unittest.dart';
9 import '../lib/message_lookup_local.dart'; 9 import '../lib/message_lookup_local.dart';
10 10
11 /** Tests the MessageFormat library in dart. */ 11 /** Tests the MessageFormat library in dart. */
12 12
13 class Person { 13 class Person {
14 String firstName, lastName; 14 String firstName, lastName;
15 Person(this.firstName, this.lastName); 15 Person(this.firstName, this.lastName);
16 } 16 }
17 17
18 main() { 18 main() {
19 test('Run all tests', () { 19 test('Run all tests', () {
20 initializeMessages('en_US').then(expectAsync1(runTests)); 20 initializeMessages('en_US').then(expectAsync1(runTests));
21 }); 21 });
22 } 22 }
23 23
24 runTests(_) { 24 runTests(_) {
25 test('Trivial Message', () { 25 test('Trivial Message', () {
26 hello() => Intl.message('Hello, world!', 26 hello() => Intl.message('Hello, world!',
27 desc: 'hello world string'); 27 desc: 'hello world string');
28 expect(hello(), equals('Hello, world!')); 28 expect(hello(), completion(equals('Hello, world!')));
29 }); 29 });
30 30
31 test('Message with one parameter', () { 31 test('Message with one parameter', () {
32 lucky(number) => Intl.message('Your lucky number is $number', 32 lucky(number) => Intl.message('Your lucky number is $number',
33 desc: 'number str', examples: {'number': 2}); 33 desc: 'number str', examples: {'number': 2});
34 expect(lucky(3), equals('Your lucky number is 3')); 34 expect(lucky(3), completion(equals('Your lucky number is 3')));
35 }); 35 });
36 36
37 test('Message with multiple plural cases (whole message)', () { 37 test('Message with multiple plural cases (whole message)', () {
38 emails(number) => Intl.message( 38 emails(number) => Intl.message(
39 Intl.plural(number, 39 Intl.plural(number,
40 {'0': 'There are no emails left.', 40 {'0': 'There are no emails left.',
41 '1': 'There is one email left.', 41 '1': 'There is one email left.',
42 'other': 'There are $number emails left.'}), 42 'other': 'There are $number emails left.'}),
43 desc: 'Message telling user how many emails will be sent.', 43 desc: 'Message telling user how many emails will be sent.',
44 examples: {'number': 32}); 44 examples: {'number': 32});
45 expect(emails(5), equals('There are 5 emails left.')); 45 expect(emails(5), completion(equals('There are 5 emails left.')));
46 expect(emails(0), equals('There are no emails left.')); 46 expect(emails(0), completion(equals('There are no emails left.')));
47 expect(emails(1), equals('There is one email left.')); 47 expect(emails(1), completion(equals('There is one email left.')));
48 }); 48 });
49 49
50 test('Message with multiple plural cases (partial message)', () { 50 test('Message with multiple plural cases (partial message)', () {
51 emails(number) => Intl.message( 51 emails(number) => Intl.message(
52 "There ${Intl.plural(number, 52 "There ${Intl.plural(number,
53 {'0': 'are', 53 {'0': 'are',
54 '1': 'is', 54 '1': 'is',
55 'other': 'are'})} $number messages left.", 55 'other': 'are'})} $number messages left.",
56 desc: 'Message telling user how many emails will be sent.', 56 desc: 'Message telling user how many emails will be sent.',
57 examples: {'number': 32}); 57 examples: {'number': 32});
58 expect(emails(5), equals('There are 5 messages left.')); 58 expect(emails(5), completion(equals('There are 5 messages left.')));
59 expect(emails(0), equals('There are 0 messages left.')); 59 expect(emails(0), completion(equals('There are 0 messages left.')));
60 expect(emails(1), equals('There is 1 messages left.')); 60 expect(emails(1), completion(equals('There is 1 messages left.')));
61 }); 61 });
62 62
63 test('Message with dictionary parameter', () { 63 test('Message with dictionary parameter', () {
64 hello(dict) => Intl.message( 64 hello(dict) => Intl.message(
65 "Hello, my name is ${dict['first']} ${dict['last']}", 65 "Hello, my name is ${dict['first']} ${dict['last']}",
66 desc: "States a person's name.", 66 desc: "States a person's name.",
67 examples: {'first': 'Ford', 'last': 'Prefect'}); 67 examples: {'first': 'Ford', 'last': 'Prefect'});
68 expect(hello({'first' : 'Ford', 'last' : 'Prefect'}), 68 expect(hello({'first' : 'Ford', 'last' : 'Prefect'}),
69 equals('Hello, my name is Ford Prefect')); 69 completion(equals('Hello, my name is Ford Prefect')));
70 }); 70 });
71 71
72 test('Message with object parameter', () { 72 test('Message with object parameter', () {
73 hello(person) => Intl.message( 73 hello(person) => Intl.message(
74 "Hello, my name is ${person.firstName} ${person.lastName}.", 74 "Hello, my name is ${person.firstName} ${person.lastName}.",
75 desc: "States a person's name.", 75 desc: "States a person's name.",
76 examples: {'first': 'Ford', 'last' : 'Prefect'}); 76 examples: {'first': 'Ford', 'last' : 'Prefect'});
77 var ford = new Person('Ford', 'Prefect'); 77 var ford = new Person('Ford', 'Prefect');
78 expect(hello(ford), equals('Hello, my name is Ford Prefect.')); 78 expect(hello(ford), completion(equals('Hello, my name is Ford Prefect.')));
79 }); 79 });
80 80
81 test('WithLocale test', () { 81 test('WithLocale test', () {
82 hello() => Intl.message('locale=${Intl.getCurrentLocale()}', 82 hello() => Intl.message('locale=${Intl.getCurrentLocale()}',
83 desc: 'explains the locale'); 83 desc: 'explains the locale');
84 expect(Intl.withLocale('en-US', () => hello()), equals('locale=en-US')); 84 expect(Intl.withLocale('en-US', () => hello()),
85 completion(equals('locale=en-US')));
85 }); 86 });
86 87
87 test('Test passing locale', () { 88 test('Test passing locale', () {
88 hello(a_locale) => Intl.message('locale=${Intl.getCurrentLocale()}', 89 hello(a_locale) => Intl.message('locale=${Intl.getCurrentLocale()}',
89 desc: 'explains the locale', locale: a_locale); 90 desc: 'explains the locale', locale: a_locale);
90 expect(hello('en-US'), equals('locale=en_US')); 91 expect(hello('en-US'), completion(equals('locale=en_US')));
91 }); 92 });
92 } 93 }
OLDNEW
« no previous file with comments | « pkg/intl/test/date_time_format_test_core.dart ('k') | pkg/intl/tool/generate_locale_data_files.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698