| 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.integration.completion.get.suggestions; | 5 library test.integration.completion.get.suggestions; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'package:analysis_server/src/protocol.dart'; |
| 8 | |
| 9 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 10 | 9 |
| 11 import '../../reflective_tests.dart'; | 10 import '../../reflective_tests.dart'; |
| 12 import '../integration_tests.dart'; | 11 import '../integration_tests.dart'; |
| 13 | 12 |
| 14 main() { | 13 main() { |
| 15 runReflectiveTests(Test); | 14 runReflectiveTests(Test); |
| 16 } | 15 } |
| 17 | 16 |
| 18 @reflectiveTest | 17 @reflectiveTest |
| 19 class Test extends AbstractAnalysisServerIntegrationTest { | 18 class Test extends AbstractAnalysisServerIntegrationTest { |
| 20 fail_test_getSuggestions_string_var() { | 19 String path; |
| 21 // See dartbug.com/20188 | 20 String content; |
| 22 String pathname = sourcePath('test.dart'); | 21 int completionOffset; |
| 23 String text = r''' | 22 |
| 24 var test = ''; | 23 void setTestSource(String relPath, String content) { |
| 24 path = sourcePath(relPath); |
| 25 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once'); |
| 26 completionOffset = content.indexOf('^'); |
| 27 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); |
| 28 int nextOffset = content.indexOf('^', completionOffset + 1); |
| 29 expect(nextOffset, equals(-1), reason: 'too many ^'); |
| 30 this.content = content.substring(0, completionOffset) + |
| 31 content.substring(completionOffset + 1); |
| 32 } |
| 33 |
| 34 test_getSuggestions() async { |
| 35 setTestSource('test.dart', r''' |
| 36 String test = ''; |
| 25 main() { | 37 main() { |
| 26 test. | 38 test.^ |
| 27 } | 39 } |
| 28 '''; | 40 '''); |
| 29 writeFile(pathname, text); | 41 writeFile(path, content); |
| 30 standardAnalysisSetup(); | 42 await standardAnalysisSetup(); |
| 43 await analysisFinished; |
| 44 CompletionGetSuggestionsResult result = |
| 45 await sendCompletionGetSuggestions(path, completionOffset); |
| 46 String completionId = result.id; |
| 47 CompletionResultsParams param = await onCompletionResults.firstWhere( |
| 48 (CompletionResultsParams param) => |
| 49 param.id == completionId && param.isLast); |
| 50 expect(param.replacementOffset, completionOffset); |
| 51 expect(param.replacementLength, 0); |
| 52 param.results.firstWhere( |
| 53 (CompletionSuggestion suggestion) => suggestion.completion == 'length'); |
| 54 } |
| 31 | 55 |
| 32 return analysisFinished.then((_) { | 56 test_getSuggestions_onlyOverlay() async { |
| 33 return sendCompletionGetSuggestions( | 57 setTestSource('test.dart', r''' |
| 34 pathname, text.indexOf('test.') + 'test.'.length).then((result) { | 58 String test = ''; |
| 35 // Since the feature doesn't work yet, just pause for a second to | 59 main() { |
| 36 // collect the output of the analysis server, and then stop the test. | 60 test.^ |
| 37 // TODO(paulberry): finish writing the integration test once the feature | 61 } |
| 38 // it more complete. | 62 '''); |
| 39 return new Future.delayed(new Duration(seconds: 1), () { | 63 // Create an overlay but do not write the file to "disk" |
| 40 fail('test not completed yet'); | 64 // writeFile(pathname, text); |
| 41 }); | 65 await standardAnalysisSetup(); |
| 42 }); | 66 await sendAnalysisUpdateContent({path: new AddContentOverlay(content)}); |
| 67 await analysisFinished; |
| 68 CompletionGetSuggestionsResult result = |
| 69 await sendCompletionGetSuggestions(path, completionOffset); |
| 70 String completionId = result.id; |
| 71 CompletionResultsParams param = await onCompletionResults.firstWhere( |
| 72 (CompletionResultsParams param) => |
| 73 param.id == completionId && param.isLast); |
| 74 expect(param.replacementOffset, completionOffset); |
| 75 expect(param.replacementLength, 0); |
| 76 param.results.firstWhere( |
| 77 (CompletionSuggestion suggestion) => suggestion.completion == 'length'); |
| 78 } |
| 79 |
| 80 test_getSuggestions_onlyOverlay_noWait() async { |
| 81 setTestSource('test.dart', r''' |
| 82 String test = ''; |
| 83 main() { |
| 84 test.^ |
| 85 } |
| 86 '''); |
| 87 // Create an overlay but do not write the file to "disk" |
| 88 // writeFile(pathname, text); |
| 89 // Don't wait for any results except the completion notifications |
| 90 standardAnalysisSetup(subscribeStatus: false); |
| 91 sendAnalysisUpdateContent({path: new AddContentOverlay(content)}); |
| 92 sendCompletionGetSuggestions(path, completionOffset); |
| 93 CompletionResultsParams param = await onCompletionResults |
| 94 .firstWhere((CompletionResultsParams param) => param.isLast); |
| 95 expect(param.replacementOffset, completionOffset); |
| 96 expect(param.replacementLength, 0); |
| 97 param.results.firstWhere( |
| 98 (CompletionSuggestion suggestion) => suggestion.completion == 'length'); |
| 99 } |
| 100 |
| 101 test_getSuggestions_sourceMissing_noWait() { |
| 102 path = sourcePath('does_not_exist.dart'); |
| 103 // Do not write the file to "disk" |
| 104 // writeFile(pathname, text); |
| 105 // Don't wait for any results except the completion notifications |
| 106 standardAnalysisSetup(subscribeStatus: false); |
| 107 // Missing file and no overlay |
| 108 //sendAnalysisUpdateContent({path: new AddContentOverlay(content)}); |
| 109 var errorToken = 'exception from server'; |
| 110 return sendCompletionGetSuggestions(path, 0).catchError((e) { |
| 111 // Exception expected |
| 112 return errorToken; |
| 113 }).then((result) { |
| 114 expect(result, same(errorToken)); |
| 43 }); | 115 }); |
| 44 } | 116 } |
| 45 | |
| 46 test_placeholder() { | |
| 47 // The unit test framework freaks out if there are no tests, so this is a | |
| 48 // placeholder until we have a passing test. | |
| 49 // TODO(paulberry): remove this. | |
| 50 } | |
| 51 } | 117 } |
| OLD | NEW |