[gen_l10n] Throw a specified exception when the language code is invalid (#102431)

This commit is contained in:
Alex Li
2022-04-25 02:04:06 +08:00
committed by GitHub
parent c654d04f11
commit dca58a289b
2 changed files with 43 additions and 2 deletions

View File

@@ -2595,6 +2595,39 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
);
});
});
testWithoutContext('throws when the language code is not supported', () {
const String arbFileWithInvalidCode = '''
{
"@@locale": "invalid",
"title": "invalid"
}''';
final Directory l10nDirectory = fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
..createSync(recursive: true);
l10nDirectory.childFile('app_invalid.arb')
.writeAsStringSync(arbFileWithInvalidCode);
expect(
() {
LocalizationsGenerator(
fileSystem: fs,
inputPathString: defaultL10nPathString,
outputPathString: defaultL10nPathString,
templateArbFileName: 'app_invalid.arb',
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
)
..loadResources()
..writeOutputFiles(BufferLogger.test());
},
throwsA(isA<L10nException>().having(
(L10nException e) => e.message,
'message',
contains('"invalid" is not a supported language code.'),
)),
);
});
});
testWithoutContext('should generate a valid pubspec.yaml file when using synthetic package if it does not already exist', () {