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

Side by Side Diff: packages/intl/test/plural_test.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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 /// Test plurals without translation.
6 ///
7 /// This exercises the plural selection rules. We aren't worried about the text,
8 /// just that it picks the right phrase for the right number.
9
10 library plural_test;
11
12 import 'package:intl/intl.dart';
13 import 'package:test/test.dart';
14
15 /// Hard-coded expected values for a Russian plural rule.
16 ///
17 /// Note that the way I'm interpreting this is that if there's a case for zero,
18 /// one or two and the number is exactly that, then use that value. Otherwise we
19 /// use One for the singular, Few for the genitive singular, and Many for the
20 /// genitive plural. Other would be used for fractional values if we supported
21 /// those.
22 var expectedRu = '''
23 0:Zero
24 1:One
25 2:Few
26 3:Few
27 4:Few
28 5:Many
29 6:Many
30 7:Many
31 8:Many
32 9:Many
33 10:Many
34 11:Many
35 12:Many
36 13:Many
37 14:Many
38 15:Many
39 16:Many
40 17:Many
41 18:Many
42 19:Many
43 20:Many
44 21:One
45 22:Few
46 23:Few
47 24:Few
48 25:Many
49 26:Many
50 27:Many
51 28:Many
52 29:Many
53 30:Many
54 31:One
55 32:Few
56 59:Many
57 60:Many
58 61:One
59 62:Few
60 63:Few
61 64:Few
62 65:Many
63 66:Many
64 67:Many
65 68:Many
66 69:Many
67 70:Many
68 71:One
69 72:Few
70 100:Many
71 101:One
72 102:Few
73 103:Few
74 104:Few
75 105:Many
76 106:Many
77 107:Many
78 108:Many
79 109:Many
80 110:Many
81 111:Many
82 112:Many
83 113:Many
84 114:Many
85 115:Many
86 116:Many
87 117:Many
88 118:Many
89 119:Many
90 120:Many
91 121:One
92 122:Few
93 129:Many
94 130:Many
95 131:One
96 132:Few
97 139:Many
98 140:Many
99 141:One
100 142:Few
101 143:Few
102 144:Few
103 145:Many
104 ''';
105
106 var expectedEn = '''
107 0:Zero
108 1:One
109 2:Other
110 3:Other
111 4:Other
112 5:Other
113 6:Other
114 7:Other
115 8:Other
116 9:Other
117 10:Other
118 11:Other
119 12:Other
120 13:Other
121 14:Other
122 15:Other
123 16:Other
124 17:Other
125 18:Other
126 19:Other
127 20:Other
128 21:Other
129 22:Other
130 145:Other
131 ''';
132
133 var expectedRo = '''
134 0:Few
135 1:One
136 2:Few
137 12:Few
138 23:Other
139 1212:Few
140 1223:Other
141 ''';
142
143 var expectedSr = '''
144 0:Other
145 1:One
146 31:One
147 3:Few
148 33:Few
149 5:Other
150 10:Other
151 35:Other
152 37:Other
153 40:Other
154 2:Few
155 20:Other
156 21:One
157 22:Few
158 23:Few
159 24:Few
160 25:Other
161 ''';
162
163 plural(n, locale) => Intl.plural(n,
164 locale: locale,
165 name: 'plural',
166 desc: 'A simple plural test case',
167 examples: {'n': 1},
168 args: [n],
169 zero: '$n:Zero',
170 one: '$n:One',
171 few: '$n:Few',
172 many: '$n:Many',
173 other: '$n:Other');
174
175 pluralNoZero(n, locale) => Intl.plural(n,
176 locale: locale,
177 name: 'plural',
178 desc: 'A simple plural test case',
179 examples: {'n': 1},
180 args: [n],
181 one: '$n:One',
182 few: '$n:Few',
183 many: '$n:Many',
184 other: '$n:Other');
185
186 main() {
187 verify(expectedRu, 'ru', plural);
188 verify(expectedRu, 'ru_RU', plural);
189 verify(expectedEn, 'en', plural);
190 verify(expectedRo, 'ro', pluralNoZero);
191 verify(expectedSr, 'sr', pluralNoZero);
192
193 test("Check null howMany", () {
194 expect(plural(0, null), "0:Zero");
195 expect(() => plural(null, null), throwsArgumentError);
196 expect(() => plural(null, "ru"), throwsArgumentError);
197 });
198 }
199
200 verify(expectedValues, locale, pluralFunction) {
201 var lines = expectedValues.split('\n').where((x) => x.isNotEmpty).toList();
202 for (var i = 0; i < lines.length; i++) {
203 test(lines[i], () {
204 var number = int.parse(lines[i].split(':').first);
205 expect(pluralFunction(number, locale), lines[i]);
206 });
207 }
208 }
OLDNEW
« no previous file with comments | « packages/intl/test/number_test_data.dart ('k') | packages/intl/tool/generate_locale_data_files.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698