| 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.suggestion; | 5 library test.services.completion.suggestion; |
| 6 | 6 |
| 7 import 'package:analysis_services/completion/completion_computer.dart'; | 7 import 'package:analysis_services/completion/completion_computer.dart'; |
| 8 import 'package:analysis_services/src/completion/top_level_computer.dart'; | 8 import 'package:analysis_services/src/completion/top_level_computer.dart'; |
| 9 import 'package:analysis_testing/abstract_single_unit.dart'; | |
| 10 import 'package:analysis_testing/reflective_tests.dart'; | 9 import 'package:analysis_testing/reflective_tests.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 12 | 11 |
| 12 import 'completion_test_util.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; |
| 14 |
| 13 main() { | 15 main() { |
| 14 groupSep = ' | '; | 16 groupSep = ' | '; |
| 15 runReflectiveTests(CompletionComputerTest); | 17 runReflectiveTests(CompletionManagerTest); |
| 18 runReflectiveTests(DartCompletionManagerTest); |
| 16 } | 19 } |
| 17 | 20 |
| 18 @ReflectiveTestCase() | 21 @ReflectiveTestCase() |
| 19 class CompletionComputerTest extends AbstractSingleUnitTest { | 22 class CompletionManagerTest extends AbstractCompletionTest { |
| 20 | 23 |
| 21 test_topLevel() { | 24 test_dart() { |
| 22 CompletionComputer.create(null).then((computers) { | 25 Source source = addSource('/does/not/exist.dart', ''); |
| 23 assertContainsType(computers, TopLevelComputer); | 26 var manager = CompletionManager.create(source, 0, null); |
| 24 expect(computers, hasLength(1)); | 27 expect(manager.runtimeType, DartCompletionManager); |
| 25 }); | |
| 26 } | 28 } |
| 27 | 29 |
| 30 test_html() { |
| 31 Source source = addSource('/does/not/exist.html', ''); |
| 32 var manager = CompletionManager.create(source, 0, null); |
| 33 expect(manager.runtimeType, NoOpCompletionManager); |
| 34 } |
| 35 |
| 36 test_other() { |
| 37 Source source = addSource('/does/not/exist.foo', ''); |
| 38 var manager = CompletionManager.create(source, 0, null); |
| 39 expect(manager.runtimeType, NoOpCompletionManager); |
| 40 } |
| 41 } |
| 42 |
| 43 @ReflectiveTestCase() |
| 44 class DartCompletionManagerTest extends AbstractCompletionTest { |
| 45 |
| 28 /// Assert that the list contains exactly one of the given type | 46 /// Assert that the list contains exactly one of the given type |
| 29 void assertContainsType(List computers, Type type) { | 47 void assertContainsType(List computers, Type type) { |
| 30 int count = 0; | 48 int count = 0; |
| 31 computers.forEach((c) { | 49 computers.forEach((c) { |
| 32 if (c.runtimeType == type) { | 50 if (c.runtimeType == type) { |
| 33 ++count; | 51 ++count; |
| 34 } | 52 } |
| 35 }); | 53 }); |
| 36 if (count != 1) { | 54 if (count != 1) { |
| 37 var msg = new StringBuffer(); | 55 var msg = new StringBuffer(); |
| 38 msg.writeln('Expected $type, but found:'); | 56 msg.writeln('Expected $type, but found:'); |
| 39 computers.forEach((c) { | 57 computers.forEach((c) { |
| 40 msg.writeln(' ${c.runtimeType}'); | 58 msg.writeln(' ${c.runtimeType}'); |
| 41 }); | 59 }); |
| 42 fail(msg.toString()); | 60 fail(msg.toString()); |
| 43 } | 61 } |
| 44 } | 62 } |
| 63 |
| 64 test_topLevel() { |
| 65 Source source = addSource('/does/not/exist.dart', ''); |
| 66 var manager = new DartCompletionManager(source, 0, searchEngine); |
| 67 manager.generate().then((List<CompletionComputer> computers) { |
| 68 assertContainsType(computers, TopLevelComputer); |
| 69 expect(computers, hasLength(1)); |
| 70 }); |
| 71 } |
| 45 } | 72 } |
| OLD | NEW |