halkyon/packages/halkyon_app/test/instance/subdivision_names_test.dart
Tizian 「ティツィアーン」 96f2d14618
halkyon_app: data locations as precise as a country or a state
An operator's DATA_LOCATION and BACKUP_LOCATION may name a subdivision
(ISO 3166-2, US-CA, DE-BY) besides the EU or a country. The app adds
"(EU)" to a member country and the country to a subdivision ("Germany
(EU)", "California, United States", "Bavaria, Germany (EU)"), in
English and German, and shows the most specific flag there is: a
subdivision's own where the flag package has one, else its country's.
Subdivision names come from Unicode CLDR 48.2 (tool/subdivision_names.py),
bundled with their licence, which the app registers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-19 18:50:26 +02:00

36 lines
1.4 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_app/halkyon_app.dart';
void main() {
test('a subdivision is named in the language asked for, else in English, '
'and one without a name not at all', () async {
const names = MemorySubdivisionNames({
'US-CA': {'en': 'California', 'de': 'Kalifornien'},
'US-TX': {'en': 'Texas'},
});
expect(await names.nameOf('US-CA', 'de'), 'Kalifornien');
expect(await names.nameOf('us-ca', 'de'), 'Kalifornien');
expect(await names.nameOf('US-TX', 'de'), 'Texas');
expect(await names.nameOf('US-ZZ', 'en'), isNull);
});
testWidgets("Unicode CLDR's names come with the package, in English and "
'German', (tester) async {
final names = await tester.runAsync(
() async => (
en: await const AssetSubdivisionNames().nameOf('US-CA', 'en'),
de: await const AssetSubdivisionNames().nameOf('US-CA', 'de'),
texas: await const AssetSubdivisionNames().nameOf('US-TX', 'de'),
scotland: await const AssetSubdivisionNames().nameOf('GB-SCT', 'de'),
unknown: await const AssetSubdivisionNames().nameOf('US-ZZ', 'en'),
),
);
expect(names?.en, 'California');
expect(names?.de, 'Kalifornien');
expect(names?.texas, 'Texas', reason: 'German as English, kept once');
expect(names?.scotland, 'Schottland');
expect(names?.unknown, isNull);
});
}