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

Unified 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: Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« lib/i18n/message_format.dart ('K') | « lib/i18n/message_format.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/i18n/message_format_test.dart
diff --git a/tests/lib/i18n/message_format_test.dart b/tests/lib/i18n/message_format_test.dart
index f75532df710aedf7c2b265dba8ddad8a23187e09..dc02f0414ef070e0d560ea497e3e7ad50122aa8f 100644
--- a/tests/lib/i18n/message_format_test.dart
+++ b/tests/lib/i18n/message_format_test.dart
@@ -7,22 +7,77 @@
#library('message_format_test');
#import('../../../lib/i18n/message_format.dart');
+#import('../../../lib/i18n/intl.dart');
#import('../../../lib/unittest/unittest.dart');
+
/**
* Tests the MessageFormat library in dart.
*/
main() {
- test('Message formatting', () {
- var msg_format = new MessageFormat(
- 'Message telling user how many emails will be sent.',
- '''{NUM_EMAILS_TO_SEND, plural,
- =0 {unused plural form}
- =1 {One email will be sent.}
- other {# emails will be sent.}}''');
- // TODO(efortuna): Uncomment when functioning correctly.
- //Expect.stringEquals('5 emails will be sent.',
- // msg_formatter.format({'NUM_EMAILS_TO_SEND' : 5}));
- });
+
+ test('Trivial message', () {
+ intl_helloWorld()
+ //@desc Hello world, doesn't get much simpler than this.
+ => "Hello World";
+ var msg_format = new MessageFormat();
+ var result = msg_format.formatMessage(intl_helloWorld,null);
+ Expect.stringEquals(result,"Hello World");
+});
Emily Fortuna 2012/06/02 01:19:26 this line should be indented two spaces, I believe
Alan Knight 2012/06/02 02:19:44 Done.
+
+
+ test('Message with one numeric', () {
+ intl_oneNumeric(num)
+ //@desc Tell the user about their lucky number.
+ => "Your lucky number is $num";
+ var msg_format = new MessageFormat();
+ var result = msg_format.formatMessage(intl_oneNumeric,42);
+ Expect.stringEquals(result,"Your lucky number is 42");
+});
+
+/**
+ * Test for the simple error of evaluating the message function before passing it in.
+**/
+
+ test('Evaluate the function by mistake', () {
+ intl_oopsie()
+ //@desc Doesn't matter
Emily Fortuna 2012/06/02 01:19:26 get rid of tabs ==> replace with spaces.
Alan Knight 2012/06/02 02:19:44 Done.
+ => "You want to pass the formatter the function, not the string";
+ var msg_format = new MessageFormat();
+ expectThrow(()=>msg_format.formatMessage(intl_oopsie(),null));
+});
+
+
+ test('Complex message with plural', () {
+ var intl = new Intl();
+ var df = intl.date;
+ intl_howManyPeopleAreHere (NUM)
+ //@desc Lists how many people are here
+ => "There ${intl.plural(NUM,{'0': 'are', '1': 'is', 'other': 'are'})} "
+ "$NUM other ${intl.plural(NUM, {'1':'person', 'other': 'people'})} here.";
+ var msg_format = new MessageFormat();
+ Expect.stringEquals(
+ msg_format.formatMessage(intl_howManyPeopleAreHere,0),
+ "There are 0 other people here.");
+ Expect.stringEquals(
+ msg_format.formatMessage(intl_howManyPeopleAreHere,1),
+ "There is 1 other person here.");
+ Expect.stringEquals(
+ msg_format.formatMessage(intl_howManyPeopleAreHere,2),
+ "There are 2 other people here.");
+});
+
+
+ test('MessageFormat with message', () {
+ intl_mapArgument (dict)
+ // @desc Lists person's name
+ => "Hello, my name is ${dict['firstName']} ${dict['lastName']}";
+
+ var msg_format = new MessageFormat.on(intl_mapArgument);
+ var person = {'firstName' : 'Ford', 'lastName': 'Prefect'};
+ Expect.stringEquals(msg_format.format(person), "Hello, my name is Ford Prefect");
+
+});
+
}
« 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