mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 14:32:24 +00:00
[analysis_server] Migrate some LSP tests off old marker functions
No functional changes, just moves the snippets tests and a few others off the old marker functions to the new TestCode class for consistency. With this change, there are approximately 15 remaining instances of "withoutMarkers" to remove (inc. the declaration). Change-Id: I7f11992bb9ce47740adf6972ed097cabbd011607 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333520 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
3f1e15ab34
commit
d1a1a273ee
23 changed files with 217 additions and 170 deletions
|
@ -2,9 +2,11 @@
|
|||
// 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/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../utils/test_code_extensions.dart';
|
||||
import 'integration_tests.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -16,14 +18,14 @@ void main() {
|
|||
@reflectiveTest
|
||||
class DiagnosticTest extends AbstractLspAnalysisServerIntegrationTest {
|
||||
Future<void> test_contextMessage() async {
|
||||
const content = '''
|
||||
final code = TestCode.parse('''
|
||||
void f() {
|
||||
x = 0;
|
||||
int [[x]] = 1;
|
||||
int [!x!] = 1;
|
||||
print(x);
|
||||
}
|
||||
''';
|
||||
newFile(mainFilePath, withoutMarkers(content));
|
||||
''');
|
||||
newFile(mainFilePath, code.code);
|
||||
|
||||
final diagnosticsUpdate = waitForDiagnostics(mainFileUri);
|
||||
await initialize();
|
||||
|
@ -41,7 +43,7 @@ void f() {
|
|||
final relatedInfo = relatedInformation.first;
|
||||
expect(relatedInfo.message, equals("The declaration of 'x' is here."));
|
||||
expect(relatedInfo.location.uri, equals(mainFileUri));
|
||||
expect(relatedInfo.location.range, equals(rangeFromMarkers(content)));
|
||||
expect(relatedInfo.location.range, equals(code.range.range));
|
||||
}
|
||||
|
||||
Future<void> test_initialAnalysis() async {
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analysis_server/lsp_protocol/protocol.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../tool/lsp_spec/matchers.dart';
|
||||
import '../utils/test_code_extensions.dart';
|
||||
import 'server_abstract.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -18,15 +20,15 @@ void main() {
|
|||
@reflectiveTest
|
||||
class CancelRequestTest extends AbstractLspAnalysisServerTest {
|
||||
Future<void> test_cancel() async {
|
||||
final content = '''
|
||||
final code = TestCode.parse('''
|
||||
void f() {
|
||||
InOtherF^
|
||||
}
|
||||
''';
|
||||
''');
|
||||
|
||||
final initialAnalysis = waitForAnalysisComplete();
|
||||
await initialize();
|
||||
await openFile(mainFileUri, withoutMarkers(content));
|
||||
await openFile(mainFileUri, code.code);
|
||||
await initialAnalysis;
|
||||
|
||||
// Create a completion request that we'll cancel.
|
||||
|
@ -34,7 +36,7 @@ void f() {
|
|||
Method.textDocument_completion,
|
||||
CompletionParams(
|
||||
textDocument: TextDocumentIdentifier(uri: mainFileUri),
|
||||
position: positionFromMarker(content),
|
||||
position: code.position.position,
|
||||
),
|
||||
);
|
||||
// And a request to cancel it.
|
||||
|
|
|
@ -409,17 +409,17 @@ build() {
|
|||
setDocumentChangesSupport();
|
||||
setSupportedCodeActionKinds([CodeActionKind.Refactor]);
|
||||
|
||||
const content = '''
|
||||
final code = TestCode.parse('''
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
build() => Contai^ner(child: Container());
|
||||
''';
|
||||
''');
|
||||
|
||||
newFile(mainFilePath, withoutMarkers(content));
|
||||
newFile(mainFilePath, code.code);
|
||||
await initialize();
|
||||
|
||||
final codeActions = await getCodeActions(mainFileUri,
|
||||
position: positionFromMarker(content));
|
||||
final codeActions =
|
||||
await getCodeActions(mainFileUri, position: code.position.position);
|
||||
final names = codeActions.map(
|
||||
(e) => e.map((command) => command.title, (action) => action.title),
|
||||
);
|
||||
|
|
|
@ -1474,7 +1474,7 @@ import 'package:^';
|
|||
Future<void> test_concurrentRequestsCancellation() async {
|
||||
// We expect a new completion request to cancel any in-flight request so
|
||||
// send multiple without awaiting, then check only the last one completes.
|
||||
final code = TestCode.parse('^');
|
||||
final code = TestCode.empty;
|
||||
|
||||
await initialize();
|
||||
await openFile(mainFileUri, code.code);
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
|
||||
import 'package:analysis_server/lsp_protocol/protocol.dart';
|
||||
import 'package:analyzer/source/line_info.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../utils/test_code_extensions.dart';
|
||||
import 'server_abstract.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -60,28 +62,26 @@ class Foo {
|
|||
}
|
||||
|
||||
Future<void> test_single() async {
|
||||
final content = '''
|
||||
final code = TestCode.parse('''
|
||||
class Foo<T> {
|
||||
void a(String b) {
|
||||
print((1 ^+ 2) * 3);
|
||||
}
|
||||
}
|
||||
''';
|
||||
final contentWithoutMarker = withoutMarkers(content);
|
||||
''');
|
||||
|
||||
await initialize();
|
||||
await openFile(mainFileUri, contentWithoutMarker);
|
||||
final lineInfo = LineInfo.fromContent(contentWithoutMarker);
|
||||
await openFile(mainFileUri, code.code);
|
||||
final lineInfo = LineInfo.fromContent(code.code);
|
||||
|
||||
// The returned List corresponds to the input list of positions, and not
|
||||
// the set of ranges - each range within that list has a (recursive) parent
|
||||
// to walk up all ranges for that position.
|
||||
final regions =
|
||||
await getSelectionRanges(mainFileUri, [positionFromMarker(content)]);
|
||||
await getSelectionRanges(mainFileUri, [code.position.position]);
|
||||
expect(regions!.length, equals(1)); // Only one position was sent.
|
||||
final regionTexts =
|
||||
_getSelectionRangeText(lineInfo, contentWithoutMarker, regions.first)
|
||||
.toList();
|
||||
_getSelectionRangeText(lineInfo, code.code, regions.first).toList();
|
||||
|
||||
expect(
|
||||
regionTexts,
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/class_declaration.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -27,28 +28,30 @@ class ClassDeclarationTest extends DartSnippetProducerTest {
|
|||
String get prefix => ClassDeclaration.prefix;
|
||||
|
||||
Future<void> test_class() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
class A {}
|
||||
|
||||
^
|
||||
|
||||
class B {}''';
|
||||
class B {}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
class A {}
|
||||
|
||||
class ClassName {
|
||||
|
||||
}
|
||||
|
||||
class B {}''');
|
||||
class B {}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 34);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/do_statement.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -27,24 +28,26 @@ class DoStatementTest extends DartSnippetProducerTest {
|
|||
String get prefix => DoStatement.prefix;
|
||||
|
||||
Future<void> test_do() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
do^
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
do {
|
||||
|
||||
} while (condition);
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 22);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
|
|
@ -30,15 +30,16 @@ class FlutterStatefulWidgetTest extends FlutterSnippetProducerTest {
|
|||
Future<void> test_noSuperParams() async {
|
||||
writeTestPackageConfig(flutter: true, languageVersion: '2.16');
|
||||
|
||||
final snippet = await expectValidSnippet('^');
|
||||
final code = TestCode.empty;
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
var code = '';
|
||||
var result = code.code;
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class MyWidget extends StatefulWidget {
|
||||
|
@ -65,7 +66,7 @@ class _MyWidgetState extends State<MyWidget> {
|
|||
Future<void> test_valid() async {
|
||||
writeTestPackageConfig(flutter: true);
|
||||
|
||||
final snippet = await expectValidSnippet('^');
|
||||
final snippet = await expectValidSnippet(TestCode.empty);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
final expected = TestCode.parse('''
|
||||
|
|
|
@ -31,15 +31,16 @@ class FlutterStatefulWidgetWithAnimationControllerTest
|
|||
Future<void> test_noSuperParams() async {
|
||||
writeTestPackageConfig(flutter: true, languageVersion: '2.16');
|
||||
|
||||
final snippet = await expectValidSnippet('^');
|
||||
final code = TestCode.empty;
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
var code = '';
|
||||
var result = code.code;
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class MyWidget extends StatefulWidget {
|
||||
|
@ -81,7 +82,7 @@ class _MyWidgetState extends State<MyWidget>
|
|||
Future<void> test_valid() async {
|
||||
writeTestPackageConfig(flutter: true);
|
||||
|
||||
final snippet = await expectValidSnippet('^');
|
||||
final snippet = await expectValidSnippet(TestCode.empty);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
final expected = TestCode.parse('''
|
||||
|
|
|
@ -29,7 +29,7 @@ class FlutterStatelessWidgetTest extends FlutterSnippetProducerTest {
|
|||
Future<void> test_noSuperParams() async {
|
||||
writeTestPackageConfig(flutter: true, languageVersion: '2.16');
|
||||
|
||||
final snippet = await expectValidSnippet('^');
|
||||
final snippet = await expectValidSnippet(TestCode.empty);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
final expected = TestCode.parse('''
|
||||
|
@ -55,7 +55,7 @@ class /*0*/MyWidget extends StatelessWidget {
|
|||
Future<void> test_valid() async {
|
||||
writeTestPackageConfig(flutter: true);
|
||||
|
||||
final snippet = await expectValidSnippet('^');
|
||||
final snippet = await expectValidSnippet(TestCode.empty);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
final expected = TestCode.parse('''
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/for_in_statement.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -27,24 +28,26 @@ class ForInStatementTest extends DartSnippetProducerTest {
|
|||
String get prefix => ForInStatement.prefix;
|
||||
|
||||
Future<void> test_for() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
forin^
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
for (var element in collection) {
|
||||
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 51);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/for_statement.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -27,24 +28,26 @@ class ForStatementTest extends DartSnippetProducerTest {
|
|||
String get prefix => ForStatement.prefix;
|
||||
|
||||
Future<void> test_for() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
for^
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
for (var i = 0; i < count; i++) {
|
||||
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 51);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/function_declaration.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -27,24 +28,26 @@ class FunctionDeclarationTest extends DartSnippetProducerTest {
|
|||
String get prefix => FunctionDeclaration.prefix;
|
||||
|
||||
Future<void> test_classMethod() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
class A {
|
||||
^
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
class A {
|
||||
void name(params) {
|
||||
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 36);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
@ -73,24 +76,26 @@ class A {
|
|||
}
|
||||
|
||||
Future<void> test_nested() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void a() {
|
||||
^
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void a() {
|
||||
void name(params) {
|
||||
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 37);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
@ -119,28 +124,30 @@ void a() {
|
|||
}
|
||||
|
||||
Future<void> test_topLevel() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
class A {}
|
||||
|
||||
^
|
||||
|
||||
class B {}''';
|
||||
class B {}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
class A {}
|
||||
|
||||
void name(params) {
|
||||
|
||||
}
|
||||
|
||||
class B {}''');
|
||||
class B {}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 36);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/if_else_statement.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -27,26 +28,28 @@ class IfElseStatementTest extends DartSnippetProducerTest {
|
|||
String get prefix => IfElseStatement.prefix;
|
||||
|
||||
Future<void> test_ifElse() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
if^
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
if (condition) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 34);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
@ -61,21 +64,22 @@ void f() {
|
|||
}
|
||||
|
||||
Future<void> test_ifElse_indentedInsideBlock() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
if (true) {
|
||||
if^
|
||||
}
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
if (true) {
|
||||
if (condition) {
|
||||
|
@ -84,7 +88,8 @@ void f() {
|
|||
|
||||
}
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 52);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/if_statement.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -27,24 +28,26 @@ class IfStatementTest extends DartSnippetProducerTest {
|
|||
String get prefix => IfStatement.prefix;
|
||||
|
||||
Future<void> test_if() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
if^
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
if (condition) {
|
||||
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 34);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
@ -59,28 +62,30 @@ void f() {
|
|||
}
|
||||
|
||||
Future<void> test_if_indentedInsideBlock() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
if (true) {
|
||||
if^
|
||||
}
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
if (true) {
|
||||
if (condition) {
|
||||
|
||||
}
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 52);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/main_function.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -48,26 +49,27 @@ class MainFunctionTest extends DartSnippetProducerTest {
|
|||
|
||||
Future<void> test_typedPrefix() => testInFile(
|
||||
testFile.path,
|
||||
code: '$prefix^',
|
||||
content: '$prefix^',
|
||||
expectArgsParameter: true,
|
||||
);
|
||||
|
||||
Future<void> testInFile(
|
||||
String file, {
|
||||
String code = '^',
|
||||
String content = '^',
|
||||
required bool expectArgsParameter,
|
||||
}) async {
|
||||
testFilePath = file;
|
||||
final code = TestCode.parse(content);
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
final expectedParams = expectArgsParameter ? 'List<String> args' : '';
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void main($expectedParams) {
|
||||
|
||||
}''');
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/switch_statement.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -27,19 +28,20 @@ class SwitchStatementTest extends DartSnippetProducerTest {
|
|||
String get prefix => SwitchStatement.prefix;
|
||||
|
||||
Future<void> test_switch() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
sw^
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
switch (expression) {
|
||||
case value:
|
||||
|
@ -47,7 +49,8 @@ void f() {
|
|||
break;
|
||||
default:
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 57);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
@ -71,21 +74,22 @@ void f() {
|
|||
}
|
||||
|
||||
Future<void> test_switch_indentedInsideBlock() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
if (true) {
|
||||
sw^
|
||||
}
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
if (true) {
|
||||
switch (expression) {
|
||||
|
@ -95,7 +99,8 @@ void f() {
|
|||
default:
|
||||
}
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 77);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/test_definition.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -28,24 +29,26 @@ class TestDefinitionTest extends DartSnippetProducerTest {
|
|||
|
||||
Future<void> test_inTestFile() async {
|
||||
testFilePath = convertPath('$testPackageLibPath/test/foo_test.dart');
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
test^
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
test('test name', () {
|
||||
|
||||
});
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 40);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
@ -63,7 +66,8 @@ void f() {
|
|||
var code = r'''
|
||||
void f() {
|
||||
test^
|
||||
}''';
|
||||
}
|
||||
''';
|
||||
await expectNotValidSnippet(code);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/test_group_definition.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -28,24 +29,26 @@ class TestGroupDefinitionTest extends DartSnippetProducerTest {
|
|||
|
||||
Future<void> test_inTestFile() async {
|
||||
testFilePath = convertPath('$testPackageLibPath/test/foo_test.dart');
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
group^
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
group('group name', () {
|
||||
|
||||
});
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 42);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
@ -63,7 +66,8 @@ void f() {
|
|||
var code = r'''
|
||||
void f() {
|
||||
group^
|
||||
}''';
|
||||
}
|
||||
''';
|
||||
await expectNotValidSnippet(code);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
|||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../abstract_single_unit.dart';
|
||||
import '../test_support.dart';
|
||||
|
||||
export '../test_support.dart';
|
||||
|
||||
|
@ -30,7 +29,7 @@ abstract class DartSnippetProducerTest extends AbstractSingleUnitTest {
|
|||
Future<void> assertSnippet(String content, String expected) async {
|
||||
final code = TestCode.parse(content);
|
||||
final expectedCode = TestCode.parse(expected);
|
||||
final snippet = await expectValidSnippet2(code);
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
|
@ -78,21 +77,7 @@ abstract class DartSnippetProducerTest extends AbstractSingleUnitTest {
|
|||
expect(await producer.isValid(), isFalse);
|
||||
}
|
||||
|
||||
Future<Snippet> expectValidSnippet(String code) async {
|
||||
// TODO(dantup): Remove this function and convert other snippets to new
|
||||
// format.
|
||||
await resolveTestCode(withoutMarkers(code));
|
||||
final request = DartSnippetRequest(
|
||||
unit: testAnalysisResult,
|
||||
offset: offsetFromMarker(code),
|
||||
);
|
||||
|
||||
final producer = generator(request, elementImportCache: {});
|
||||
expect(await producer.isValid(), isTrue);
|
||||
return producer.compute();
|
||||
}
|
||||
|
||||
Future<Snippet> expectValidSnippet2(TestCode code) async {
|
||||
Future<Snippet> expectValidSnippet(TestCode code) async {
|
||||
await resolveTestCode(code.code);
|
||||
final request = DartSnippetRequest(
|
||||
unit: testAnalysisResult,
|
||||
|
@ -142,7 +127,7 @@ abstract class FlutterSnippetProducerTest extends DartSnippetProducerTest {
|
|||
Future<void> test_valid_importsAndEditsOverlap() async {
|
||||
writeTestPackageConfig(flutter: true);
|
||||
|
||||
final snippet = await expectValidSnippet('$prefix^');
|
||||
final snippet = await expectValidSnippet(TestCode.parse('$prefix^'));
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
|
||||
|
@ -160,11 +145,11 @@ abstract class FlutterSnippetProducerTest extends DartSnippetProducerTest {
|
|||
Future<void> test_valid_suffixReplacement() async {
|
||||
writeTestPackageConfig(flutter: true);
|
||||
|
||||
final snippet = await expectValidSnippet('''
|
||||
final snippet = await expectValidSnippet(TestCode.parse('''
|
||||
class A {}
|
||||
|
||||
$prefix^
|
||||
''');
|
||||
'''));
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/try_catch_statement.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -27,26 +28,28 @@ class TryCatchStatementTest extends DartSnippetProducerTest {
|
|||
String get prefix => TryCatchStatement.prefix;
|
||||
|
||||
Future<void> test_tryCatch() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
tr^
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
try {
|
||||
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 23);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
@ -61,21 +64,22 @@ void f() {
|
|||
}
|
||||
|
||||
Future<void> test_tryCatch_indentedInsideBlock() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
if (true) {
|
||||
tr^
|
||||
}
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
if (true) {
|
||||
try {
|
||||
|
@ -84,7 +88,8 @@ void f() {
|
|||
|
||||
}
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 41);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/snippets/dart/while_statement.dart';
|
||||
import 'package:analyzer/src/test_utilities/test_code_format.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -27,24 +28,26 @@ class WhileStatementTest extends DartSnippetProducerTest {
|
|||
String get prefix => WhileStatement.prefix;
|
||||
|
||||
Future<void> test_while() async {
|
||||
var code = r'''
|
||||
final code = TestCode.parse(r'''
|
||||
void f() {
|
||||
while^
|
||||
}''';
|
||||
}
|
||||
''');
|
||||
final snippet = await expectValidSnippet(code);
|
||||
expect(snippet.prefix, prefix);
|
||||
expect(snippet.label, label);
|
||||
expect(snippet.change.edits, hasLength(1));
|
||||
code = withoutMarkers(code);
|
||||
var result = code.code;
|
||||
for (var edit in snippet.change.edits) {
|
||||
code = SourceEdit.applySequence(code, edit.edits);
|
||||
result = SourceEdit.applySequence(result, edit.edits);
|
||||
}
|
||||
expect(code, '''
|
||||
expect(result, '''
|
||||
void f() {
|
||||
while (condition) {
|
||||
|
||||
}
|
||||
}''');
|
||||
}
|
||||
''');
|
||||
expect(snippet.change.selection!.file, testFile.path);
|
||||
expect(snippet.change.selection!.offset, 37);
|
||||
expect(snippet.change.linkedEditGroups.map((group) => group.toJson()), [
|
||||
|
|
|
@ -29,6 +29,10 @@ class TestCode {
|
|||
static final _positionPattern = RegExp(r'\/\*(\d+)\*\/');
|
||||
static final _rangeStartPattern = RegExp(r'\/\*\[(\d+)\*\/');
|
||||
static final _rangeEndPattern = RegExp(r'\/\*(\d+)\]\*\/');
|
||||
|
||||
/// An empty code block with a single position at offset 0.
|
||||
static final empty = TestCode.parse('^');
|
||||
|
||||
final String code;
|
||||
final String rawCode;
|
||||
|
||||
|
|
Loading…
Reference in a new issue