Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(860)

Unified Diff: pkg/analysis_server/test/domain_analysis_test.dart

Issue 300553014: Implementation for 'analysis.updateContent' API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/domain_analysis_test.dart
diff --git a/pkg/analysis_server/test/domain_analysis_test.dart b/pkg/analysis_server/test/domain_analysis_test.dart
index 7daf7fe300ad20711e7fa982481ea254c1ebe1ec..405757174785bba990e69cfa13f974652031f674 100644
--- a/pkg/analysis_server/test/domain_analysis_test.dart
+++ b/pkg/analysis_server/test/domain_analysis_test.dart
@@ -30,6 +30,7 @@ main() {
});
group('notification.errors', testNotificationErrors);
+ group('notification.errors', testUpdateContent);
Brian Wilkerson 2014/05/28 20:38:15 "errors" --> "updateContent"? I still don't under
scheglov 2014/05/28 20:44:05 Done.
group('AnalysisDomainHandler', () {
test('getFixes', () {
@@ -110,16 +111,6 @@ main() {
expect(response, isNull);
});
- test('updateContent', () {
- var request = new Request('0', AnalysisDomainHandler.UPDATE_CONTENT_METHOD);
-// request.setParameter(
-// AnalysisDomainHandler.FILES_PARAM,
-// {'project/test.dart' : null});
- var response = handler.handleRequest(request);
- // TODO(scheglov) implement
- expect(response, isNull);
- });
-
test('updateOptions', () {
var request = new Request('0', AnalysisDomainHandler.UPDATE_OPTIONS_METHOD);
request.setParameter(
@@ -213,20 +204,38 @@ class AnalysisTestHelper {
* Creates a project with a single Dart file `/project/bin/test.dart` with
* the given [code].
*/
- createSingleFileProject(code) {
- if (code is List<String>) {
- code = code.join('\n');
- }
- this.testCode = code;
+ void createSingleFileProject(code) {
+ this.testCode = _getCodeString(code);
resourceProvider.newFolder('/project');
resourceProvider.newFile('/project/pubspec.yaml', 'name: project');
resourceProvider.newFile(testFile, testCode);
Request request = new Request('0', AnalysisDomainHandler.SET_ANALYSIS_ROOTS_METHOD);
request.setParameter(AnalysisDomainHandler.INCLUDED_PARAM, ['/project']);
request.setParameter(AnalysisDomainHandler.EXCLUDED_PARAM, []);
+ handleSuccessfulRequest(request);
+ }
+
+ /**
+ * Validates that the given [request] is handled successfully.
+ */
+ void handleSuccessfulRequest(Request request) {
Response response = handler.handleRequest(request);
expect(response, isResponseSuccess('0'));
}
+
+ /**
+ * Stops the associated server.
+ */
+ void stopServer() {
+ server.done();
+ }
+
+ static String _getCodeString(code) {
+ if (code is List<String>) {
+ code = code.join('\n');
+ }
+ return code as String;
+ }
}
@@ -266,6 +275,64 @@ testNotificationErrors() {
}
+testUpdateContent() {
+ test('full content', () {
+ AnalysisTestHelper helper = new AnalysisTestHelper();
+ helper.createSingleFileProject('// empty');
+ return helper.waitForTasksFinished().then((_) {
+ // no errors initially
+ List<AnalysisError> errors = helper.getTestErrors();
+ expect(errors, isEmpty);
+ // update code
+ {
+ Request request = new Request('0', AnalysisDomainHandler.UPDATE_CONTENT_METHOD);
+ request.setParameter('files',
+ {
+ helper.testFile : {
+ AnalysisDomainHandler.CONTENT_PARAM : 'library lib'
+ }
+ });
+ helper.handleSuccessfulRequest(request);
+ }
+ // wait, there is an error
+ helper.waitForTasksFinished().then((_) {
+ List<AnalysisError> errors = helper.getTestErrors();
+ expect(errors, hasLength(1));
+ });
+ });
+ });
+
+ test('incremental', () {
+ AnalysisTestHelper helper = new AnalysisTestHelper();
+ helper.createSingleFileProject('library A;');
+ return helper.waitForTasksFinished().then((_) {
+ // no errors initially
+ List<AnalysisError> errors = helper.getTestErrors();
+ expect(errors, isEmpty);
+ // update code
+ {
+ Request request = new Request('0', AnalysisDomainHandler.UPDATE_CONTENT_METHOD);
+ request.setParameter('files',
+ {
+ helper.testFile : {
+ AnalysisDomainHandler.CONTENT_PARAM : 'library lib',
+ AnalysisDomainHandler.OFFSET_PARAM : 'library '.length,
+ AnalysisDomainHandler.OLD_LENGTH_PARAM : 'A;'.length,
+ AnalysisDomainHandler.NEW_LENGTH_PARAM : 'lib'.length,
+ }
+ });
+ helper.handleSuccessfulRequest(request);
+ }
+ // wait, there is an error
+ helper.waitForTasksFinished().then((_) {
+ List<AnalysisError> errors = helper.getTestErrors();
+ expect(errors, hasLength(1));
+ });
+ });
+ });
+}
+
+
class AnalysisError {
final String file;
final String errorCode;

Powered by Google App Engine
This is Rietveld 408576698