You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.0 KiB
78 lines
2.0 KiB
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:eaimar/core/translations/language/en_us.dart';
|
|
import 'package:eaimar/core/translations/language/is_is.dart';
|
|
|
|
Set<String> _extractPlaceholders(String value) {
|
|
final placeholders = <String>{};
|
|
|
|
placeholders.addAll(
|
|
RegExp(r'\{[a-zA-Z_][a-zA-Z0-9_]*\}')
|
|
.allMatches(value)
|
|
.map((m) => m.group(0)!)
|
|
.toSet(),
|
|
);
|
|
|
|
placeholders.addAll(
|
|
RegExp(r'@[a-zA-Z_][a-zA-Z0-9_]*')
|
|
.allMatches(value)
|
|
.map((m) => m.group(0)!)
|
|
.toSet(),
|
|
);
|
|
|
|
placeholders.addAll(
|
|
RegExp(r'\$\{[a-zA-Z_][a-zA-Z0-9_]*\}')
|
|
.allMatches(value)
|
|
.map((m) => m.group(0)!)
|
|
.toSet(),
|
|
);
|
|
|
|
placeholders.addAll(
|
|
RegExp(r'%(?:\d+\$)?[sdif]')
|
|
.allMatches(value)
|
|
.map((m) => m.group(0)!)
|
|
.toSet(),
|
|
);
|
|
|
|
return placeholders;
|
|
}
|
|
|
|
void main() {
|
|
test('isIS can be imported and accessed', () {
|
|
expect(isIS, isNotEmpty);
|
|
expect(isIS['continue'], isNotNull);
|
|
});
|
|
|
|
test('isIS has the same translation keys as enUS', () {
|
|
expect(isIS.keys.toSet(), equals(enUS.keys.toSet()));
|
|
});
|
|
|
|
test('isIS has no empty values', () {
|
|
final emptyKeys = isIS.entries
|
|
.where((entry) => entry.value.trim().isEmpty)
|
|
.map((entry) => entry.key)
|
|
.toList(growable: false);
|
|
expect(emptyKeys, isEmpty);
|
|
});
|
|
|
|
test('isIS placeholders match enUS placeholders', () {
|
|
final mismatches = <String>[];
|
|
|
|
for (final key in enUS.keys) {
|
|
final enValue = enUS[key] ?? '';
|
|
final isValue = isIS[key] ?? '';
|
|
|
|
final enPlaceholders = _extractPlaceholders(enValue);
|
|
final isPlaceholders = _extractPlaceholders(isValue);
|
|
|
|
if (enPlaceholders.length != isPlaceholders.length ||
|
|
!enPlaceholders.containsAll(isPlaceholders) ||
|
|
!isPlaceholders.containsAll(enPlaceholders)) {
|
|
mismatches.add(
|
|
'$key | en=$enPlaceholders | is=$isPlaceholders | enValue=$enValue | isValue=$isValue',
|
|
);
|
|
}
|
|
}
|
|
|
|
expect(mismatches, isEmpty);
|
|
});
|
|
}
|
|
|