| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.domain.completion; | 5 library test.domain.completion; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 10 import 'package:analysis_server/src/domain_completion.dart'; | 10 import 'package:analysis_server/src/domain_completion.dart'; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 int nextOffset = content.indexOf('^', completionOffset + 1); | 39 int nextOffset = content.indexOf('^', completionOffset + 1); |
| 40 expect(nextOffset, equals(-1), reason: 'too many ^'); | 40 expect(nextOffset, equals(-1), reason: 'too many ^'); |
| 41 return super.addTestFile( | 41 return super.addTestFile( |
| 42 content.substring(0, completionOffset) | 42 content.substring(0, completionOffset) |
| 43 + content.substring(completionOffset + 1)); | 43 + content.substring(completionOffset + 1)); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void assertHasResult(CompletionSuggestionKind kind, String completion, | 46 void assertHasResult(CompletionSuggestionKind kind, String completion, |
| 47 [CompletionRelevance relevance = CompletionRelevance.DEFAULT, | 47 [CompletionRelevance relevance = CompletionRelevance.DEFAULT, |
| 48 bool isDeprecated = false, bool isPotential = false]) { | 48 bool isDeprecated = false, bool isPotential = false]) { |
| 49 var cs = suggestions.firstWhere((cs) => cs.completion == completion, orElse:
() { | 49 var cs; |
| 50 suggestions.forEach((s) { |
| 51 if (s.completion == completion) { |
| 52 if (cs == null) { |
| 53 cs = s; |
| 54 } else { |
| 55 fail('expected exactly one $completion but found > 1'); |
| 56 } |
| 57 } |
| 58 }); |
| 59 if (cs == null) { |
| 50 var completions = suggestions.map((s) => s.completion).toList(); | 60 var completions = suggestions.map((s) => s.completion).toList(); |
| 51 fail('expected "$completion" but found\n $completions'); | 61 fail('expected "$completion" but found\n $completions'); |
| 52 }); | 62 } |
| 53 expect(cs.kind, equals(kind)); | 63 expect(cs.kind, equals(kind)); |
| 54 expect(cs.relevance, equals(relevance)); | 64 expect(cs.relevance, equals(relevance)); |
| 55 expect(cs.selectionOffset, equals(completion.length)); | 65 expect(cs.selectionOffset, equals(completion.length)); |
| 56 expect(cs.selectionLength, equals(0)); | 66 expect(cs.selectionLength, equals(0)); |
| 57 expect(cs.isDeprecated, equals(isDeprecated)); | 67 expect(cs.isDeprecated, equals(isDeprecated)); |
| 58 expect(cs.isPotential, equals(isPotential)); | 68 expect(cs.isPotential, equals(isPotential)); |
| 59 } | 69 } |
| 60 | 70 |
| 61 void assertNoResult(String completion) { | 71 void assertNoResult(String completion) { |
| 62 if (suggestions.any((cs) => cs.completion == completion)) { | 72 if (suggestions.any((cs) => cs.completion == completion)) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 91 void processNotification(Notification notification) { | 101 void processNotification(Notification notification) { |
| 92 if (notification.event == COMPLETION_RESULTS) { | 102 if (notification.event == COMPLETION_RESULTS) { |
| 93 String id = notification.getParameter(ID); | 103 String id = notification.getParameter(ID); |
| 94 assertValidId(id); | 104 assertValidId(id); |
| 95 if (id == completionId) { | 105 if (id == completionId) { |
| 96 expect(suggestionsDone, isFalse); | 106 expect(suggestionsDone, isFalse); |
| 97 replacementOffset = notification.getParameter(REPLACEMENT_OFFSET); | 107 replacementOffset = notification.getParameter(REPLACEMENT_OFFSET); |
| 98 replacementLength = notification.getParameter(REPLACEMENT_LENGTH); | 108 replacementLength = notification.getParameter(REPLACEMENT_LENGTH); |
| 99 suggestionsDone = notification.getParameter(LAST); | 109 suggestionsDone = notification.getParameter(LAST); |
| 100 expect(suggestionsDone, isNotNull); | 110 expect(suggestionsDone, isNotNull); |
| 111 suggestions = []; |
| 101 for (Map<String, Object> json in notification.getParameter(RESULTS)) { | 112 for (Map<String, Object> json in notification.getParameter(RESULTS)) { |
| 102 expect(json, isNotNull); | 113 expect(json, isNotNull); |
| 103 suggestions.add(new CompletionSuggestion.fromJson(json)); | 114 suggestions.add(new CompletionSuggestion.fromJson(json)); |
| 104 } | 115 } |
| 105 } | 116 } |
| 106 } | 117 } |
| 107 } | 118 } |
| 108 | 119 |
| 109 @override | 120 @override |
| 110 void setUp() { | 121 void setUp() { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 '''); | 185 '''); |
| 175 return getSuggestions().then((_) { | 186 return getSuggestions().then((_) { |
| 176 // expect(replacementOffset, equals(completionOffset - 3)); | 187 // expect(replacementOffset, equals(completionOffset - 3)); |
| 177 // expect(replacementLength, equals(4)); | 188 // expect(replacementLength, equals(4)); |
| 178 assertHasResult(CompletionSuggestionKind.CLASS, 'Object'); | 189 assertHasResult(CompletionSuggestionKind.CLASS, 'Object'); |
| 179 assertHasResult(CompletionSuggestionKind.TOP_LEVEL_VARIABLE, 'test'); | 190 assertHasResult(CompletionSuggestionKind.TOP_LEVEL_VARIABLE, 'test'); |
| 180 assertNoResult('HtmlElement'); | 191 assertNoResult('HtmlElement'); |
| 181 }); | 192 }); |
| 182 } | 193 } |
| 183 } | 194 } |
| OLD | NEW |