| 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.services.completion.toplevel; |
| 6 |
| 7 import 'package:analysis_services/completion/completion_suggestion.dart'; |
| 8 import 'package:analysis_services/completion/top_level_computer.dart'; |
| 9 import 'package:analysis_services/index/index.dart'; |
| 10 import 'package:analysis_services/index/local_memory_index.dart'; |
| 11 import 'package:analysis_services/src/search/search_engine.dart'; |
| 12 import 'package:analysis_testing/abstract_single_unit.dart'; |
| 13 import 'package:analysis_testing/reflective_tests.dart'; |
| 14 import 'package:unittest/unittest.dart'; |
| 15 import 'dart:async'; |
| 16 |
| 17 main() { |
| 18 groupSep = ' | '; |
| 19 runReflectiveTests(TopLevelComputerTest); |
| 20 } |
| 21 |
| 22 @ReflectiveTestCase() |
| 23 class TopLevelComputerTest extends AbstractSingleUnitTest { |
| 24 Index index; |
| 25 SearchEngineImpl searchEngine; |
| 26 TopLevelComputer computer; |
| 27 List<CompletionSuggestion> suggestions; |
| 28 |
| 29 test_class() { |
| 30 addTestUnit('class B {boolean v;}'); |
| 31 return compute().then((_) { |
| 32 assertHasResult(CompletionSuggestionKind.CLASS, 'B'); |
| 33 assertNoResult('v'); |
| 34 }); |
| 35 } |
| 36 |
| 37 void addTestUnit(String code) { |
| 38 resolveTestUnit(code); |
| 39 index.indexUnit(context, testUnit); |
| 40 } |
| 41 |
| 42 void assertHasResult(CompletionSuggestionKind kind, String completion, |
| 43 [CompletionRelevance relevance = CompletionRelevance.DEFAULT, |
| 44 bool isDeprecated = false, bool isPotential = false]) { |
| 45 var cs = suggestions.firstWhere((cs) => cs.completion == completion, orElse:
() { |
| 46 var completions = suggestions.map((s) => s.completion).toList(); |
| 47 fail('expected "$completion" but found\n $completions'); |
| 48 }); |
| 49 expect(cs.kind, equals(kind)); |
| 50 expect(cs.relevance, equals(relevance)); |
| 51 expect(cs.selectionOffset, equals(completion.length)); |
| 52 expect(cs.selectionLength, equals(0)); |
| 53 expect(cs.isDeprecated, equals(isDeprecated)); |
| 54 expect(cs.isPotential, equals(isPotential)); |
| 55 } |
| 56 |
| 57 void assertNoResult(String completion) { |
| 58 if (suggestions.any((cs) => cs.completion == completion)) { |
| 59 fail('did not expect completion: $completion'); |
| 60 } |
| 61 } |
| 62 |
| 63 Future compute() { |
| 64 return computer.compute().then((List<CompletionSuggestion> results) { |
| 65 this.suggestions = results; |
| 66 }); |
| 67 } |
| 68 |
| 69 @override |
| 70 void setUp() { |
| 71 super.setUp(); |
| 72 index = createLocalMemoryIndex(); |
| 73 searchEngine = new SearchEngineImpl(index); |
| 74 computer = new TopLevelComputer(searchEngine); |
| 75 verifyNoTestUnitErrors = false; |
| 76 } |
| 77 } |
| OLD | NEW |