Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library test.domain.completion; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:analysis_server/src/constants.dart'; | |
| 10 import 'package:analysis_server/src/domain_completion.dart'; | |
| 11 import 'package:analysis_server/src/protocol.dart'; | |
| 12 import 'package:analysis_services/index/index.dart' show Index; | |
| 13 import 'package:analysis_services/index/local_memory_index.dart'; | |
| 14 import 'package:analysis_testing/reflective_tests.dart'; | |
| 15 import 'package:unittest/unittest.dart'; | |
| 16 | |
| 17 import 'analysis_abstract.dart'; | |
| 18 | |
| 19 main() { | |
| 20 group('completion', () { | |
| 21 runReflectiveTests(CompletionTest); | |
| 22 }); | |
| 23 } | |
| 24 | |
| 25 @ReflectiveTestCase() | |
| 26 class CompletionTest extends AbstractAnalysisTest { | |
| 27 String completionId; | |
| 28 List<CompletionSuggestion> suggestions = []; | |
| 29 bool suggestionsDone = false; | |
| 30 | |
| 31 void assertHasResult(String completion) { | |
| 32 var cs = suggestions.firstWhere((cs) => cs.completion == completion, orElse: () { | |
| 33 var completions = suggestions.map((s) => s.completion).toList(); | |
| 34 fail('expected "$completion" but found\n $completions'); | |
| 35 }); | |
| 36 } | |
| 37 | |
| 38 void assertValidId(String id) { | |
| 39 expect(id, isNotNull); | |
| 40 expect(id.isNotEmpty, isTrue); | |
| 41 } | |
| 42 | |
| 43 @override | |
| 44 Index createIndex() { | |
| 45 return createLocalMemoryIndex(); | |
| 46 } | |
| 47 | |
| 48 Future getSuggestions(String pattern, int offsetFromPatternStart) { | |
| 49 return waitForTasksFinished().then((_) { | |
| 50 int offset = testCode.indexOf(pattern) + offsetFromPatternStart; | |
|
scheglov
2014/07/17 21:09:32
Would it be easier to use some special character,
danrubel
2014/07/17 21:38:45
Great suggestion. https://codereview.chromium.org/
| |
| 51 Request request = new Request('0', COMPLETION_GET_SUGGESTIONS); | |
| 52 request.setParameter(FILE, testFile); | |
| 53 request.setParameter(OFFSET, offset); | |
| 54 Response response = handleSuccessfulRequest(request); | |
| 55 completionId = response.getResult(ID); | |
| 56 assertValidId(completionId); | |
| 57 return waitForSuggestions(); | |
| 58 }); | |
| 59 } | |
| 60 | |
| 61 void processNotification(Notification notification) { | |
| 62 if (notification.event == COMPLETION_RESULTS) { | |
| 63 String id = notification.getParameter(ID); | |
| 64 assertValidId(id); | |
| 65 if (id == completionId) { | |
| 66 expect(suggestionsDone, isFalse); | |
| 67 suggestionsDone = notification.getParameter(LAST); | |
| 68 expect(suggestionsDone, isNotNull); | |
| 69 for (Map<String, Object> json in notification.getParameter(RESULTS)) { | |
| 70 expect(json, isNotNull); | |
| 71 suggestions.add(new CompletionSuggestion.fromJson(json)); | |
| 72 } | |
| 73 } | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 @override | |
| 78 void setUp() { | |
| 79 super.setUp(); | |
| 80 createProject(); | |
| 81 handler = new CompletionDomainHandler(server); | |
| 82 } | |
| 83 | |
| 84 Future waitForSuggestions() { | |
| 85 if (suggestionsDone) { | |
| 86 return new Future.value(); | |
| 87 } | |
| 88 return new Future.delayed(Duration.ZERO, waitForSuggestions); | |
| 89 } | |
| 90 | |
| 91 test_suggestions() { | |
| 92 addTestFile(''' | |
| 93 import 'dart:html'; | |
| 94 main() {} | |
| 95 '''); | |
| 96 return getSuggestions('}', 0).then((_) { | |
| 97 assertHasResult('Object'); | |
| 98 assertHasResult('HtmlElement'); | |
| 99 }); | |
| 100 } | |
| 101 } | |
| OLD | NEW |