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

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

Issue 12733003: Adds facilities for extracting Intl.message calls and generating code from translations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 /**
6 * Tests the Intl.message facility in dart with no localization, so we
7 * expect it to just return the same strings it was given, with parameter
8 * substitution, pluralization, and so forth.
9 */
5 library intl_message_test; 10 library intl_message_test;
6 11
7 import '../lib/intl.dart'; 12 import 'package:intl/intl.dart';
8 import '../../../pkg/unittest/lib/unittest.dart'; 13 import 'package:intl/src/intl_helpers.dart';
9 import '../lib/message_lookup_local.dart'; 14 import 'package:unittest/unittest.dart';
10 15 import 'package:intl/message_lookup_by_library.dart';
11 /** Tests the MessageFormat library in dart. */ 16 import 'dart:async';
12 17
13 class Person { 18 class Person {
14 String firstName, lastName; 19 String firstName, lastName;
15 Person(this.firstName, this.lastName); 20 Person(this.firstName, this.lastName);
16 } 21 }
17 22
18 main() { 23 main() {
19 test('Run all tests', () { 24 test('Run all tests', () {
20 initializeMessages('en_US').then(expectAsync1(runTests)); 25 initializeMessages('en_US').then(expectAsync1(runTests));
21 }); 26 });
22 } 27 }
23 28
29 initializeMessages(String localeName) {
30 initializeInternalMessageLookup(() => new CompositeMessageLookup());
31 messageLookup.addLocale(localeName, (_) => null);
32 return new Future.immediate(null);
Emily Fortuna 2013/03/13 18:54:43 do you need to return a future here if it's always
Alan Knight 2013/03/14 17:49:05 Hmm. Actually, I think the thing to do is delete t
33 }
34
24 runTests(_) { 35 runTests(_) {
25 test('Trivial Message', () { 36 test('Trivial Message', () {
26 hello() => Intl.message('Hello, world!', 37 hello() => Intl.message('Hello, world!',
27 desc: 'hello world string'); 38 desc: 'hello world string');
28 expect(hello(), completion(equals('Hello, world!'))); 39 expect(hello(), 'Hello, world!');
29 }); 40 });
30 41
31 test('Message with one parameter', () { 42 test('Message with one parameter', () {
32 lucky(number) => Intl.message('Your lucky number is $number', 43 lucky(number) => Intl.message('Your lucky number is $number',
33 desc: 'number str', examples: {'number': 2}); 44 desc: 'number str', examples: {'number': 2});
34 expect(lucky(3), completion(equals('Your lucky number is 3'))); 45 expect(lucky(3), 'Your lucky number is 3');
35 }); 46 });
36 47
37 test('Message with multiple plural cases (whole message)', () { 48 test('Message with multiple plural cases (whole message)', () {
38 emails(number) => Intl.message( 49 emails(number) => Intl.message(
39 Intl.plural(number, 50 Intl.plural(number,
40 {'0': 'There are no emails left.', 51 {'0': 'There are no emails left.',
41 '1': 'There is one email left.', 52 '1': 'There is one email left.',
42 'other': 'There are $number emails left.'}), 53 'other': 'There are $number emails left.'}),
43 desc: 'Message telling user how many emails will be sent.', 54 desc: 'Message telling user how many emails will be sent.',
44 examples: {'number': 32}); 55 examples: {'number': 32});
45 expect(emails(5), completion(equals('There are 5 emails left.'))); 56 expect(emails(5), 'There are 5 emails left.');
46 expect(emails(0), completion(equals('There are no emails left.'))); 57 expect(emails(0), 'There are no emails left.');
47 expect(emails(1), completion(equals('There is one email left.'))); 58 expect(emails(1), 'There is one email left.');
48 }); 59 });
49 60
50 test('Message with multiple plural cases (partial message)', () { 61 test('Message with multiple plural cases (partial message)', () {
51 emails(number) => Intl.message( 62 emails(number) => Intl.message(
52 "There ${Intl.plural(number, 63 "There ${Intl.plural(number,
53 {'0': 'are', 64 {'0': 'are',
54 '1': 'is', 65 '1': 'is',
55 'other': 'are'})} $number messages left.", 66 'other': 'are'})} $number messages left.",
56 desc: 'Message telling user how many emails will be sent.', 67 desc: 'Message telling user how many emails will be sent.',
57 examples: {'number': 32}); 68 examples: {'number': 32});
58 expect(emails(5), completion(equals('There are 5 messages left.'))); 69 expect(emails(5), 'There are 5 messages left.');
59 expect(emails(0), completion(equals('There are 0 messages left.'))); 70 expect(emails(0), 'There are 0 messages left.');
60 expect(emails(1), completion(equals('There is 1 messages left.'))); 71 expect(emails(1), 'There is 1 messages left.');
61 }); 72 });
62 73
63 test('Message with dictionary parameter', () { 74 test('Message with dictionary parameter', () {
64 hello(dict) => Intl.message( 75 hello(dict) => Intl.message(
65 "Hello, my name is ${dict['first']} ${dict['last']}", 76 "Hello, my name is ${dict['first']} ${dict['last']}",
66 desc: "States a person's name.", 77 desc: "States a person's name.",
67 examples: {'first': 'Ford', 'last': 'Prefect'}); 78 examples: {'first': 'Ford', 'last': 'Prefect'});
68 expect(hello({'first' : 'Ford', 'last' : 'Prefect'}), 79 expect(hello({'first' : 'Ford', 'last' : 'Prefect'}),
69 completion(equals('Hello, my name is Ford Prefect'))); 80 'Hello, my name is Ford Prefect');
70 }); 81 });
71 82
72 test('Message with object parameter', () { 83 test('Message with object parameter', () {
73 hello(person) => Intl.message( 84 hello(person) => Intl.message(
74 "Hello, my name is ${person.firstName} ${person.lastName}.", 85 "Hello, my name is ${person.firstName} ${person.lastName}.",
75 desc: "States a person's name.", 86 desc: "States a person's name.",
76 examples: {'first': 'Ford', 'last' : 'Prefect'}); 87 examples: {'first': 'Ford', 'last' : 'Prefect'});
77 var ford = new Person('Ford', 'Prefect'); 88 var ford = new Person('Ford', 'Prefect');
78 expect(hello(ford), completion(equals('Hello, my name is Ford Prefect.'))); 89 expect(hello(ford), 'Hello, my name is Ford Prefect.');
79 }); 90 });
80 91
81 test('WithLocale test', () { 92 test('WithLocale test', () {
82 hello() => Intl.message('locale=${Intl.getCurrentLocale()}', 93 hello() => Intl.message('locale=${Intl.getCurrentLocale()}',
83 desc: 'explains the locale'); 94 desc: 'explains the locale');
84 expect(Intl.withLocale('en-US', () => hello()), 95 expect(Intl.withLocale('en-US', () => hello()), 'locale=en-US');
85 completion(equals('locale=en-US')));
86 }); 96 });
87 97
88 test('Test passing locale', () { 98 test('Test passing locale', () {
89 hello(a_locale) => Intl.message('locale=${Intl.getCurrentLocale()}', 99 hello(a_locale) => Intl.message('locale=${Intl.getCurrentLocale()}',
90 desc: 'explains the locale', locale: a_locale); 100 desc: 'explains the locale', locale: a_locale);
91 expect(hello('en-US'), completion(equals('locale=en_US'))); 101 expect(hello('en-US'), 'locale=en_US');
92 }); 102 });
93 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698