OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, 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.inherited_computer_test; |
| 6 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 8 hide Element, ElementKind; |
| 9 import 'package:analysis_server/src/provisional/completion/completion_dart.dart'
; |
| 10 import 'package:analysis_server/src/services/completion/dart/inherited_contribut
or.dart'; |
| 11 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart' |
| 12 hide DartCompletionContributor; |
| 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 14 import 'package:unittest/unittest.dart'; |
| 15 |
| 16 // import '../../../utils.dart'; |
| 17 import 'dart_completion_contributor_test.dart'; |
| 18 |
| 19 main() { |
| 20 // Revisit this contributor and these tests |
| 21 // once DartChangeBuilder API has solidified. |
| 22 // initializeTestEnvironment(); |
| 23 // defineReflectiveTests(InheritedContributorTest); |
| 24 } |
| 25 |
| 26 @reflectiveTest |
| 27 class InheritedContributorTest extends DartCompletionContributorTest { |
| 28 @override |
| 29 DartCompletionContributor createContributor() { |
| 30 return new InheritedContributor(); |
| 31 } |
| 32 |
| 33 test_fromMultipleSuperclasses() async { |
| 34 addTestSource(r''' |
| 35 class A { |
| 36 A suggested1(int x) => null; |
| 37 B suggested2(String y) => null; |
| 38 } |
| 39 class B extends A { |
| 40 B suggested2(String y) => null; |
| 41 C suggested3([String z]) => null; |
| 42 } |
| 43 class C extends B { |
| 44 sugg^ |
| 45 } |
| 46 '''); |
| 47 await computeSuggestions(); |
| 48 _assertOverride('''@override |
| 49 A suggested1(int x) { |
| 50 // TODO: implement suggested1 |
| 51 return null; |
| 52 }'''); |
| 53 _assertOverride( |
| 54 '''@override\n A suggested1(int x) {\n // TODO: implement suggested1
\n return null;\n }'''); |
| 55 _assertOverride( |
| 56 '''@override\n B suggested2(String y) {\n // TODO: implement suggest
ed2\n return null;\n }'''); |
| 57 _assertOverride( |
| 58 '''@override\n C suggested3([String z]) {\n // TODO: implement sugge
sted3\n return null;\n }'''); |
| 59 } |
| 60 |
| 61 test_fromPart() async { |
| 62 addSource( |
| 63 '/myLib.dart', |
| 64 ''' |
| 65 library myLib; |
| 66 part '$testFile' |
| 67 part '/otherPart.dart' |
| 68 class A { |
| 69 A suggested1(int x) => null; |
| 70 B suggested2(String y) => null; |
| 71 } |
| 72 '''); |
| 73 addSource( |
| 74 '/otherPart.dart', |
| 75 ''' |
| 76 part of myLib; |
| 77 class B extends A { |
| 78 B suggested2(String y) => null; |
| 79 C suggested3([String z]) => null; |
| 80 } |
| 81 '''); |
| 82 addTestSource(r''' |
| 83 part of myLib; |
| 84 class C extends B { |
| 85 sugg^ |
| 86 } |
| 87 '''); |
| 88 // assume information for context.getLibrariesContaining has been cached |
| 89 await computeLibrariesContaining(); |
| 90 await computeSuggestions(); |
| 91 _assertOverride('''@override |
| 92 A suggested1(int x) { |
| 93 // TODO: implement suggested1 |
| 94 return null; |
| 95 }'''); |
| 96 _assertOverride( |
| 97 '''@override\n A suggested1(int x) {\n // TODO: implement suggested1
\n return null;\n }'''); |
| 98 _assertOverride( |
| 99 '''@override\n B suggested2(String y) {\n // TODO: implement suggest
ed2\n return null;\n }'''); |
| 100 _assertOverride( |
| 101 '''@override\n C suggested3([String z]) {\n // TODO: implement sugge
sted3\n return null;\n }'''); |
| 102 } |
| 103 |
| 104 CompletionSuggestion _assertOverride(String completion) { |
| 105 CompletionSuggestion cs = getSuggest( |
| 106 completion: completion, |
| 107 csKind: CompletionSuggestionKind.IDENTIFIER, |
| 108 elemKind: null); |
| 109 if (cs == null) { |
| 110 failedCompletion('expected $completion', suggestions); |
| 111 } |
| 112 expect(cs.kind, equals(CompletionSuggestionKind.IDENTIFIER)); |
| 113 expect(cs.relevance, equals(DART_RELEVANCE_HIGH)); |
| 114 expect(cs.importUri, null); |
| 115 // expect(cs.selectionOffset, equals(completion.length)); |
| 116 // expect(cs.selectionLength, equals(0)); |
| 117 expect(cs.isDeprecated, isFalse); |
| 118 expect(cs.isPotential, isFalse); |
| 119 expect(cs.element, isNotNull); |
| 120 return cs; |
| 121 } |
| 122 } |
OLD | NEW |