Files
sdk/pkg/analysis_server/test/lsp/will_rename_files_test.dart
T
Danny Tuppeny 56e5655353 [analyzer] Migrate more LSP tests to null-safety
Change-Id: Iaeb2152d47df05434ab470901900da56cae7e792
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196125
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2021-04-20 21:15:28 +00:00

61 lines
1.6 KiB
Dart

// Copyright (c) 2020, 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 'dart:async';
import 'package:analysis_server/lsp_protocol/protocol_generated.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'server_abstract.dart';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(WillRenameFilesTest);
});
}
@reflectiveTest
class WillRenameFilesTest extends AbstractLspAnalysisServerTest {
Future<void> test_rename_updatesImports() async {
final otherFilePath = join(projectFolderPath, 'lib', 'other.dart');
final otherFileUri = Uri.file(otherFilePath);
final otherFileNewPath = join(projectFolderPath, 'lib', 'other_new.dart');
final otherFileNewUri = Uri.file(otherFileNewPath);
final mainContent = '''
import 'other.dart';
final a = A();
''';
final otherContent = '''
class A {}
''';
final expectedMainContent = '''
import 'other_new.dart';
final a = A();
''';
await initialize();
await openFile(mainFileUri, mainContent);
await openFile(otherFileUri, otherContent);
final edit = await onWillRename([
FileRename(
oldUri: otherFileUri.toString(),
newUri: otherFileNewUri.toString(),
),
]);
// Ensure applying the edit will give us the expected content.
final contents = {
mainFilePath: withoutMarkers(mainContent),
};
applyChanges(contents, edit.changes!);
expect(contents[mainFilePath], equals(expectedMainContent));
}
}