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

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: Changes made from review 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/message_format.dart ('K') | « 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
30 test('Message with one numeric', () {
31 intl_oneNumeric(num)
32 //@desc Tell the user about their lucky number.
33 => "Your lucky number is $num";
34 var msg_format = new MessageFormat();
35 var result = msg_format.formatMessage(intl_oneNumeric,42);
36 Expect.stringEquals(result,"Your lucky number is 42");
37 });
38
39 /**
40 * Test for the simple error of evaluating the message function before
41 * passing it in.
42 */
43
44 test('Evaluate the function by mistake', () {
Emily Fortuna 2012/06/05 00:30:39 lovely!
Alan Knight 2012/06/05 17:24:47 :-)
45 intl_oopsie()
46 //@desc Doesn't matter
47 => "You want to pass the formatter the function, not the string";
48 var msg_format = new MessageFormat();
49 expectThrow(()=>msg_format.formatMessage(intl_oopsie(),null));
50 });
51
52
53 test('Complex message with plural', () {
54 var intl = new Intl();
55 var df = intl.date;
56 intl_howManyPeopleAreHere (NUM) =>
57 //@desc Lists how many people are here
58 "There ${intl.plural(NUM,{'0': 'are', '1': 'is', 'other': 'are'})} "
59 "$NUM other ${intl.plural(NUM, {'1':'person', 'other': 'people'})} here.";
60 var msg_format = new MessageFormat();
61 Expect.stringEquals(
62 msg_format.formatMessage(intl_howManyPeopleAreHere,0),
63 "There are 0 other people here.");
64 Expect.stringEquals(
65 msg_format.formatMessage(intl_howManyPeopleAreHere,1),
66 "There is 1 other person here.");
67 Expect.stringEquals(
68 msg_format.formatMessage(intl_howManyPeopleAreHere,2),
69 "There are 2 other people here.");
70 });
71
72
73 test('MessageFormat with message', () {
74 intl_mapArgument (dict)
75 // @desc Lists person's name
76 => "Hello, my name is ${dict['firstName']} ${dict['lastName']}";
77
78 var msg_format = new MessageFormat(intl_mapArgument);
79 var person = {'firstName' : 'Ford', 'lastName': 'Prefect'};
80 Expect.stringEquals(
81 msg_format.format(person),
82 "Hello, my name is Ford Prefect");
83
84 });
85
28 } 86 }
OLDNEW
« lib/i18n/message_format.dart ('K') | « lib/i18n/message_format.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698