blob: cfc19f514adc8670b0ea575551ac8d57c6830cd8 [file] [log] [blame]
[email protected]4c2604d2012-09-17 22:25:48 +00001// 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 Team795c4902019-08-29 10:58:28 -07005@TestOn('browser')
[email protected]3a88e392012-10-31 21:32:10 +00006library find_default_locale_browser_test;
[email protected]4c2604d2012-09-17 22:25:48 +00007
[email protected]771dfd72013-01-13 01:11:07 +00008import 'package:intl/intl.dart';
9import 'package:intl/intl_browser.dart';
alanknight810432e2017-06-15 13:40:56 -070010import 'package:test/test.dart';
[email protected]4c2604d2012-09-17 22:25:48 +000011
Dart Team795c4902019-08-29 10:58:28 -070012void main() {
13 test('Find system locale in browser', () {
[email protected]4c2604d2012-09-17 22:25:48 +000014 // 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 Team795c4902019-08-29 10:58:28 -070018 var callback = expectAsync1(verifyLocale);
[email protected]148d8ed2012-10-02 16:25:40 +000019 findSystemLocale().then(callback);
[email protected]4c2604d2012-09-17 22:25:48 +000020 });
21}
22
Dart Team795c4902019-08-29 10:58:28 -070023void verifyLocale(_) {
24 expect(Intl.systemLocale, isNot(equals('xx_YY')));
[email protected]72dd03f2013-01-15 20:39:22 +000025 // Allow either en_US or just en type locales. Windows in particular may
26 // give us just ru for ru_RU
Dart Team795c4902019-08-29 10:58:28 -070027 var pattern = RegExp(r'\w\w_[A-Z0-9]+');
28 var shortPattern = RegExp(r'\w\w');
[email protected]4c2604d2012-09-17 22:25:48 +000029 var match = pattern.hasMatch(Intl.systemLocale);
[email protected]72dd03f2013-01-15 20:39:22 +000030 var shortMatch = shortPattern.hasMatch(Intl.systemLocale);
31 expect(match || shortMatch, isTrue);
[email protected]4c2604d2012-09-17 22:25:48 +000032}