| OLD | NEW |
| 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 /// Test date formatting and parsing using locale data which is available |
| 6 * Test date formatting and parsing using locale data which is available | 6 /// directly in the program as a constant. |
| 7 * directly in the program as a constant. | |
| 8 */ | |
| 9 | 7 |
| 10 library date_time_format_test; | 8 library date_time_format_test; |
| 11 | 9 |
| 12 import 'dart:async'; | 10 import 'dart:async'; |
| 13 import 'package:unittest/unittest.dart'; | 11 import 'package:test/test.dart'; |
| 14 import 'package:intl/intl.dart'; | 12 import 'package:intl/intl.dart'; |
| 15 import 'date_time_format_test_core.dart'; | 13 import 'date_time_format_test_core.dart'; |
| 16 | 14 |
| 17 typedef List<String> TestListFunc(); | 15 typedef List<String> TestListFunc(); |
| 18 | 16 |
| 19 typedef Future InitializeDateFormattingFunc(String locale, String filePath); | 17 typedef Future InitializeDateFormattingFunc(String locale, String filePath); |
| 20 | 18 |
| 21 /** | 19 /// Return only the odd-numbered locales. A simple way to divide the list into |
| 22 * Return only the odd-numbered locales. A simple way to divide the list into | 20 /// two roughly equal parts. |
| 23 * two roughly equal parts. | |
| 24 */ | |
| 25 List<String> oddLocales() { | 21 List<String> oddLocales() { |
| 26 int i = 1; | 22 int i = 1; |
| 27 return allLocales().where((x) => (i++).isOdd).toList(); | 23 return allLocales().where((x) => (i++).isOdd).toList(); |
| 28 } | 24 } |
| 29 | 25 |
| 30 /** | 26 /// Return a set of a few locales to run just the tests on a small sample. |
| 31 * Return a set of a few locales to run just the tests on a small sample. | 27 List<String> smallSetOfLocales() { |
| 32 */ | |
| 33 List smallSetOfLocales() { | |
| 34 return allLocales().sublist(0, 10); | 28 return allLocales().sublist(0, 10); |
| 35 } | 29 } |
| 36 | 30 |
| 37 /** | 31 /// Return only the even-numbered locales. A simple way to divide the list into |
| 38 * Return only the even-numbered locales. A simple way to divide the list into | 32 /// two roughly equal parts. |
| 39 * two roughly equal parts. | |
| 40 */ | |
| 41 List<String> evenLocales() { | 33 List<String> evenLocales() { |
| 42 int i = 1; | 34 int i = 1; |
| 43 return allLocales().where((x) => !((i++).isOdd)).toList(); | 35 return allLocales().where((x) => !((i++).isOdd)).toList(); |
| 44 } | 36 } |
| 45 | 37 |
| 46 void runWith(TestListFunc getSubset, String dir, | 38 void runWith(TestListFunc getSubset, String dir, |
| 47 InitializeDateFormattingFunc initFunction) { | 39 InitializeDateFormattingFunc initFunction) { |
| 48 // Initialize one locale just so we know what the list is. | 40 // Initialize one locale just so we know what the list is. |
| 49 // Also, note that we take the list of locales as a function so that we don't | 41 // Also, note that we take the list of locales as a function so that we don't |
| 50 // evaluate it until after we know that all the locales are available. | 42 // evaluate it until after we know that all the locales are available. |
| 51 | 43 |
| 52 bool initialized = false; | 44 bool initialized = false; |
| 53 | 45 |
| 54 setUp(() { | 46 setUp(() { |
| 55 if (initialized) { | 47 if (initialized) { |
| 56 return null; | 48 return null; |
| 57 } | 49 } |
| 58 return initFunction("en_US", dir).then((_) { | 50 return initFunction("en_US", dir).then((_) { |
| 59 return Future.forEach(DateFormat.allLocalesWithSymbols(), (locale) { | 51 return Future.forEach(DateFormat.allLocalesWithSymbols(), (locale) { |
| 60 return initFunction(locale, dir); | 52 return initFunction(locale, dir); |
| 61 }); | 53 }); |
| 62 }).then((_) { | 54 }).then((_) { |
| 63 initialized = true; | 55 initialized = true; |
| 64 }); | 56 }); |
| 65 }); | 57 }); |
| 66 | 58 |
| 67 runDateTests(getSubset); | 59 runDateTests(getSubset); |
| 68 } | 60 } |
| OLD | NEW |