-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 49054. Use prefix filter for UriBasedDirective, use MatchStyle.…
…FILENAME Bug: #49054 Change-Id: I127944d9eca20f0d8a57e26b3050fcfcb381d2b1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245623 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
- Loading branch information
Showing
6 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
pkg/analysis_server/test/services/completion/dart/location/directive_uri_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart'; | ||
import 'package:analyzer_utilities/check/check.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../../../../client/completion_driver_test.dart'; | ||
import '../completion_check.dart'; | ||
|
||
void main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(DirectiveUriTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class DirectiveUriTest extends AbstractCompletionDriverTest { | ||
@override | ||
TestingCompletionProtocol get protocol => TestingCompletionProtocol.version2; | ||
|
||
Future<void> test_uri_end() async { | ||
await _checkDirectives( | ||
uriContent: 'foo0^', | ||
validator: (response) { | ||
// We have both `foo0x`, but no `bar`. | ||
check(response).suggestions.matchesInAnyOrder([ | ||
(suggestion) => suggestion | ||
..isImport | ||
..completion.isEqualTo('package:foo/foo01.dart'), | ||
(suggestion) => suggestion | ||
..isImport | ||
..completion.isEqualTo('package:foo/foo02.dart'), | ||
]); | ||
}, | ||
); | ||
} | ||
|
||
Future<void> test_uri_notEnd() async { | ||
await _checkDirectives( | ||
uriContent: 'foo0^xyz', | ||
validator: (response) { | ||
// We ignore 'xyz' after the caret. | ||
check(response).suggestions.matchesInAnyOrder([ | ||
(suggestion) => suggestion | ||
..isImport | ||
..completion.isEqualTo('package:foo/foo01.dart'), | ||
(suggestion) => suggestion | ||
..isImport | ||
..completion.isEqualTo('package:foo/foo02.dart'), | ||
]); | ||
}, | ||
); | ||
} | ||
|
||
Future<void> _checkDirectives({ | ||
required String uriContent, | ||
required void Function(CompletionResponseForTesting response) validator, | ||
}) async { | ||
_configurePackagesFooBar(); | ||
|
||
{ | ||
var response = await getTestCodeSuggestions(''' | ||
export '$uriContent'; | ||
'''); | ||
validator(response); | ||
} | ||
|
||
{ | ||
var response = await getTestCodeSuggestions(''' | ||
import '$uriContent'; | ||
'''); | ||
validator(response); | ||
} | ||
} | ||
|
||
void _configurePackagesFooBar() { | ||
final fooPackageRoot = getFolder('$packagesRootPath/foo'); | ||
newFile('$packagesRootPath/foo/lib/foo01.dart', ''); | ||
newFile('$packagesRootPath/foo/lib/foo02.dart', ''); | ||
// We use this file to check that exactly `foo0` is used as prefix. | ||
// So, we don't have one-off and don't use just `foo`. | ||
newFile('$packagesRootPath/foo/lib/foo11.dart', ''); | ||
|
||
final barPackageRoot = getFolder('$packagesRootPath/bar'); | ||
newFile('$packagesRootPath/bar/lib/bar01.dart', ''); | ||
|
||
writeTestPackageConfig( | ||
config: PackageConfigFileBuilder() | ||
..add(name: 'foo', rootPath: fooPackageRoot.path) | ||
..add(name: 'bar', rootPath: barPackageRoot.path), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters