Remove synthetic
package qualifier for flutter: generate:
error. (#163145)
`generateLocalizations` should fail (`flutter gen-l10n`) if `flutter: generate:` does not exist. The previous logic was faulty, because it was totally possible to opt-out of synthetic packages (i.e. in a `l10n.yaml` file), but still not be specifying `flutter: generate:`, which I _believe_ is supposed to still be an error. This came up in https://github.com/flutter/flutter/pull/160289 as `flutter config --explicit-package-dependencies` is enabled by default, as the error is no longer thrown. Made a few other small test forward-fixes that otherwise would break with the switch (but are expected) as well.
This commit is contained in:
parent
063f80d40f
commit
1e32c00349
@ -78,6 +78,7 @@ dev_dependencies:
|
|||||||
yaml: 3.1.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
yaml: 3.1.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
|
generate: true
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
|
||||||
# PUBSPEC CHECKSUM: 17a3
|
# PUBSPEC CHECKSUM: 17a3
|
||||||
|
@ -34,8 +34,7 @@ Future<LocalizationsGenerator> generateLocalizations({
|
|||||||
fileSystem: projectDir.fileSystem,
|
fileSystem: projectDir.fileSystem,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
);
|
);
|
||||||
if (options.syntheticPackage &&
|
if (flutterManifest == null || !flutterManifest.generateLocalizations) {
|
||||||
(flutterManifest == null || !flutterManifest.generateLocalizations)) {
|
|
||||||
throwToolExit(
|
throwToolExit(
|
||||||
'Attempted to generate localizations code without having '
|
'Attempted to generate localizations code without having '
|
||||||
'the flutter: generate flag turned on.'
|
'the flutter: generate flag turned on.'
|
||||||
|
@ -7,6 +7,7 @@ import 'package:flutter_tools/src/artifacts.dart';
|
|||||||
import 'package:flutter_tools/src/base/file_system.dart';
|
import 'package:flutter_tools/src/base/file_system.dart';
|
||||||
import 'package:flutter_tools/src/base/logger.dart';
|
import 'package:flutter_tools/src/base/logger.dart';
|
||||||
import 'package:flutter_tools/src/convert.dart';
|
import 'package:flutter_tools/src/convert.dart';
|
||||||
|
import 'package:flutter_tools/src/features.dart';
|
||||||
import 'package:flutter_tools/src/localizations/gen_l10n.dart';
|
import 'package:flutter_tools/src/localizations/gen_l10n.dart';
|
||||||
import 'package:flutter_tools/src/localizations/gen_l10n_types.dart';
|
import 'package:flutter_tools/src/localizations/gen_l10n_types.dart';
|
||||||
import 'package:flutter_tools/src/localizations/localizations_utils.dart';
|
import 'package:flutter_tools/src/localizations/localizations_utils.dart';
|
||||||
@ -14,6 +15,7 @@ import 'package:yaml/yaml.dart';
|
|||||||
|
|
||||||
import '../src/common.dart';
|
import '../src/common.dart';
|
||||||
import '../src/context.dart';
|
import '../src/context.dart';
|
||||||
|
import '../src/fakes.dart';
|
||||||
|
|
||||||
const String defaultTemplateArbFileName = 'app_en.arb';
|
const String defaultTemplateArbFileName = 'app_en.arb';
|
||||||
const String defaultOutputFileString = 'output-localization-file.dart';
|
const String defaultOutputFileString = 'output-localization-file.dart';
|
||||||
@ -66,6 +68,11 @@ flutter:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
// TODO(matanlurey): Remove after `explicit-package-dependencies` is enabled by default.
|
||||||
|
FeatureFlags enableExplicitPackageDependencies() {
|
||||||
|
return TestFeatureFlags(isExplicitPackageDependenciesEnabled: true);
|
||||||
|
}
|
||||||
|
|
||||||
late MemoryFileSystem fs;
|
late MemoryFileSystem fs;
|
||||||
late BufferLogger logger;
|
late BufferLogger logger;
|
||||||
late Artifacts artifacts;
|
late Artifacts artifacts;
|
||||||
@ -129,12 +136,18 @@ void main() {
|
|||||||
..writeOutputFiles(isFromYaml: isFromYaml);
|
..writeOutputFiles(isFromYaml: isFromYaml);
|
||||||
}
|
}
|
||||||
|
|
||||||
String getGeneratedFileContent({String? locale}) {
|
String getSyntheticGeneratedFileContent({String? locale}) {
|
||||||
final String fileName =
|
final String fileName =
|
||||||
locale == null ? 'output-localization-file.dart' : 'output-localization-file_$locale.dart';
|
locale == null ? 'output-localization-file.dart' : 'output-localization-file_$locale.dart';
|
||||||
return fs.file(fs.path.join(syntheticL10nPackagePath, fileName)).readAsStringSync();
|
return fs.file(fs.path.join(syntheticL10nPackagePath, fileName)).readAsStringSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getInPackageGeneratedFileContent({String? locale}) {
|
||||||
|
final String fileName =
|
||||||
|
locale == null ? 'output-localization-file.dart' : 'output-localization-file_$locale.dart';
|
||||||
|
return fs.file(fs.path.join(defaultL10nPathString, fileName)).readAsStringSync();
|
||||||
|
}
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
fs = MemoryFileSystem.test();
|
fs = MemoryFileSystem.test();
|
||||||
logger = BufferLogger.test();
|
logger = BufferLogger.test();
|
||||||
@ -834,7 +847,9 @@ class FooEn extends Foo {
|
|||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('throws exception on missing flutter: generate: true flag', () async {
|
testUsingContext(
|
||||||
|
'throws exception on missing flutter: generate: true flag',
|
||||||
|
() async {
|
||||||
_standardFlutterDirectoryL10nSetup(fs);
|
_standardFlutterDirectoryL10nSetup(fs);
|
||||||
|
|
||||||
// Missing flutter: generate: true should throw exception.
|
// Missing flutter: generate: true should throw exception.
|
||||||
@ -873,9 +888,13 @@ flutter:
|
|||||||
'flutter: generate flag turned on.',
|
'flutter: generate flag turned on.',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
overrides: <Type, Generator>{FeatureFlags: enableExplicitPackageDependencies},
|
||||||
|
);
|
||||||
|
|
||||||
testUsingContext('uses the same line terminator as pubspec.yaml', () async {
|
testUsingContext(
|
||||||
|
'uses the same line terminator as pubspec.yaml',
|
||||||
|
() async {
|
||||||
_standardFlutterDirectoryL10nSetup(fs);
|
_standardFlutterDirectoryL10nSetup(fs);
|
||||||
|
|
||||||
fs.file('pubspec.yaml')
|
fs.file('pubspec.yaml')
|
||||||
@ -899,9 +918,11 @@ flutter:\r
|
|||||||
artifacts: artifacts,
|
artifacts: artifacts,
|
||||||
processManager: processManager,
|
processManager: processManager,
|
||||||
);
|
);
|
||||||
final String content = getGeneratedFileContent(locale: 'en');
|
final String content = getInPackageGeneratedFileContent(locale: 'en');
|
||||||
expect(content, contains('\r\n'));
|
expect(content, contains('\r\n'));
|
||||||
});
|
},
|
||||||
|
overrides: <Type, Generator>{FeatureFlags: enableExplicitPackageDependencies},
|
||||||
|
);
|
||||||
|
|
||||||
testWithoutContext('blank lines generated nicely', () async {
|
testWithoutContext('blank lines generated nicely', () async {
|
||||||
_standardFlutterDirectoryL10nSetup(fs);
|
_standardFlutterDirectoryL10nSetup(fs);
|
||||||
@ -1389,7 +1410,10 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
"helloWorld": "Hello world!"
|
"helloWorld": "Hello world!"
|
||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
expect(getGeneratedFileContent(), contains('/// No description provided for @helloWorld.'));
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(),
|
||||||
|
contains('/// No description provided for @helloWorld.'),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('multiline descriptions are correctly formatted as comments', () {
|
testWithoutContext('multiline descriptions are correctly formatted as comments', () {
|
||||||
@ -1403,7 +1427,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(),
|
getSyntheticGeneratedFileContent(),
|
||||||
contains('''
|
contains('''
|
||||||
/// The generic example string in every language.
|
/// The generic example string in every language.
|
||||||
/// Use this for tests!'''),
|
/// Use this for tests!'''),
|
||||||
@ -1417,7 +1441,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
'en': singleMessageArbFileString,
|
'en': singleMessageArbFileString,
|
||||||
'es': singleEsMessageArbFileString,
|
'es': singleEsMessageArbFileString,
|
||||||
});
|
});
|
||||||
final String content = getGeneratedFileContent();
|
final String content = getSyntheticGeneratedFileContent();
|
||||||
expect(content, contains('/// Title for the application.'));
|
expect(content, contains('/// Title for the application.'));
|
||||||
expect(
|
expect(
|
||||||
content,
|
content,
|
||||||
@ -1439,7 +1463,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
}''',
|
}''',
|
||||||
'es': singleEsMessageArbFileString,
|
'es': singleEsMessageArbFileString,
|
||||||
});
|
});
|
||||||
final String content = getGeneratedFileContent();
|
final String content = getSyntheticGeneratedFileContent();
|
||||||
expect(content, contains('/// Title for the application.'));
|
expect(content, contains('/// Title for the application.'));
|
||||||
expect(
|
expect(
|
||||||
content,
|
content,
|
||||||
@ -1471,7 +1495,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
"price": "El precio de este artículo es: ${price}"
|
"price": "El precio de este artículo es: ${price}"
|
||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
final String content = getGeneratedFileContent();
|
final String content = getSyntheticGeneratedFileContent();
|
||||||
expect(content, contains('/// The price of an online shopping cart item.'));
|
expect(content, contains('/// The price of an online shopping cart item.'));
|
||||||
expect(
|
expect(
|
||||||
content,
|
content,
|
||||||
@ -1491,14 +1515,14 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('class AppLocalizationsEn extends AppLocalizations'),
|
contains('class AppLocalizationsEn extends AppLocalizations'),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('class AppLocalizationsEnCa extends AppLocalizationsEn'),
|
contains('class AppLocalizationsEnCa extends AppLocalizationsEn'),
|
||||||
);
|
);
|
||||||
expect(() => getGeneratedFileContent(locale: 'en_US'), throwsException);
|
expect(() => getSyntheticGeneratedFileContent(locale: 'en_US'), throwsException);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext(
|
testWithoutContext(
|
||||||
@ -1510,7 +1534,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
'zh': singleZhMessageArbFileString,
|
'zh': singleZhMessageArbFileString,
|
||||||
'es': singleEsMessageArbFileString,
|
'es': singleEsMessageArbFileString,
|
||||||
}, preferredSupportedLocales: preferredSupportedLocales);
|
}, preferredSupportedLocales: preferredSupportedLocales);
|
||||||
final String content = getGeneratedFileContent();
|
final String content = getSyntheticGeneratedFileContent();
|
||||||
expect(
|
expect(
|
||||||
content,
|
content,
|
||||||
contains('''
|
contains('''
|
||||||
@ -1595,7 +1619,7 @@ import 'output-localization-file.g.dart';
|
|||||||
setupLocalizations(<String, String>{
|
setupLocalizations(<String, String>{
|
||||||
'en': singleMessageArbFileString,
|
'en': singleMessageArbFileString,
|
||||||
}, useDeferredLoading: true);
|
}, useDeferredLoading: true);
|
||||||
final String content = getGeneratedFileContent();
|
final String content = getSyntheticGeneratedFileContent();
|
||||||
expect(
|
expect(
|
||||||
content,
|
content,
|
||||||
contains('''
|
contains('''
|
||||||
@ -1615,7 +1639,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
"helloWorld": "Hello {name}"
|
"helloWorld": "Hello {name}"
|
||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
final String content = getGeneratedFileContent(locale: 'en');
|
final String content = getSyntheticGeneratedFileContent(locale: 'en');
|
||||||
expect(content, contains('String helloWorld(Object name) {'));
|
expect(content, contains('String helloWorld(Object name) {'));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -1637,8 +1661,14 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
''',
|
''',
|
||||||
});
|
});
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains('String helloWorld(Object name) {'));
|
expect(
|
||||||
expect(getGeneratedFileContent(locale: 'es'), contains('String helloWorld(Object name) {'));
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
|
contains('String helloWorld(Object name) {'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'es'),
|
||||||
|
contains('String helloWorld(Object name) {'),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext(
|
testWithoutContext(
|
||||||
@ -1655,7 +1685,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
}''',
|
}''',
|
||||||
}, relaxSyntax: true);
|
}, relaxSyntax: true);
|
||||||
final String content = getGeneratedFileContent(locale: 'en');
|
final String content = getSyntheticGeneratedFileContent(locale: 'en');
|
||||||
expect(content, contains("String get helloWorld => 'Hello {name}'"));
|
expect(content, contains("String get helloWorld => 'Hello {name}'"));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -1679,7 +1709,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains(intlImportDartCode));
|
expect(getSyntheticGeneratedFileContent(locale: 'en'), contains(intlImportDartCode));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('throws an exception when improperly formatted date is passed in', () {
|
testWithoutContext('throws an exception when improperly formatted date is passed in', () {
|
||||||
@ -1730,7 +1760,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
final String content = getGeneratedFileContent(locale: 'en');
|
final String content = getSyntheticGeneratedFileContent(locale: 'en');
|
||||||
expect(content, contains('DateFormat.yMd(localeName)'));
|
expect(content, contains('DateFormat.yMd(localeName)'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1752,7 +1782,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
final String content = getGeneratedFileContent(locale: 'en');
|
final String content = getSyntheticGeneratedFileContent(locale: 'en');
|
||||||
expect(content, contains(r"DateFormat('asdf o\'clock', localeName)"));
|
expect(content, contains(r"DateFormat('asdf o\'clock', localeName)"));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1774,7 +1804,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
final String content = getGeneratedFileContent(locale: 'en');
|
final String content = getSyntheticGeneratedFileContent(locale: 'en');
|
||||||
expect(content, contains(r"DateFormat('asdf o\'clock', localeName)"));
|
expect(content, contains(r"DateFormat('asdf o\'clock', localeName)"));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1793,7 +1823,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
final String content = getGeneratedFileContent(locale: 'en');
|
final String content = getSyntheticGeneratedFileContent(locale: 'en');
|
||||||
expect(content, contains(r'DateFormat.yMd(localeName).add_jms()'));
|
expect(content, contains(r'DateFormat.yMd(localeName).add_jms()'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1812,7 +1842,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
final String content = getGeneratedFileContent(locale: 'en');
|
final String content = getSyntheticGeneratedFileContent(locale: 'en');
|
||||||
expect(content, contains(r'DateFormat.yMMMMEEEEd(localeName).add_QQQQ().add_Hm()'));
|
expect(content, contains(r'DateFormat.yMMMMEEEEd(localeName).add_QQQQ().add_Hm()'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1939,17 +1969,20 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains('intl.DateFormat.MMMd(localeName)'));
|
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'ja'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
|
contains('intl.DateFormat.MMMd(localeName)'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
contains('intl.DateFormat.MMMMd(localeName)'),
|
contains('intl.DateFormat.MMMMd(localeName)'),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('String springBegins(DateTime springStartDate)'),
|
contains('String springBegins(DateTime springStartDate)'),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'ja'),
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
contains('String springBegins(DateTime springStartDate)'),
|
contains('String springBegins(DateTime springStartDate)'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -1980,19 +2013,19 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('intl.DateFormat.MMMd(localeName)'),
|
contains('intl.DateFormat.MMMd(localeName)'),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'ja'),
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
contains('intl.DateFormat.MMMd(localeName)'),
|
contains('intl.DateFormat.MMMd(localeName)'),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('String springBegins(DateTime springStartDate)'),
|
contains('String springBegins(DateTime springStartDate)'),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'ja'),
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
contains('String springBegins(DateTime springStartDate)'),
|
contains('String springBegins(DateTime springStartDate)'),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -2030,17 +2063,23 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains('intl.DateFormat.MMMd(localeName)'));
|
|
||||||
expect(getGeneratedFileContent(locale: 'ja'), contains('intl.DateFormat.MMMd(localeName)'));
|
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
|
contains('intl.DateFormat.MMMd(localeName)'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
|
contains('intl.DateFormat.MMMd(localeName)'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('String springBegins(DateTime springStartDate)'),
|
contains('String springBegins(DateTime springStartDate)'),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'ja'),
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
contains('String springBegins(DateTime springStartDate)'),
|
contains('String springBegins(DateTime springStartDate)'),
|
||||||
);
|
);
|
||||||
expect(getGeneratedFileContent(locale: 'ja'), isNot(contains('notUsed')));
|
expect(getSyntheticGeneratedFileContent(locale: 'ja'), isNot(contains('notUsed')));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('handle date with multiple locale when placeholders are incompatible', () {
|
testWithoutContext('handle date with multiple locale when placeholders are incompatible', () {
|
||||||
@ -2168,14 +2207,20 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains('intl.DateFormat.MMMd(localeName)'));
|
|
||||||
expect(getGeneratedFileContent(locale: 'ja'), contains(r"DateFormat('立春', localeName)"));
|
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
|
contains('intl.DateFormat.MMMd(localeName)'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
|
contains(r"DateFormat('立春', localeName)"),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('String springBegins(DateTime springStartDate)'),
|
contains('String springBegins(DateTime springStartDate)'),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'ja'),
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
contains('String springBegins(DateTime springStartDate)'),
|
contains('String springBegins(DateTime springStartDate)'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -2214,16 +2259,19 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains(r"DateFormat('asdf o\'clock', localeName)"),
|
contains(r"DateFormat('asdf o\'clock', localeName)"),
|
||||||
);
|
);
|
||||||
expect(getGeneratedFileContent(locale: 'ja'), contains(r"DateFormat('立春', localeName)"));
|
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
|
contains(r"DateFormat('立春', localeName)"),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('String springBegins(DateTime springStartDate)'),
|
contains('String springBegins(DateTime springStartDate)'),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'ja'),
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
contains('String springBegins(DateTime springStartDate)'),
|
contains('String springBegins(DateTime springStartDate)'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -2246,7 +2294,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
final String content = getGeneratedFileContent(locale: 'en');
|
final String content = getSyntheticGeneratedFileContent(locale: 'en');
|
||||||
expect(content, contains(intlImportDartCode));
|
expect(content, contains(intlImportDartCode));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2292,7 +2340,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
'en': singleMessageArbFileString,
|
'en': singleMessageArbFileString,
|
||||||
'es': singleEsMessageArbFileString,
|
'es': singleEsMessageArbFileString,
|
||||||
});
|
});
|
||||||
expect(getGeneratedFileContent(locale: 'es'), contains(intlImportDartCode));
|
expect(getSyntheticGeneratedFileContent(locale: 'es'), contains(intlImportDartCode));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2351,7 +2399,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('String helloWorlds(num count) {'),
|
contains('String helloWorlds(num count) {'),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -2401,7 +2449,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('String genderSelect(String gender) {'),
|
contains('String genderSelect(String gender) {'),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -2473,7 +2521,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('intl.DateFormat.yMd(localeName).format(today)'),
|
contains('intl.DateFormat.yMd(localeName).format(today)'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -2486,7 +2534,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('intl.DateFormat.jms(localeName).format(current)'),
|
contains('intl.DateFormat.jms(localeName).format(current)'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -2506,7 +2554,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('String datetime(DateTime today) {'),
|
contains('String datetime(DateTime today) {'),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -2522,7 +2570,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('String datetime(DateTime today) {'),
|
contains('String datetime(DateTime today) {'),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -2625,8 +2673,8 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
''';
|
''';
|
||||||
setupLocalizations(<String, String>{'en': pluralMessageArb, 'es': pluralMessageEsArb});
|
setupLocalizations(<String, String>{'en': pluralMessageArb, 'es': pluralMessageEsArb});
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains(intlImportDartCode));
|
expect(getSyntheticGeneratedFileContent(locale: 'en'), contains(intlImportDartCode));
|
||||||
expect(getGeneratedFileContent(locale: 'es'), contains(intlImportDartCode));
|
expect(getSyntheticGeneratedFileContent(locale: 'es'), contains(intlImportDartCode));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2650,8 +2698,8 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
''';
|
''';
|
||||||
setupLocalizations(<String, String>{'en': selectMessageArb, 'es': selectMessageEsArb});
|
setupLocalizations(<String, String>{'en': selectMessageArb, 'es': selectMessageEsArb});
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains(intlImportDartCode));
|
expect(getSyntheticGeneratedFileContent(locale: 'en'), contains(intlImportDartCode));
|
||||||
expect(getGeneratedFileContent(locale: 'es'), contains(intlImportDartCode));
|
expect(getSyntheticGeneratedFileContent(locale: 'es'), contains(intlImportDartCode));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2662,7 +2710,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
});
|
});
|
||||||
// Tests a few of the lines in the generated code.
|
// Tests a few of the lines in the generated code.
|
||||||
// Localizations lookup code
|
// Localizations lookup code
|
||||||
final String localizationsFile = getGeneratedFileContent();
|
final String localizationsFile = getSyntheticGeneratedFileContent();
|
||||||
expect(localizationsFile.contains(' switch (locale.languageCode) {'), true);
|
expect(localizationsFile.contains(' switch (locale.languageCode) {'), true);
|
||||||
expect(localizationsFile.contains(" case 'en': return AppLocalizationsEn();"), true);
|
expect(localizationsFile.contains(" case 'en': return AppLocalizationsEn();"), true);
|
||||||
expect(localizationsFile.contains(" case 'es': return AppLocalizationsEs();"), true);
|
expect(localizationsFile.contains(" case 'es': return AppLocalizationsEs();"), true);
|
||||||
@ -2685,7 +2733,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
'en': singleMessageArbFileString,
|
'en': singleMessageArbFileString,
|
||||||
'es': singleEsMessageArbFileString,
|
'es': singleEsMessageArbFileString,
|
||||||
}, useDeferredLoading: true);
|
}, useDeferredLoading: true);
|
||||||
expect(getGeneratedFileContent(), isNot(contains(foundationImportDartCode)));
|
expect(getSyntheticGeneratedFileContent(), isNot(contains(foundationImportDartCode)));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2696,7 +2744,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
'en': singleMessageArbFileString,
|
'en': singleMessageArbFileString,
|
||||||
'es': singleEsMessageArbFileString,
|
'es': singleEsMessageArbFileString,
|
||||||
});
|
});
|
||||||
expect(getGeneratedFileContent(), contains(foundationImportDartCode));
|
expect(getSyntheticGeneratedFileContent(), contains(foundationImportDartCode));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2803,7 +2851,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
''';
|
''';
|
||||||
setupLocalizations(<String, String>{'en': enArbCheckList, 'es': esArbCheckList});
|
setupLocalizations(<String, String>{'en': enArbCheckList, 'es': esArbCheckList});
|
||||||
final String localizationsFile = getGeneratedFileContent(locale: 'es');
|
final String localizationsFile = getSyntheticGeneratedFileContent(locale: 'es');
|
||||||
expect(localizationsFile, contains(r'$one'));
|
expect(localizationsFile, contains(r'$one'));
|
||||||
expect(localizationsFile, contains(r'$two'));
|
expect(localizationsFile, contains(r'$two'));
|
||||||
expect(localizationsFile, contains(r'${three}'));
|
expect(localizationsFile, contains(r'${three}'));
|
||||||
@ -2854,7 +2902,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}
|
}
|
||||||
''';
|
''';
|
||||||
setupLocalizations(<String, String>{'en': enArbCheckList, 'es': esArbCheckList});
|
setupLocalizations(<String, String>{'en': enArbCheckList, 'es': esArbCheckList});
|
||||||
final String localizationsFile = getGeneratedFileContent(locale: 'es');
|
final String localizationsFile = getSyntheticGeneratedFileContent(locale: 'es');
|
||||||
expect(localizationsFile, contains(r'test $count test'));
|
expect(localizationsFile, contains(r'test $count test'));
|
||||||
expect(localizationsFile, contains(r'哈$count哈'));
|
expect(localizationsFile, contains(r'哈$count哈'));
|
||||||
expect(localizationsFile, contains(r'm${count}m'));
|
expect(localizationsFile, contains(r'm${count}m'));
|
||||||
@ -3061,14 +3109,17 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains('String money(int number)'));
|
expect(getSyntheticGeneratedFileContent(locale: 'en'), contains('String money(int number)'));
|
||||||
expect(getGeneratedFileContent(locale: 'ja'), contains('String money(int number)'));
|
expect(getSyntheticGeneratedFileContent(locale: 'ja'), contains('String money(int number)'));
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains('intl.NumberFormat.currency('));
|
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'ja'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
|
contains('intl.NumberFormat.currency('),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
contains('intl.NumberFormat.decimalPatternDigits('),
|
contains('intl.NumberFormat.decimalPatternDigits('),
|
||||||
);
|
);
|
||||||
expect(getGeneratedFileContent(locale: 'ja'), contains('decimalDigits: 3'));
|
expect(getSyntheticGeneratedFileContent(locale: 'ja'), contains('decimalDigits: 3'));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext(
|
testWithoutContext(
|
||||||
@ -3105,16 +3156,28 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains('String money(int number)'));
|
|
||||||
expect(getGeneratedFileContent(locale: 'ja'), contains('String money(int number)'));
|
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
|
contains('String money(int number)'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
|
contains('String money(int number)'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains('intl.NumberFormat.decimalPatternDigits('),
|
contains('intl.NumberFormat.decimalPatternDigits('),
|
||||||
);
|
);
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains('decimalDigits: 3'));
|
expect(getSyntheticGeneratedFileContent(locale: 'en'), contains('decimalDigits: 3'));
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains(r"return 'Sum $numberString'"));
|
expect(
|
||||||
expect(getGeneratedFileContent(locale: 'ja'), isNot(contains('intl.NumberFormat')));
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
expect(getGeneratedFileContent(locale: 'ja'), contains(r"return '合計 $number'"));
|
contains(r"return 'Sum $numberString'"),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
|
isNot(contains('intl.NumberFormat')),
|
||||||
|
);
|
||||||
|
expect(getSyntheticGeneratedFileContent(locale: 'ja'), contains(r"return '合計 $number'"));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -3152,16 +3215,28 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''',
|
}''',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains('String money(int number)'));
|
|
||||||
expect(getGeneratedFileContent(locale: 'ja'), contains('String money(int number)'));
|
|
||||||
expect(getGeneratedFileContent(locale: 'en'), isNot(contains('intl.NumberFormat')));
|
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains(r"return 'Sum $number'"));
|
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'ja'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
|
contains('String money(int number)'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
|
contains('String money(int number)'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
|
isNot(contains('intl.NumberFormat')),
|
||||||
|
);
|
||||||
|
expect(getSyntheticGeneratedFileContent(locale: 'en'), contains(r"return 'Sum $number'"));
|
||||||
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
contains('intl.NumberFormat.decimalPatternDigits('),
|
contains('intl.NumberFormat.decimalPatternDigits('),
|
||||||
);
|
);
|
||||||
expect(getGeneratedFileContent(locale: 'ja'), contains('decimalDigits: 3'));
|
expect(getSyntheticGeneratedFileContent(locale: 'ja'), contains('decimalDigits: 3'));
|
||||||
expect(getGeneratedFileContent(locale: 'ja'), contains(r"return '合計 $numberString'"));
|
expect(
|
||||||
|
getSyntheticGeneratedFileContent(locale: 'ja'),
|
||||||
|
contains(r"return '合計 $numberString'"),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -3213,20 +3288,20 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
|||||||
}''';
|
}''';
|
||||||
setupLocalizations(<String, String>{'en': arbFile});
|
setupLocalizations(<String, String>{'en': arbFile});
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
containsIgnoringWhitespace(r'''
|
containsIgnoringWhitespace(r'''
|
||||||
String orderNumber(int number) {
|
String orderNumber(int number) {
|
||||||
return 'This is order #$number.';
|
return 'This is order #$number.';
|
||||||
}
|
}
|
||||||
'''),
|
'''),
|
||||||
);
|
);
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains(intlImportDartCode));
|
expect(getSyntheticGeneratedFileContent(locale: 'en'), contains(intlImportDartCode));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('app localizations lookup is a public method', () {
|
testWithoutContext('app localizations lookup is a public method', () {
|
||||||
setupLocalizations(<String, String>{'en': singleMessageArbFileString});
|
setupLocalizations(<String, String>{'en': singleMessageArbFileString});
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(),
|
getSyntheticGeneratedFileContent(),
|
||||||
containsIgnoringWhitespace(r'''
|
containsIgnoringWhitespace(r'''
|
||||||
AppLocalizations lookupAppLocalizations(Locale locale) {
|
AppLocalizations lookupAppLocalizations(Locale locale) {
|
||||||
'''),
|
'''),
|
||||||
@ -3242,7 +3317,7 @@ AppLocalizations lookupAppLocalizations(Locale locale) {
|
|||||||
}
|
}
|
||||||
}''';
|
}''';
|
||||||
setupLocalizations(<String, String>{'en': arbFile}, useEscaping: true);
|
setupLocalizations(<String, String>{'en': arbFile}, useEscaping: true);
|
||||||
expect(getGeneratedFileContent(locale: 'en'), contains(r"Flutter\'s amazing"));
|
expect(getSyntheticGeneratedFileContent(locale: 'en'), contains(r"Flutter\'s amazing"));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('suppress warnings flag actually suppresses warnings', () {
|
testWithoutContext('suppress warnings flag actually suppresses warnings', () {
|
||||||
@ -3279,7 +3354,7 @@ AppLocalizations lookupAppLocalizations(Locale locale) {
|
|||||||
}
|
}
|
||||||
}''';
|
}''';
|
||||||
setupLocalizations(<String, String>{'en': arbFile});
|
setupLocalizations(<String, String>{'en': arbFile});
|
||||||
final String localizationsFile = getGeneratedFileContent(locale: 'en');
|
final String localizationsFile = getSyntheticGeneratedFileContent(locale: 'en');
|
||||||
expect(
|
expect(
|
||||||
localizationsFile,
|
localizationsFile,
|
||||||
containsIgnoringWhitespace(r'''
|
containsIgnoringWhitespace(r'''
|
||||||
@ -3305,7 +3380,7 @@ NumberFormat.decimalPatternDigits(
|
|||||||
}''';
|
}''';
|
||||||
setupLocalizations(<String, String>{'en': dollarSignWithSelect});
|
setupLocalizations(<String, String>{'en': dollarSignWithSelect});
|
||||||
expect(
|
expect(
|
||||||
getGeneratedFileContent(locale: 'en'),
|
getSyntheticGeneratedFileContent(locale: 'en'),
|
||||||
contains(r'\$nice_bug\nHello Bug! Manifestation #1 $_temp0'),
|
contains(r'\$nice_bug\nHello Bug! Manifestation #1 $_temp0'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -3340,7 +3415,7 @@ NumberFormat.decimalPatternDigits(
|
|||||||
}
|
}
|
||||||
''';
|
''';
|
||||||
setupLocalizations(<String, String>{'en': arbFile}, useNamedParameters: true);
|
setupLocalizations(<String, String>{'en': arbFile}, useNamedParameters: true);
|
||||||
final String localizationsFile = getGeneratedFileContent(locale: 'en');
|
final String localizationsFile = getSyntheticGeneratedFileContent(locale: 'en');
|
||||||
expect(
|
expect(
|
||||||
localizationsFile,
|
localizationsFile,
|
||||||
containsIgnoringWhitespace(r'''
|
containsIgnoringWhitespace(r'''
|
||||||
|
@ -49,6 +49,9 @@ dependencies:
|
|||||||
flutter_localizations:
|
flutter_localizations:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
intl: any # Pick up the pinned version from flutter_localizations
|
intl: any # Pick up the pinned version from flutter_localizations
|
||||||
|
|
||||||
|
flutter:
|
||||||
|
generate: true
|
||||||
''';
|
''';
|
||||||
|
|
||||||
String? _main;
|
String? _main;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user