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 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.
| |
| 49 return waitForTasksFinished().then((_) { | |
| 50 Request request = new Request('0', COMPLETION_GET_SUGGESTIONS); | |
| 51 request.setParameter(FILE, testFile); | |
| 52 request.setParameter(OFFSET, offset); | |
| 53 Response response = handleSuccessfulRequest(request); | |
| 54 completionId = response.getResult(ID); | |
| 55 assertValidId(completionId); | |
| 56 return waitForSuggestions(); | |
| 57 }); | |
| 58 } | |
| 59 | |
| 60 void processNotification(Notification notification) { | |
| 61 if (notification.event == COMPLETION_RESULTS) { | |
| 62 String id = notification.getParameter(ID); | |
| 63 assertValidId(id); | |
| 64 if (id == completionId) { | |
| 65 expect(suggestionsDone, isFalse); | |
| 66 suggestionsDone = notification.getParameter(LAST); | |
| 67 expect(suggestionsDone, isNotNull); | |
| 68 for (Map<String, Object> json in notification.getParameter(RESULTS)) { | |
| 69 expect(json, isNotNull); | |
| 70 suggestions.add(new CompletionSuggestion.fromJson(json)); | |
| 71 } | |
| 72 } | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 @override | |
| 77 void setUp() { | |
| 78 super.setUp(); | |
| 79 createProject(); | |
| 80 handler = new CompletionDomainHandler(server); | |
| 81 } | |
| 82 | |
| 83 Future waitForSuggestions() { | |
| 84 if (suggestionsDone) { | |
| 85 return new Future.value(); | |
| 86 } | |
| 87 return new Future.delayed(Duration.ZERO, waitForSuggestions); | |
| 88 } | |
| 89 | |
| 90 test_suggestions() { | |
| 91 addTestFile(''' | |
| 92 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
| |
| 93 main() {} | |
| 94 '''); | |
| 95 return getSuggestions('}', 0).then((_) { | |
| 96 assertHasResult('Object'); | |
| 97 assertHasResult('HtmlElement'); | |
| 98 }); | |
| 99 } | |
| 100 } | |
| OLD | NEW |