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

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

Issue 10494005: Updated message formatting to be more compatible with Dart string interpolation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mostly formatting 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
« no previous file with comments | « lib/i18n/message_format.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 /** 1 /**
2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 * for details. All rights reserved. Use of this source code is governed by a 3 * for details. All rights reserved. Use of this source code is governed by a
4 * BSD-style license that can be found in the LICENSE file. 4 * BSD-style license that can be found in the LICENSE file.
5 */ 5 */
6 6
7 #library('message_format_test'); 7 #library('message_format_test');
8 8
9 #import('../../../lib/i18n/message_format.dart'); 9 #import('../../../lib/i18n/message_format.dart');
10 #import('../../../lib/i18n/intl.dart');
10 #import('../../../lib/unittest/unittest.dart'); 11 #import('../../../lib/unittest/unittest.dart');
11 12
13
12 /** 14 /**
13 * Tests the MessageFormat library in dart. 15 * Tests the MessageFormat library in dart.
14 */ 16 */
15 17
16 main() { 18 main() {
17 test('Message formatting', () { 19
18 var msg_format = new MessageFormat( 20 test('Trivial message', () {
19 'Message telling user how many emails will be sent.', 21 intl_helloWorld()
20 '''{NUM_EMAILS_TO_SEND, plural, 22 //@desc Hello world, doesn't get much simpler than this.
21 =0 {unused plural form} 23 => "Hello World";
22 =1 {One email will be sent.} 24 var msg_format = new MessageFormat();
23 other {# emails will be sent.}}'''); 25 var result = msg_format.formatMessage(intl_helloWorld,null);
24 // TODO(efortuna): Uncomment when functioning correctly. 26 Expect.stringEquals(result,"Hello World");
25 //Expect.stringEquals('5 emails will be sent.',
26 // msg_formatter.format({'NUM_EMAILS_TO_SEND' : 5}));
27 }); 27 });
28
29 test('Message with one numeric', () {
30 intl_oneNumeric(num)
31 //@desc Tell the user about their lucky number.
32 => "Your lucky number is $num";
33 var msg_format = new MessageFormat();
34 var result = msg_format.formatMessage(intl_oneNumeric,42);
35 Expect.stringEquals(result,"Your lucky number is 42");
36 });
37
38 /**
39 * Test for the simple error of evaluating the message function before
40 * passing it in.
41 */
42
43 test('Evaluate the function by mistake', () {
44 intl_oopsie()
45 //@desc Doesn't matter
46 => "You want to pass the formatter the function, not the string";
47 var msg_format = new MessageFormat();
48 expectThrow(()=>msg_format.formatMessage(intl_oopsie(),null));
49 });
50
51 test('Complex message with plural', () {
52 var intl = new Intl();
53 var df = intl.date;
54 intl_howManyPeopleAreHere (NUM) =>
55 //@desc Lists how many people are here
56 "There ${intl.plural(NUM,{'0': 'are', '1': 'is', 'other': 'are'})} "
57 "$NUM other ${intl.plural(NUM, {'1':'person', 'other': 'people'})} here.";
58 var msg_format = new MessageFormat();
59 Expect.stringEquals(
60 msg_format.formatMessage(intl_howManyPeopleAreHere,0),
61 "There are 0 other people here.");
62 Expect.stringEquals(
63 msg_format.formatMessage(intl_howManyPeopleAreHere,1),
64 "There is 1 other person here.");
65 Expect.stringEquals(
66 msg_format.formatMessage(intl_howManyPeopleAreHere,2),
67 "There are 2 other people here.");
68 });
69
70 test('MessageFormat with message', () {
71 intl_mapArgument (dict)
72 // @desc Lists person's name
73 => "Hello, my name is ${dict['firstName']} ${dict['lastName']}";
74 var msg_format = new MessageFormat(intl_mapArgument);
75 var person = {'firstName' : 'Ford', 'lastName': 'Prefect'};
76 Expect.stringEquals(
77 msg_format.format(person),
78 "Hello, my name is Ford Prefect");
79 });
80
28 } 81 }
OLDNEW
« no previous file with comments | « lib/i18n/message_format.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698