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

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: Fixes from review comments, also made tests more robust, removed scheduled_test dependency 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library intl_message_test;
6
7 import '../lib/intl.dart';
8 import '../../../pkg/unittest/lib/unittest.dart';
9 import '../lib/message_lookup_local.dart';
10
11 /** Tests the MessageFormat library in dart. */
12
13 class Person {
14 String firstName, lastName;
15 Person(this.firstName, this.lastName);
16 }
17
18 main() {
19 test('Run all tests', () {
20 initializeMessages('en_US').then(expectAsync1(runTests));
21 });
22 }
23
24 runTests(_) {
25 test('Trivial Message', () {
26 hello() => Intl.message('Hello, world!',
27 desc: 'hello world string');
28 expect(hello(), completion(equals('Hello, world!')));
29 });
30
31 test('Message with one parameter', () {
32 lucky(number) => Intl.message('Your lucky number is $number',
33 desc: 'number str', examples: {'number': 2});
34 expect(lucky(3), completion(equals('Your lucky number is 3')));
35 });
36
37 test('Message with multiple plural cases (whole message)', () {
38 emails(number) => Intl.message(
39 Intl.plural(number,
40 {'0': 'There are no emails left.',
41 '1': 'There is one email left.',
42 'other': 'There are $number emails left.'}),
43 desc: 'Message telling user how many emails will be sent.',
44 examples: {'number': 32});
45 expect(emails(5), completion(equals('There are 5 emails left.')));
46 expect(emails(0), completion(equals('There are no emails left.')));
47 expect(emails(1), completion(equals('There is one email left.')));
48 });
49
50 test('Message with multiple plural cases (partial message)', () {
51 emails(number) => Intl.message(
52 "There ${Intl.plural(number,
53 {'0': 'are',
54 '1': 'is',
55 'other': 'are'})} $number messages left.",
56 desc: 'Message telling user how many emails will be sent.',
57 examples: {'number': 32});
58 expect(emails(5), completion(equals('There are 5 messages left.')));
59 expect(emails(0), completion(equals('There are 0 messages left.')));
60 expect(emails(1), completion(equals('There is 1 messages left.')));
61 });
62
63 test('Message with dictionary parameter', () {
64 hello(dict) => Intl.message(
65 "Hello, my name is ${dict['first']} ${dict['last']}",
66 desc: "States a person's name.",
67 examples: {'first': 'Ford', 'last': 'Prefect'});
68 expect(hello({'first' : 'Ford', 'last' : 'Prefect'}),
69 completion(equals('Hello, my name is Ford Prefect')));
70 });
71
72 test('Message with object parameter', () {
73 hello(person) => Intl.message(
74 "Hello, my name is ${person.firstName} ${person.lastName}.",
75 desc: "States a person's name.",
76 examples: {'first': 'Ford', 'last' : 'Prefect'});
77 var ford = new Person('Ford', 'Prefect');
78 expect(hello(ford), completion(equals('Hello, my name is Ford Prefect.')));
79 });
80
81 test('WithLocale test', () {
82 hello() => Intl.message('locale=${Intl.getCurrentLocale()}',
83 desc: 'explains the locale');
84 expect(Intl.withLocale('en-US', () => hello()),
85 completion(equals('locale=en-US')));
86 });
87
88 test('Test passing locale', () {
89 hello(a_locale) => Intl.message('locale=${Intl.getCurrentLocale()}',
90 desc: 'explains the locale', locale: a_locale);
91 expect(hello('en-US'), completion(equals('locale=en_US')));
92 });
93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698