main
dart 56 lines 1.64 KB
Raw
1 import 'package:flutter/material.dart';
2 import 'package:flutter_test/flutter_test.dart';
3 import 'package:localmind/core/utils/locale_utils.dart';
4 import 'package:localmind/l10n/app_localizations.dart';
5
6 void main() {
7 group('parseLocaleCode', () {
8 test('parses language only locales', () {
9 expect(parseLocaleCode('zh'), const Locale('zh'));
10 });
11
12 test('parses locales with country codes', () {
13 expect(parseLocaleCode('zh_TW'), const Locale('zh', 'TW'));
14 expect(parseLocaleCode('zh-TW'), const Locale('zh', 'TW'));
15 expect(parseLocaleCode('tr_TR'), const Locale('tr', 'TR'));
16 });
17 });
18
19 group('findSupportedLocale', () {
20 test('matches Turkish locale exactly', () {
21 expect(
22 findSupportedLocale('tr', AppLocalizations.supportedLocales),
23 const Locale('tr'),
24 );
25 expect(
26 findSupportedLocale('tr_TR', AppLocalizations.supportedLocales),
27 const Locale('tr'),
28 );
29 });
30
31 test('matches French locale exactly', () {
32 expect(
33 findSupportedLocale('fr', AppLocalizations.supportedLocales),
34 const Locale('fr'),
35 );
36 expect(
37 findSupportedLocale('fr_FR', AppLocalizations.supportedLocales),
38 const Locale('fr'),
39 );
40 });
41
42 test('matches Traditional Chinese exactly', () {
43 expect(
44 findSupportedLocale('zh_TW', AppLocalizations.supportedLocales),
45 const Locale('zh', 'TW'),
46 );
47 });
48
49 test('falls back to language-only locale when region is unsupported', () {
50 expect(
51 findSupportedLocale('zh_HK', AppLocalizations.supportedLocales),
52 const Locale('zh'),
53 );
54 });
55 });
56 }