Initial flame_lua_runtime package
This commit is contained in:
63
test/runtime/game/runtime_locale_test.dart
Normal file
63
test/runtime/game/runtime_locale_test.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
import 'dart:ui' show Locale;
|
||||
|
||||
import 'package:flame_lua_runtime/runtime/game/runtime_locale.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('RuntimeLocaleResolver', () {
|
||||
test('normalizes locale tags', () {
|
||||
expect(RuntimeLocaleResolver.normalizeTag('zh_hans_cn'), 'zh-Hans-CN');
|
||||
expect(RuntimeLocaleResolver.normalizeTag('EN-us'), 'en-US');
|
||||
expect(RuntimeLocaleResolver.tagOf(const Locale('zh', 'CN')), 'zh-CN');
|
||||
});
|
||||
|
||||
test('resolves exact, language and fallback locales', () {
|
||||
expect(
|
||||
RuntimeLocaleResolver.resolve(
|
||||
requested: const Locale.fromSubtags(
|
||||
languageCode: 'zh',
|
||||
scriptCode: 'Hans',
|
||||
),
|
||||
defaultLocale: 'en',
|
||||
supportedLocales: const ['zh-Hans', 'en'],
|
||||
).resolved,
|
||||
'zh-Hans',
|
||||
);
|
||||
|
||||
expect(
|
||||
RuntimeLocaleResolver.resolve(
|
||||
requested: const Locale('en', 'US'),
|
||||
defaultLocale: 'zh-Hans',
|
||||
supportedLocales: const ['zh-Hans', 'en'],
|
||||
).resolved,
|
||||
'en',
|
||||
);
|
||||
|
||||
expect(
|
||||
RuntimeLocaleResolver.resolve(
|
||||
requested: const Locale('fr', 'FR'),
|
||||
defaultLocale: 'zh-Hans',
|
||||
supportedLocales: const ['zh-Hans', 'en'],
|
||||
).resolved,
|
||||
'zh-Hans',
|
||||
);
|
||||
});
|
||||
|
||||
test('exports locale context for Lua', () {
|
||||
final info = RuntimeLocaleResolver.resolve(
|
||||
requested: const Locale('en', 'US'),
|
||||
defaultLocale: 'zh-Hans',
|
||||
supportedLocales: const ['zh-Hans', 'en'],
|
||||
);
|
||||
|
||||
expect(info.toMap(), {
|
||||
'requested': 'en-US',
|
||||
'resolved': 'en',
|
||||
'default': 'zh-Hans',
|
||||
'supported': ['zh-Hans', 'en'],
|
||||
'languageCode': 'en',
|
||||
'countryCode': 'US',
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user