[email protected] | 4c2604d | 2012-09-17 22:25:48 +0000 | [diff] [blame] | 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 | |||||
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 5 | @TestOn('browser') |
[email protected] | 3a88e39 | 2012-10-31 21:32:10 +0000 | [diff] [blame] | 6 | library find_default_locale_browser_test; |
[email protected] | 4c2604d | 2012-09-17 22:25:48 +0000 | [diff] [blame] | 7 | |
[email protected] | 771dfd7 | 2013-01-13 01:11:07 +0000 | [diff] [blame] | 8 | import 'package:intl/intl.dart'; |
9 | import 'package:intl/intl_browser.dart'; | ||||
alanknight | 810432e | 2017-06-15 13:40:56 -0700 | [diff] [blame] | 10 | import 'package:test/test.dart'; |
[email protected] | 4c2604d | 2012-09-17 22:25:48 +0000 | [diff] [blame] | 11 | |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 12 | void main() { |
13 | test('Find system locale in browser', () { | ||||
[email protected] | 4c2604d | 2012-09-17 22:25:48 +0000 | [diff] [blame] | 14 | // TODO (alanknight): This only verifies that we found some locale. We |
15 | // should find a way to force the system locale before the test is run | ||||
16 | // and then verify that it's actually the correct value. | ||||
17 | Intl.systemLocale = 'xx_YY'; | ||||
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 18 | var callback = expectAsync1(verifyLocale); |
[email protected] | 148d8ed | 2012-10-02 16:25:40 +0000 | [diff] [blame] | 19 | findSystemLocale().then(callback); |
[email protected] | 4c2604d | 2012-09-17 22:25:48 +0000 | [diff] [blame] | 20 | }); |
21 | } | ||||
22 | |||||
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 23 | void verifyLocale(_) { |
24 | expect(Intl.systemLocale, isNot(equals('xx_YY'))); | ||||
[email protected] | 72dd03f | 2013-01-15 20:39:22 +0000 | [diff] [blame] | 25 | // Allow either en_US or just en type locales. Windows in particular may |
26 | // give us just ru for ru_RU | ||||
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 27 | var pattern = RegExp(r'\w\w_[A-Z0-9]+'); |
28 | var shortPattern = RegExp(r'\w\w'); | ||||
[email protected] | 4c2604d | 2012-09-17 22:25:48 +0000 | [diff] [blame] | 29 | var match = pattern.hasMatch(Intl.systemLocale); |
[email protected] | 72dd03f | 2013-01-15 20:39:22 +0000 | [diff] [blame] | 30 | var shortMatch = shortPattern.hasMatch(Intl.systemLocale); |
31 | expect(match || shortMatch, isTrue); | ||||
[email protected] | 4c2604d | 2012-09-17 22:25:48 +0000 | [diff] [blame] | 32 | } |