| 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.services.completion.toplevel; | 5 library test.services.completion.toplevel; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/services/completion/imported_computer.dart'; | 7 import 'package:analysis_server/src/services/completion/imported_computer.dart'; |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 9 | 9 |
| 10 import '../../reflective_tests.dart'; | 10 import '../../reflective_tests.dart'; |
| 11 import 'completion_test_util.dart'; | 11 import 'completion_test_util.dart'; |
| 12 import 'package:analysis_server/src/protocol.dart'; |
| 13 import 'package:analyzer/src/generated/engine.dart'; |
| 14 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 12 | 15 |
| 13 main() { | 16 main() { |
| 14 groupSep = ' | '; | 17 groupSep = ' | '; |
| 15 runReflectiveTests(ImportedTypeComputerTest); | 18 runReflectiveTests(ImportedTypeComputerTest); |
| 16 } | 19 } |
| 17 | 20 |
| 18 @ReflectiveTestCase() | 21 @ReflectiveTestCase() |
| 19 class ImportedTypeComputerTest extends AbstractSelectorSuggestionTest { | 22 class ImportedTypeComputerTest extends AbstractSelectorSuggestionTest { |
| 20 | 23 |
| 21 @override | 24 @override |
| 22 void setUp() { | 25 void setUpComputer() { |
| 23 super.setUp(); | |
| 24 computer = new ImportedComputer(); | 26 computer = new ImportedComputer(); |
| 25 } | 27 } |
| 28 |
| 29 /** |
| 30 * Assert that the ImportedComputer uses cached results to produce identical |
| 31 * suggestions to the original set of suggestions. |
| 32 */ |
| 33 void assertCachedCompute(_) { |
| 34 expect(request.unit.element, isNotNull); |
| 35 List<CompletionSuggestion> oldSuggestions = request.suggestions; |
| 36 /* |
| 37 * Simulate a source change to flush the cached compilation unit |
| 38 */ |
| 39 ChangeSet changes = new ChangeSet(); |
| 40 changes.addedSource(testSource); |
| 41 context.applyChanges(changes); |
| 42 /* |
| 43 * Calculate a new completion at the same location |
| 44 */ |
| 45 setUpComputer(); |
| 46 request = new DartCompletionRequest( |
| 47 context, |
| 48 searchEngine, |
| 49 testSource, |
| 50 completionOffset, |
| 51 cache); |
| 52 expect(computeFast(), isTrue); |
| 53 expect(request.unit.element, isNull); |
| 54 List<CompletionSuggestion> newSuggestions = request.suggestions; |
| 55 expect(newSuggestions.length, oldSuggestions.length); |
| 56 oldSuggestions.forEach((CompletionSuggestion s) { |
| 57 expect(newSuggestions.contains(s), isTrue); |
| 58 }); |
| 59 } |
| 60 |
| 61 @override |
| 62 test_ArgumentList() { |
| 63 return super.test_ArgumentList().then((_) { |
| 64 expect(request.cache.importKey, "import '/libA.dart';"); |
| 65 }); |
| 66 } |
| 67 |
| 68 @override |
| 69 test_ArgumentList_imported_function() { |
| 70 return super.test_ArgumentList_imported_function().then((_) { |
| 71 expect(request.cache.importKey, "import '/libA.dart';"); |
| 72 }); |
| 73 } |
| 74 |
| 75 @override |
| 76 test_AssignmentExpression_RHS() { |
| 77 return super.test_AssignmentExpression_RHS().then((_) { |
| 78 expect(request.cache.importKey, ''); |
| 79 }); |
| 80 } |
| 81 |
| 82 @override |
| 83 test_Block() { |
| 84 return super.test_Block().then((_) { |
| 85 expect(request.cache.importKey, 'import "/testAB.dart";import "/testCD.dar
t" hide D;import "/testEEF.dart" show EE;import "/testG.dart" as g;'); |
| 86 }); |
| 87 } |
| 26 } | 88 } |
| OLD | NEW |