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

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

Issue 179783004: Verify the default locale in case we're given an invalid one and need to fall back. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 library intl_test; 5 library intl_test;
6 6
7 import 'package:intl/intl.dart'; 7 import 'package:intl/intl.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 import 'package:intl/date_symbol_data_local.dart'; 9 import 'package:intl/date_symbol_data_local.dart';
10 10
(...skipping 16 matching lines...) Expand all
27 }); 27 });
28 28
29 test("Canonicalizing locales", () { 29 test("Canonicalizing locales", () {
30 expect(Intl.canonicalizedLocale('en-us'), 'en_US'); 30 expect(Intl.canonicalizedLocale('en-us'), 'en_US');
31 expect(Intl.canonicalizedLocale('en_us'), 'en_US'); 31 expect(Intl.canonicalizedLocale('en_us'), 'en_US');
32 expect(Intl.canonicalizedLocale('en_US'), 'en_US'); 32 expect(Intl.canonicalizedLocale('en_US'), 'en_US');
33 expect(Intl.canonicalizedLocale('xx-yyy'), 'xx_YYY'); 33 expect(Intl.canonicalizedLocale('xx-yyy'), 'xx_YYY');
34 expect(Intl.canonicalizedLocale('xx_YYY'), 'xx_YYY'); 34 expect(Intl.canonicalizedLocale('xx_YYY'), 'xx_YYY');
35 expect(Intl.canonicalizedLocale('C'), 'en_ISO'); 35 expect(Intl.canonicalizedLocale('C'), 'en_ISO');
36 }); 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
Emily Fortuna 2014/02/25 19:16:36 remove extra empty line here
Alan Knight 2014/02/25 19:18:55 Done.
81
82 });
37 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698