Suggest a potential valid name for the flutter project when using flutter create (#130900)

Fixes https://github.com/flutter/flutter/issues/109775

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
This commit is contained in:
Valentin Vignal
2023-07-22 03:09:25 +08:00
committed by GitHub
parent 764095ce1a
commit be7c7e3e45
3 changed files with 45 additions and 4 deletions

View File

@@ -735,10 +735,13 @@ void main() {
testUsingContext('plugin project with invalid custom project name', () async {
expect(
() => _createProject(projectDir,
<String>['--no-pub', '--template=plugin', '--project-name', 'xyz.xyz', '--platforms', 'android,ios',],
<String>['--no-pub', '--template=plugin', '--project-name', 'xyz-xyz', '--platforms', 'android,ios',],
<String>[],
),
throwsToolExit(message: '"xyz.xyz" is not a valid Dart package name.'),
allOf(
throwsToolExit(message: '"xyz-xyz" is not a valid Dart package name.'),
throwsToolExit(message: 'Try "xyz_xyz" instead.'),
),
);
});

View File

@@ -20,6 +20,18 @@ void main() {
expect(isValidPackageName('Foo_bar'), false);
});
test('Suggests a valid Pub package name', () {
expect(potentialValidPackageName('92'), '_92');
expect(potentialValidPackageName('a-b-c'), 'a_b_c');
expect(potentialValidPackageName('Foo_bar'), 'foo_bar');
expect(potentialValidPackageName('foo-_bar'), 'foo__bar');
expect(potentialValidPackageName('잘못된 이름'), isNull, reason: 'It should return null if it cannot find a valid name.');
});
test('kWindowsDrivePattern', () {
expect(CreateBase.kWindowsDrivePattern.hasMatch(r'D:\'), isFalse);
expect(CreateBase.kWindowsDrivePattern.hasMatch(r'z:\'), isFalse);