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

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

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 /** 5 /**
6 * Tests the DateFormat library in dart. This file contains core tests that 6 * Tests the DateFormat library in dart. This file contains core tests that
7 * are run regardless of where the locale data is found, so it doesn't expect to 7 * are run regardless of where the locale data is found, so it doesn't expect to
8 * be run on its own, but rather to be imported and run from another test file. 8 * be run on its own, but rather to be imported and run from another test file.
9 */ 9 */
10 10
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 DateFormat.ABBR_QUARTER, 151 DateFormat.ABBR_QUARTER,
152 DateFormat.YEAR, 152 DateFormat.YEAR,
153 DateFormat.YEAR_NUM_MONTH, 153 DateFormat.YEAR_NUM_MONTH,
154 DateFormat.YEAR_ABBR_MONTH, 154 DateFormat.YEAR_ABBR_MONTH,
155 DateFormat.YEAR_MONTH, 155 DateFormat.YEAR_MONTH,
156 DateFormat.MONTH_WEEKDAY_DAY, 156 DateFormat.MONTH_WEEKDAY_DAY,
157 DateFormat.NUM_MONTH_WEEKDAY_DAY, 157 DateFormat.NUM_MONTH_WEEKDAY_DAY,
158 DateFormat.ABBR_MONTH_WEEKDAY_DAY]; 158 DateFormat.ABBR_MONTH_WEEKDAY_DAY];
159 for(int i = 0; i < formatsToTest.length; i++) { 159 for(int i = 0; i < formatsToTest.length; i++) {
160 var skeleton = formatsToTest[i]; 160 var skeleton = formatsToTest[i];
161 if (!badSkeletons.some((x) => x == skeleton)) { 161 if (!badSkeletons.any((x) => x == skeleton)) {
162 var format = new DateFormat(skeleton, localeName); 162 var format = new DateFormat(skeleton, localeName);
163 var actualResult = format.format(date); 163 var actualResult = format.format(date);
164 var parsed = format.parse(actualResult); 164 var parsed = format.parse(actualResult);
165 var thenPrintAgain = format.format(parsed); 165 var thenPrintAgain = format.format(parsed);
166 expect(thenPrintAgain, equals(actualResult)); 166 expect(thenPrintAgain, equals(actualResult));
167 } 167 }
168 } 168 }
169 } 169 }
170 170
171 /** A shortcut for returning all the locales we have available.*/ 171 /** A shortcut for returning all the locales we have available.*/
172 List<String> allLocales() => DateFormat.allLocalesWithSymbols(); 172 List<String> allLocales() => DateFormat.allLocalesWithSymbols();
173 173
174 /** 174 /**
175 * Return only the odd-numbered locales. A simple way to divide the list into 175 * Return only the odd-numbered locales. A simple way to divide the list into
176 * two roughly equal parts. 176 * two roughly equal parts.
177 */ 177 */
178 List oddLocales() { 178 List oddLocales() {
179 int i = 1; 179 int i = 1;
180 return allLocales().filter((x) => (i++).isOdd); 180 return allLocales().where((x) => (i++).isOdd).toList();
181 } 181 }
182 182
183 /** 183 /**
184 * Return a set of a few locales to run just the tests on a small sample. 184 * Return a set of a few locales to run just the tests on a small sample.
185 */ 185 */
186 List smallSetOfLocales() { 186 List smallSetOfLocales() {
187 return allLocales().getRange(0,10); 187 return allLocales().getRange(0,10);
188 } 188 }
189 189
190 /** 190 /**
191 * Return only the even-numbered locales. A simple way to divide the list into 191 * Return only the even-numbered locales. A simple way to divide the list into
192 * two roughly equal parts. 192 * two roughly equal parts.
193 */ 193 */
194 List evenLocales() { 194 List evenLocales() {
195 int i = 1; 195 int i = 1;
196 return allLocales().filter((x) => !((i++).isOdd)); 196 return allLocales().where((x) => !((i++).isOdd)).toList();
197 } 197 }
198 198
199 // TODO(alanknight): Run specific tests for the en_ISO locale which isn't 199 // TODO(alanknight): Run specific tests for the en_ISO locale which isn't
200 // included in CLDR, and check that our patterns for it are correct (they 200 // included in CLDR, and check that our patterns for it are correct (they
201 // very likely aren't). 201 // very likely aren't).
202 runDateTests([List<String> subset]) { 202 runDateTests([List<String> subset]) {
203 test('Multiple patterns', () { 203 test('Multiple patterns', () {
204 var date = new Date.now(); 204 var date = new Date.now();
205 var multiple1 = new DateFormat.yMd().add_jms(); 205 var multiple1 = new DateFormat.yMd().add_jms();
206 var multiple2 = new DateFormat("yMd").add_jms(); 206 var multiple2 = new DateFormat("yMd").add_jms();
207 var separate1 = new DateFormat.yMd(); 207 var separate1 = new DateFormat.yMd();
208 var separate2 = new DateFormat.jms(); 208 var separate2 = new DateFormat.jms();
209 var separateFormat = "${separate1.format(date)} ${separate2.format(date)}"; 209 var separateFormat = "${separate1.format(date)} ${separate2.format(date)}";
210 expect(multiple1.format(date), equals(multiple2.format(date))); 210 expect(multiple1.format(date), equals(multiple2.format(date)));
211 expect(multiple1.format(date), equals(separateFormat)); 211 expect(multiple1.format(date), equals(separateFormat));
212 var customPunctuation = new DateFormat("yMd").addPattern("jms",":::"); 212 var customPunctuation = new DateFormat("yMd").addPattern("jms",":::");
213 var custom = "${separate1.format(date)}:::${separate2.format(date)}"; 213 var custom = "${separate1.format(date)}:::${separate2.format(date)}";
214 expect(customPunctuation.format(date), equals(custom)); 214 expect(customPunctuation.format(date), equals(custom));
215 }); 215 });
216 216
217 test('Basic date format parsing', () { 217 test('Basic date format parsing', () {
218 var date_format = new DateFormat("d"); 218 var date_format = new DateFormat("d");
219 expect( 219 expect(
220 date_format.parsePattern("hh:mm:ss").map((x) => x.pattern), 220 date_format.parsePattern("hh:mm:ss")
221 .mappedBy((x) => x.pattern)
222 .toList(),
221 orderedEquals(["hh",":", "mm",":","ss"])); 223 orderedEquals(["hh",":", "mm",":","ss"]));
222 expect( 224 expect(
223 date_format.parsePattern("hh:mm:ss").map((x) => x.pattern), 225 date_format.parsePattern("hh:mm:ss")
226 .mappedBy((x) => x.pattern)
227 .toList(),
224 orderedEquals(["hh",":", "mm",":","ss"])); 228 orderedEquals(["hh",":", "mm",":","ss"]));
225 }); 229 });
226 230
227 test('Test ALL the supported formats on representative locales', () { 231 test('Test ALL the supported formats on representative locales', () {
228 var aDate = new Date(2012, 1, 27, 20, 58, 59, 0); 232 var aDate = new Date(2012, 1, 27, 20, 58, 59, 0);
229 testLocale("en_US", English, aDate); 233 testLocale("en_US", English, aDate);
230 if (subset.length > 1) { 234 if (subset.length > 1) {
231 // Don't run if we have just one locale, so some of these won't be there. 235 // Don't run if we have just one locale, so some of these won't be there.
232 testLocale("de_DE", German, aDate); 236 testLocale("de_DE", German, aDate);
233 testLocale("fr_FR", French, aDate); 237 testLocale("fr_FR", French, aDate);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 355
352 test('Test default format', () { 356 test('Test default format', () {
353 var someDate = new Date(2012, 1, 27, 20, 58, 59, 1); 357 var someDate = new Date(2012, 1, 27, 20, 58, 59, 1);
354 var emptyFormat = new DateFormat(null, "en_US"); 358 var emptyFormat = new DateFormat(null, "en_US");
355 var knownDefault = new DateFormat.yMMMMd("en_US").add_jms(); 359 var knownDefault = new DateFormat.yMMMMd("en_US").add_jms();
356 var result = emptyFormat.format(someDate); 360 var result = emptyFormat.format(someDate);
357 var knownResult = knownDefault.format(someDate); 361 var knownResult = knownDefault.format(someDate);
358 expect(result, knownResult); 362 expect(result, knownResult);
359 }); 363 });
360 } 364 }
OLDNEW
« no previous file with comments | « pkg/intl/test/date_time_format_local_test_stub.dart ('k') | pkg/intl/test/intl_message_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698