This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Expand file tree
/
Copy pathlocale_test.dart
More file actions
68 lines (57 loc) · 3.41 KB
/
locale_test.dart
File metadata and controls
68 lines (57 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2013 The Flutter Authors. 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:ui';
import 'package:litetest/litetest.dart';
void main() {
test('Locale', () {
expect(const Locale('en').toLanguageTag(), 'en');
expect(const Locale('en'), const Locale('en'));
expect(const Locale('en').hashCode, const Locale('en').hashCode);
expect(const Locale('en', 'US').toLanguageTag(), 'en-US');
expect(const Locale('en', 'US').toString(), 'en_US');
expect(const Locale('iw').toLanguageTag(), 'he');
expect(const Locale('iw', 'DD').toLanguageTag(), 'he-DE');
expect(const Locale('iw', 'DD').toString(), 'he_DE');
expect(const Locale('iw', 'DD'), const Locale('he', 'DE'));
});
test('Locale.fromSubtags', () {
expect(const Locale.fromSubtags().languageCode, 'und');
expect(const Locale.fromSubtags().scriptCode, null);
expect(const Locale.fromSubtags().countryCode, null);
expect(const Locale.fromSubtags(languageCode: 'en').toLanguageTag(), 'en');
expect(const Locale.fromSubtags(languageCode: 'en').languageCode, 'en');
expect(const Locale.fromSubtags(scriptCode: 'Latn').toLanguageTag(), 'und-Latn');
expect(const Locale.fromSubtags(scriptCode: 'Latn').toString(), 'und_Latn');
expect(const Locale.fromSubtags(scriptCode: 'Latn').scriptCode, 'Latn');
expect(const Locale.fromSubtags(countryCode: 'US').toLanguageTag(), 'und-US');
expect(const Locale.fromSubtags(countryCode: 'US').toString(), 'und_US');
expect(const Locale.fromSubtags(countryCode: 'US').countryCode, 'US');
expect(const Locale.fromSubtags(languageCode: 'es', countryCode: '419').toLanguageTag(), 'es-419');
expect(const Locale.fromSubtags(languageCode: 'es', countryCode: '419').toString(), 'es_419');
expect(const Locale.fromSubtags(languageCode: 'es', countryCode: '419').languageCode, 'es');
expect(const Locale.fromSubtags(languageCode: 'es', countryCode: '419').scriptCode, null);
expect(const Locale.fromSubtags(languageCode: 'es', countryCode: '419').countryCode, '419');
expect(const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans', countryCode: 'CN').toLanguageTag(), 'zh-Hans-CN');
expect(const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans', countryCode: 'CN').toString(), 'zh_Hans_CN');
});
test('Locale equality', () {
expect(const Locale.fromSubtags(languageCode: 'en'),
notEquals(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn')));
expect(const Locale.fromSubtags(languageCode: 'en').hashCode,
notEquals(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn').hashCode));
expect(const Locale('en', ''), const Locale('en'));
expect(const Locale('en'), const Locale('en', ''));
expect(const Locale('en'), const Locale('en'));
expect(const Locale('en', ''), const Locale('en', ''));
expect(const Locale('en', ''), notEquals(const Locale('en', 'GB')));
expect(const Locale('en'), notEquals(const Locale('en', 'GB')));
expect(const Locale('en', 'GB'), notEquals(const Locale('en', '')));
expect(const Locale('en', 'GB'), notEquals(const Locale('en')));
});
test("Locale toString does not include separator for ''", () {
expect(const Locale('en').toString(), 'en');
expect(const Locale('en', '').toString(), 'en');
expect(const Locale('en', 'US').toString(), 'en_US');
});
}