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

Side by Side Diff: tests/lib/i18n/intl_message_test.dart

Issue 10536105: Make Intl.message static (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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
« lib/i18n/intl.dart ('K') | « lib/i18n/intl_message.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 { 16 class Person {
17 String firstName, lastName; 17 String firstName, lastName;
18 Person(this.firstName, this.lastName); 18 Person(this.firstName, this.lastName);
19 } 19 }
20 20
21 main() { 21 main() {
22 Intl intl = new Intl();
23
24 test('Trivial Message', () { 22 test('Trivial Message', () {
25 hello() => intl.message('Hello, world!', 23 hello() => Intl.message('Hello, world!',
26 desc: 'hello world string'); 24 desc: 'hello world string');
27 expect(hello(), equals('Hello, world!')); 25 expect(hello(), equals('Hello, world!'));
28 }); 26 });
29 27
30 test('Message with one parameter', () { 28 test('Message with one parameter', () {
31 lucky(number) => intl.message('Your lucky number is $number', 29 lucky(number) => Intl.message('Your lucky number is $number',
32 desc: 'number str', examples: {'number': 2}); 30 desc: 'number str', examples: {'number': 2});
33 expect(lucky(3), equals('Your lucky number is 3')); 31 expect(lucky(3), equals('Your lucky number is 3'));
34 }); 32 });
35 33
36 test('Message with multiple plural cases (whole message)', () { 34 test('Message with multiple plural cases (whole message)', () {
37 emails(number) => intl.message( 35 emails(number) => Intl.message(
38 Intl.plural(number, 36 Intl.plural(number,
39 {'0': 'There are no emails left.', 37 {'0': 'There are no emails left.',
40 '1': 'There is one email left.', 38 '1': 'There is one email left.',
41 'other': 'There are $number emails left.'}), 39 'other': 'There are $number emails left.'}),
42 desc: 'Message telling user how many emails will be sent.', 40 desc: 'Message telling user how many emails will be sent.',
43 examples: {'number': 32}); 41 examples: {'number': 32});
44 expect(emails(5), equals('There are 5 emails left.')); 42 expect(emails(5), equals('There are 5 emails left.'));
45 expect(emails(0), equals('There are no emails left.')); 43 expect(emails(0), equals('There are no emails left.'));
46 expect(emails(1), equals('There is one email left.')); 44 expect(emails(1), equals('There is one email left.'));
47 }); 45 });
48 46
49 test('Message with multiple plural cases (partial message)', () { 47 test('Message with multiple plural cases (partial message)', () {
50 emails(number) => intl.message( 48 emails(number) => Intl.message(
51 "There ${Intl.plural(number, 49 "There ${Intl.plural(number,
52 {'0': 'are', 50 {'0': 'are',
53 '1': 'is', 51 '1': 'is',
54 'other': 'are'})} $number messages left.", 52 'other': 'are'})} $number messages left.",
55 desc: 'Message telling user how many emails will be sent.', 53 desc: 'Message telling user how many emails will be sent.',
56 examples: {'number': 32}); 54 examples: {'number': 32});
57 expect(emails(5), equals('There are 5 messages left.')); 55 expect(emails(5), equals('There are 5 messages left.'));
58 expect(emails(0), equals('There are 0 messages left.')); 56 expect(emails(0), equals('There are 0 messages left.'));
59 expect(emails(1), equals('There is 1 messages left.')); 57 expect(emails(1), equals('There is 1 messages left.'));
60 }); 58 });
61 59
62 test('Message with dictionary parameter', () { 60 test('Message with dictionary parameter', () {
63 hello(dict) => intl.message( 61 hello(dict) => Intl.message(
64 "Hello, my name is ${dict['first']} ${dict['last']}", 62 "Hello, my name is ${dict['first']} ${dict['last']}",
65 desc: "States a person's name.", 63 desc: "States a person's name.",
66 examples: {'first': 'Ford', 'last': 'Prefect'}); 64 examples: {'first': 'Ford', 'last': 'Prefect'});
67 expect(hello({'first' : 'Ford', 'last' : 'Prefect'}), 65 expect(hello({'first' : 'Ford', 'last' : 'Prefect'}),
68 equals('Hello, my name is Ford Prefect')); 66 equals('Hello, my name is Ford Prefect'));
69 }); 67 });
70 68
71 test('Message with object parameter', () { 69 test('Message with object parameter', () {
72 hello(person) => intl.message( 70 hello(person) => Intl.message(
73 "Hello, my name is ${person.firstName} ${person.lastName}.", 71 "Hello, my name is ${person.firstName} ${person.lastName}.",
74 desc: "States a person's name.", 72 desc: "States a person's name.",
75 examples: {'first': 'Ford', 'last' : 'Prefect'}); 73 examples: {'first': 'Ford', 'last' : 'Prefect'});
76 var ford = new Person('Ford', 'Prefect'); 74 var ford = new Person('Ford', 'Prefect');
77 expect(hello(ford), equals('Hello, my name is Ford Prefect.')); 75 expect(hello(ford), equals('Hello, my name is Ford Prefect.'));
78 }); 76 });
77
78 test('WithLocale test', () {
79 hello() => Intl.message('Hello, world!',
80 desc: 'hello world string');
81 expect(Intl.withLocale('en-US', () => hello()), equals('Hello, world!'));
Alan Knight 2012/06/13 00:52:32 But this doesn't actually test that the locale can
Emily Fortuna 2012/06/13 01:27:48 _locale is hidden, and I was planning on testing t
Alan Knight 2012/06/13 01:34:58 test('withLocale actually does something', () {
82 });
83
84 test('Test passing locale', () {
85 hello(a_locale) => Intl.message('Hello, world!',
86 desc: 'hello world string', locale: a_locale);
87 expect(hello('en-US'), equals('Hello, world!'));
88 });
79 } 89 }
OLDNEW
« lib/i18n/intl.dart ('K') | « lib/i18n/intl_message.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698