Chromium Code Reviews| Index: pkg/analysis_server/test/completion_test.dart |
| diff --git a/pkg/analysis_server/test/completion_test.dart b/pkg/analysis_server/test/completion_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b91bcab1894b3c8ed34da6e18f5e74f04dab7425 |
| --- /dev/null |
| +++ b/pkg/analysis_server/test/completion_test.dart |
| @@ -0,0 +1,100 @@ |
| +// Copyright (c) 2014, 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. |
| + |
| +library test.domain.completion; |
| + |
| +import 'dart:async'; |
| + |
| +import 'package:analysis_server/src/constants.dart'; |
| +import 'package:analysis_server/src/domain_completion.dart'; |
| +import 'package:analysis_server/src/protocol.dart'; |
| +import 'package:analysis_services/index/index.dart' show Index; |
| +import 'package:analysis_services/index/local_memory_index.dart'; |
| +import 'package:analysis_testing/reflective_tests.dart'; |
| +import 'package:unittest/unittest.dart'; |
| + |
| +import 'analysis_abstract.dart'; |
| + |
| +main() { |
| + group('completion', () { |
| + runReflectiveTests(CompletionTest); |
| + }); |
| +} |
| + |
| +@ReflectiveTestCase() |
| +class CompletionTest extends AbstractAnalysisTest { |
| + String completionId; |
| + List<CompletionSuggestion> suggestions = []; |
| + bool suggestionsDone = false; |
| + |
| + void assertHasResult(String completion) { |
| + var cs = suggestions.firstWhere((cs) => cs.completion == completion, orElse: () { |
| + var completions = suggestions.map((s) => s.completion).toList(); |
| + fail('expected "$completion" but found\n $completions'); |
| + }); |
| + } |
| + |
| + void assertValidId(String id) { |
| + expect(id, isNotNull); |
| + expect(id.isNotEmpty, isTrue); |
| + } |
| + |
| + @override |
| + Index createIndex() { |
| + return createLocalMemoryIndex(); |
| + } |
| + |
| + Future getSuggestions(String pattern, int offset) { |
|
scheglov
2014/07/17 20:40:00
You don't use "pattern", did you mean to find offs
danrubel
2014/07/17 21:01:14
Yes! Good eyes. Fixed.
|
| + return waitForTasksFinished().then((_) { |
| + Request request = new Request('0', COMPLETION_GET_SUGGESTIONS); |
| + request.setParameter(FILE, testFile); |
| + request.setParameter(OFFSET, offset); |
| + Response response = handleSuccessfulRequest(request); |
| + completionId = response.getResult(ID); |
| + assertValidId(completionId); |
| + return waitForSuggestions(); |
| + }); |
| + } |
| + |
| + void processNotification(Notification notification) { |
| + if (notification.event == COMPLETION_RESULTS) { |
| + String id = notification.getParameter(ID); |
| + assertValidId(id); |
| + if (id == completionId) { |
| + expect(suggestionsDone, isFalse); |
| + suggestionsDone = notification.getParameter(LAST); |
| + expect(suggestionsDone, isNotNull); |
| + for (Map<String, Object> json in notification.getParameter(RESULTS)) { |
| + expect(json, isNotNull); |
| + suggestions.add(new CompletionSuggestion.fromJson(json)); |
| + } |
| + } |
| + } |
| + } |
| + |
| + @override |
| + void setUp() { |
| + super.setUp(); |
| + createProject(); |
| + handler = new CompletionDomainHandler(server); |
| + } |
| + |
| + Future waitForSuggestions() { |
| + if (suggestionsDone) { |
| + return new Future.value(); |
| + } |
| + return new Future.delayed(Duration.ZERO, waitForSuggestions); |
| + } |
| + |
| + test_suggestions() { |
| + addTestFile(''' |
| + import 'dart:html'; |
|
scheglov
2014/07/17 20:40:00
It's up to you, but I'd start sample code with lin
danrubel
2014/07/17 21:01:14
I found it jarring to see things abruptly left ali
scheglov
2014/07/17 21:09:32
OK
|
| + main() {} |
| + '''); |
| + return getSuggestions('}', 0).then((_) { |
| + assertHasResult('Object'); |
| + assertHasResult('HtmlElement'); |
| + }); |
| + } |
| +} |