Add a test for Platform.localeName

Change-Id: I53b995239426b463b8a3dbd529447f016fe81d81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215156
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
This commit is contained in:
Brian Quinlan 2021-10-04 18:41:50 +00:00 committed by commit-bot@chromium.org
parent b927288ed1
commit 4933f44a82
2 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,21 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "dart:io";
import "package:expect/expect.dart";
main() {
// Match patterns like:
// "en-US" (Android, iOS, MacOS, Windows)
// "en_US", "en_US.UTF-8" (Linux)
// "ESP-USA" (theoretically possible)
// Assumes that the platform has a reasonably configured locale.
var localePattern = RegExp(r"[A-Za-z]{2,4}[_-][A-Za-z]{2}");
var localeName = Platform.localeName;
Expect.isNotNull(
localePattern.matchAsPrefix(localeName),
"Platform.localeName: ${localeName} does not match "
"${localePattern.pattern}");
}

View file

@ -0,0 +1,23 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.9
import "dart:io";
import "package:expect/expect.dart";
main() {
// Match patterns like:
// "en-US" (Android, iOS, MacOS, Windows)
// "en_US", "en_US.UTF-8" (Linux)
// "ESP-USA" (theoretically possible)
// Assumes that the platform has a reasonably configured locale.
var localePattern = RegExp(r"[A-Za-z]{2,4}[_-][A-Za-z]{2}");
var localeName = Platform.localeName;
Expect.isNotNull(
localePattern.matchAsPrefix(localeName),
"Platform.localeName: ${localeName} does not match "
"${localePattern.pattern}");
}