Files
sdk/pkg/analysis_server/test/analysis/notification_folding_test.dart
T
Sam Rawlins 27984095de [analysis_server] Avoid Future-of-implicit-dynamic in tests
* 99% of these are `Future ` --> `Future<void> `
* There are some `test_` methods which declare a return type of `Future` which
  is non-idiomatic, I think, but in order to create a pragmatic consistency, I
  added `<void>` to the few test methods in these libraries. Later if we
  desire, we can remove all of the return types.
* Also a few `Completer ` --> `Completer<void> ` and
  `Stream ` --> `Stream<Object?> `
* There are many remaining cases in `lib/`

Change-Id: I41cd51bab6886788e15ac7065dd21e95e789d09f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287260
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-03-07 21:12:58 +00:00

98 lines
2.9 KiB
Dart

// Copyright (c) 2018, 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/protocol/protocol_constants.dart';
import 'package:analysis_server/src/protocol_server.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../analysis_server_base.dart';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(AnalysisNotificationFoldingTest);
});
}
@reflectiveTest
class AnalysisNotificationFoldingTest extends PubPackageAnalysisServerTest {
static const sampleCode = '''
import 'dart:async';
import 'dart:core';
main async() {}
''';
static final expectedResults = [
// We don't include the first "import" in the region because
// we want that to remain visible (not collapse).
FoldingRegion(FoldingKind.DIRECTIVES, 6, 34)
];
List<FoldingRegion>? lastRegions;
late Completer<void> _regionsReceived;
@override
void processNotification(Notification notification) {
if (notification.event == ANALYSIS_NOTIFICATION_FOLDING) {
var params = AnalysisFoldingParams.fromNotification(notification);
if (params.file == testFile.path) {
lastRegions = params.regions;
_regionsReceived.complete();
}
} else if (notification.event == SERVER_NOTIFICATION_ERROR) {
var params = ServerErrorParams.fromNotification(notification);
throw '${params.message}\n${params.stackTrace}';
}
}
@override
Future<void> setUp() async {
super.setUp();
await setRoots(included: [workspaceRootPath], excluded: []);
}
Future<void> subscribeForFolding() async {
await addAnalysisSubscription(AnalysisService.FOLDING, testFile);
}
Future<void> test_afterAnalysis() async {
addTestFile(sampleCode);
await waitForTasksFinished();
expect(lastRegions, isNull);
await waitForFolding(() async => await subscribeForFolding());
expect(lastRegions, expectedResults);
}
Future<void> test_afterUpdate() async {
addTestFile('');
// Currently required to get notifications on updates
setPriorityFiles([testFile]);
// Before subscribing, we shouldn't have had any folding regions.
await waitForTasksFinished();
expect(lastRegions, isNull);
// With no content, there should be zero regions.
await waitForFolding(() async => await subscribeForFolding());
expect(lastRegions, hasLength(0));
// With sample code there will be folding regions.
await waitForFolding(() async => modifyTestFile(sampleCode));
expect(lastRegions, expectedResults);
}
Future<void> waitForFolding(Future<void> Function() action) async {
_regionsReceived = Completer();
await action();
return _regionsReceived.future;
}
}