Test to ensure _kn.arb files are properly escaped (#56091)
* Run encode kn character encoding tool when gen_localizations is run * Add test that ensures *_kn.arb files are properly encoded/escaped in order to be checked in * Fix *_no.arb test to not incorrectly pass
This commit is contained in:
@@ -2,12 +2,19 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../test_utils.dart';
|
||||
|
||||
final String rootDirectoryPath = Directory.current.parent.path;
|
||||
|
||||
void main() {
|
||||
for (final String language in kMaterialSupportedLanguages) {
|
||||
testWidgets('translations exist for $language', (WidgetTester tester) async {
|
||||
@@ -467,8 +474,12 @@ void main() {
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/53036.
|
||||
testWidgets('`nb` uses `no` as its synonym when `nb` arb file is not present', (WidgetTester tester) async {
|
||||
final File nbMaterialArbFile = File('lib/src/l10n/material_nb.arb');
|
||||
final File noMaterialArbFile = File('lib/src/l10n/material_no.arb');
|
||||
final File nbMaterialArbFile = File(
|
||||
path.join(rootDirectoryPath, 'lib', 'src', 'l10n', 'material_nb.arb'),
|
||||
);
|
||||
final File noMaterialArbFile = File(
|
||||
path.join(rootDirectoryPath, 'lib', 'src', 'l10n', 'material_no.arb'),
|
||||
);
|
||||
|
||||
// No need to run test if `nb` arb file exists or if `no` arb file does not exist.
|
||||
if (noMaterialArbFile.existsSync() && !nbMaterialArbFile.existsSync()) {
|
||||
@@ -492,4 +503,33 @@ void main() {
|
||||
expect(localizations.okButtonLabel, okButtonLabelNo);
|
||||
}
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/36704.
|
||||
testWidgets('kn arb file should be properly Unicode escaped', (WidgetTester tester) async {
|
||||
final File file = File(
|
||||
path.join(rootDirectoryPath, 'lib', 'src', 'l10n', 'material_kn.arb'),
|
||||
);
|
||||
|
||||
final Map<String, dynamic> bundle = json.decode(
|
||||
file.readAsStringSync(),
|
||||
) as Map<String, dynamic>;
|
||||
|
||||
// Encodes the arb resource values if they have not already been
|
||||
// encoded.
|
||||
encodeBundleTranslations(bundle);
|
||||
|
||||
// Generates the encoded arb output file in as a string.
|
||||
final String encodedArbFile = generateArbString(bundle);
|
||||
|
||||
// After encoding the bundles, the generated string should match
|
||||
// the existing material_kn.arb.
|
||||
if (Platform.isWindows) {
|
||||
// On Windows, the character '\n' can output the two-character sequence
|
||||
// '\r\n' (and when reading the file back, '\r\n' is translated back
|
||||
// into a single '\n' character).
|
||||
expect(file.readAsStringSync().replaceAll('\r\n', '\n'), encodedArbFile);
|
||||
} else {
|
||||
expect(file.readAsStringSync(), encodedArbFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user