OLD | NEW |
| (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_test; | |
6 | |
7 import 'package:intl/intl.dart'; | |
8 import 'package:unittest/unittest.dart'; | |
9 import 'package:intl/date_symbol_data_local.dart'; | |
10 | |
11 main() { | |
12 test("Locale setting doesn't verify the core locale", () { | |
13 var de = new Intl('de_DE'); | |
14 expect(de.locale, equals('de_DE')); | |
15 }); | |
16 | |
17 test('DateFormat creation does verify the locale', () { | |
18 // TODO(alanknight): We need to make the locale verification be on a per | |
19 // usage basis rather than once for the entire Intl object. The set of | |
20 // locales covered for messages may be different from that for date | |
21 // formatting. | |
22 initializeDateFormatting('de_DE', null).then((_) { | |
23 var de = new Intl('de_DE'); | |
24 var format = de.date().add_d(); | |
25 expect(format.locale, equals('de')); | |
26 }); | |
27 }); | |
28 | |
29 test("Canonicalizing locales", () { | |
30 expect(Intl.canonicalizedLocale('en-us'), 'en_US'); | |
31 expect(Intl.canonicalizedLocale('en_us'), 'en_US'); | |
32 expect(Intl.canonicalizedLocale('en_US'), 'en_US'); | |
33 expect(Intl.canonicalizedLocale('xx-yyy'), 'xx_YYY'); | |
34 expect(Intl.canonicalizedLocale('xx_YYY'), 'xx_YYY'); | |
35 expect(Intl.canonicalizedLocale('C'), 'en_ISO'); | |
36 }); | |
37 | |
38 test("Verifying locale fallback for numbers", () { | |
39 expect(Intl.verifiedLocale('en-us', NumberFormat.localeExists), 'en_US'); | |
40 expect(Intl.verifiedLocale('en_us', NumberFormat.localeExists), 'en_US'); | |
41 expect(Intl.verifiedLocale('es-419', NumberFormat.localeExists), 'es_419'); | |
42 expect(Intl.verifiedLocale('en-ZZ', NumberFormat.localeExists), 'en'); | |
43 expect(Intl.verifiedLocale('es-999', NumberFormat.localeExists), 'es'); | |
44 | |
45 void checkAsNumberDefault(String locale, String expected) { | |
46 var oldDefault = Intl.defaultLocale; | |
47 Intl.defaultLocale = locale; | |
48 var format = new NumberFormat(); | |
49 expect(format.locale, expected); | |
50 Intl.defaultLocale = oldDefault; | |
51 } | |
52 | |
53 checkAsNumberDefault('en-us', 'en_US'); | |
54 checkAsNumberDefault('en_us', 'en_US'); | |
55 checkAsNumberDefault('es-419', 'es_419'); | |
56 checkAsNumberDefault('en-ZZ', 'en'); | |
57 checkAsNumberDefault('es-999', 'es'); | |
58 }); | |
59 | |
60 test("Verifying locale fallback for dates", () { | |
61 expect(Intl.verifiedLocale('en-us', DateFormat.localeExists), 'en_US'); | |
62 expect(Intl.verifiedLocale('en_us', DateFormat.localeExists), 'en_US'); | |
63 expect(Intl.verifiedLocale('es-419', DateFormat.localeExists), 'es_419'); | |
64 expect(Intl.verifiedLocale('en-ZZ', DateFormat.localeExists), 'en'); | |
65 expect(Intl.verifiedLocale('es-999', DateFormat.localeExists), 'es'); | |
66 | |
67 void checkAsDateDefault(String locale, String expected) { | |
68 var oldDefault = Intl.defaultLocale; | |
69 Intl.defaultLocale = locale; | |
70 var format = new DateFormat(); | |
71 expect(format.locale, expected); | |
72 Intl.defaultLocale = oldDefault; | |
73 } | |
74 | |
75 checkAsDateDefault('en-us', 'en_US'); | |
76 checkAsDateDefault('en_us', 'en_US'); | |
77 checkAsDateDefault('es-419', 'es_419'); | |
78 checkAsDateDefault('en-ZZ', 'en'); | |
79 checkAsDateDefault('es-999', 'es'); | |
80 }); | |
81 } | |
OLD | NEW |