| 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.invocation; | 5 library test.services.completion.invocation; |
| 6 | 6 |
| 7 | 7 |
| 8 import 'package:analysis_server/src/services/completion/invocation_computer.dart
'; | 8 import 'package:analysis_server/src/services/completion/invocation_computer.dart
'; |
| 9 import '../../reflective_tests.dart'; | 9 import '../../reflective_tests.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 11 | 11 |
| 12 import 'completion_test_util.dart'; | 12 import 'completion_test_util.dart'; |
| 13 | 13 |
| 14 main() { | 14 main() { |
| 15 groupSep = ' | '; | 15 groupSep = ' | '; |
| 16 runReflectiveTests(InvocationComputerTest); | 16 runReflectiveTests(InvocationComputerTest); |
| 17 } | 17 } |
| 18 | 18 |
| 19 @ReflectiveTestCase() | 19 @ReflectiveTestCase() |
| 20 class InvocationComputerTest extends AbstractCompletionTest { | 20 class InvocationComputerTest extends AbstractCompletionTest { |
| 21 | 21 |
| 22 @override | 22 @override |
| 23 void setUp() { | 23 void setUp() { |
| 24 super.setUp(); | 24 super.setUp(); |
| 25 computer = new InvocationComputer(); | 25 computer = new InvocationComputer(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 test_field() { | 28 test_field() { |
| 29 addTestSource('class A {var b; var _c;} main() {A a; a.^}'); | 29 addTestSource('class A {var b; X _c;} class X{} main() {A a; a.^}'); |
| 30 return computeFull().then((_) { | 30 return computeFull().then((_) { |
| 31 assertSuggestField('b'); | 31 assertSuggestField('b', 'A', null); |
| 32 assertSuggestField('_c'); | 32 assertSuggestField('_c', 'A', 'X'); |
| 33 }); | 33 }); |
| 34 } | 34 } |
| 35 | 35 |
| 36 test_field_imported() { | 36 test_field_imported() { |
| 37 addSource('/testB.dart', 'lib B; class X {var y; var _z;}'); | 37 addSource('/testB.dart', 'lib B; class X {M y; var _z;} class M{}'); |
| 38 addTestSource('import "/testB.dart"; main() {X x; x.^}'); | 38 addTestSource('import "/testB.dart"; main() {X x; x.^}'); |
| 39 return computeFull().then((_) { | 39 return computeFull().then((_) { |
| 40 assertSuggestField('y'); | 40 assertSuggestField('y', 'X', 'M'); |
| 41 assertNotSuggested('_z'); | 41 assertNotSuggested('_z'); |
| 42 }); | 42 }); |
| 43 } | 43 } |
| 44 | 44 |
| 45 test_field_superclass() { | 45 test_field_superclass() { |
| 46 addTestSource( | 46 addTestSource( |
| 47 'class A {var b; var _c;} class B extends A {} main() {B b; b.^}'); | 47 'class A {X b; var _c;} class X{} class B extends A {} main() {B b; b.^}
'); |
| 48 return computeFull().then((_) { | 48 return computeFull().then((_) { |
| 49 assertSuggestField('b'); | 49 assertSuggestField('b', 'A', 'X'); |
| 50 assertSuggestField('_c'); | 50 assertSuggestField('_c', 'A', null); |
| 51 }); | 51 }); |
| 52 } | 52 } |
| 53 | 53 |
| 54 test_getter() { | 54 test_getter() { |
| 55 addTestSource( | 55 addTestSource( |
| 56 'class A {A get b => new A();A get _c => new A();} main() {A a; a.^}'); | 56 'class A {X get b => new A();get _c => new A();} class X{} main() {A a;
a.^}'); |
| 57 return computeFull().then((_) { | 57 return computeFull().then((_) { |
| 58 assertSuggestGetter('b'); | 58 assertSuggestGetter('b', 'X'); |
| 59 assertSuggestGetter('_c'); | 59 assertSuggestGetter('_c', null); |
| 60 }); | 60 }); |
| 61 } | 61 } |
| 62 | 62 |
| 63 test_getter_imported() { | 63 test_getter_imported() { |
| 64 addSource( | 64 addSource( |
| 65 '/testB.dart', | 65 '/testB.dart', |
| 66 'lib B; class X {X get y => new X(); X get _z => new X();}'); | 66 'lib B; class S{} class X {S get y => new X(); X get _z => new X();}'); |
| 67 addTestSource('import "/testB.dart"; main() {X x; x.^}'); | 67 addTestSource('import "/testB.dart"; main() {X x; x.^}'); |
| 68 return computeFull().then((_) { | 68 return computeFull().then((_) { |
| 69 assertSuggestGetter('y'); | 69 assertSuggestGetter('y', 'S'); |
| 70 assertNotSuggested('_z'); | 70 assertNotSuggested('_z'); |
| 71 }); | 71 }); |
| 72 } | 72 } |
| 73 | 73 |
| 74 test_getter_interface() { | 74 test_getter_interface() { |
| 75 addTestSource( | 75 addTestSource('''class A {S get b => new A();A get _c => new A();} |
| 76 '''class A {A get b => new A();A get _c => new A();} | 76 class B implements A {S get b => new A();} class S{} |
| 77 class B implements A {A get b => new A();} | |
| 78 main() {B b; b.^}'''); | 77 main() {B b; b.^}'''); |
| 79 return computeFull().then((_) { | 78 return computeFull().then((_) { |
| 80 assertSuggestGetter('b'); | 79 assertSuggestGetter('b', 'S'); |
| 81 assertSuggestGetter('_c'); | 80 assertSuggestGetter('_c', 'A'); |
| 82 }); | 81 }); |
| 83 } | 82 } |
| 84 | 83 |
| 85 test_library_prefix() { | 84 test_library_prefix() { |
| 86 addSource('/testB.dart', 'lib B; class X { }'); | 85 addSource('/testB.dart', 'lib B; class X { }'); |
| 87 addTestSource('import "/testB.dart" as b; main() {b.^}'); | 86 addTestSource('import "/testB.dart" as b; main() {b.^}'); |
| 88 return computeFull().then((_) { | 87 return computeFull().then((_) { |
| 89 assertSuggestClass('X'); | 88 assertSuggestClass('X'); |
| 90 }); | 89 }); |
| 91 } | 90 } |
| 92 | 91 |
| 93 test_method() { | 92 test_method() { |
| 94 addTestSource('class A {b(X x) {} _c(X x) {}} main() {A a; a.^}'); | 93 addTestSource('class S{} class A {b(X x) {} S _c(X x) {}} main() {A a; a.^}'
); |
| 95 return computeFull().then((_) { | 94 return computeFull().then((_) { |
| 96 assertSuggestMethod('b'); | 95 assertSuggestMethod('b', 'A', null); |
| 97 assertSuggestMethod('_c'); | 96 assertSuggestMethod('_c', 'A', 'S'); |
| 98 }); | 97 }); |
| 99 } | 98 } |
| 100 | 99 |
| 101 test_method_imported() { | 100 test_method_imported() { |
| 102 addSource('/testB.dart', 'lib B; class X {y(X x) {} _z(X x) {}}'); | 101 addSource('/testB.dart', 'lib B; class X {T y(X x) {} _z(X x) {}} class T{}'
); |
| 103 addTestSource('import "/testB.dart"; main() {X x; x.^}'); | 102 addTestSource('import "/testB.dart"; main() {X x; x.^}'); |
| 104 return computeFull().then((_) { | 103 return computeFull().then((_) { |
| 105 assertSuggestMethod('y'); | 104 assertSuggestMethod('y', 'X', 'T'); |
| 106 assertNotSuggested('_z'); | 105 assertNotSuggested('_z'); |
| 107 }); | 106 }); |
| 108 } | 107 } |
| 109 | 108 |
| 110 test_method_imported_mixin() { | 109 test_method_imported_mixin() { |
| 111 addSource('/testB.dart', 'lib B; class X {y(X x) {} _z(X x) {}}'); | 110 addSource('/testB.dart', 'lib B; class X {T y(X x) {} _z(X x) {}} class T{}'
); |
| 112 addTestSource('''import "/testB.dart"; | 111 addTestSource('''import "/testB.dart"; |
| 113 class A extends Object with X {} | 112 class A extends Object with X {} |
| 114 main() {A a; a.^}'''); | 113 main() {A a; a.^}'''); |
| 115 return computeFull().then((_) { | 114 return computeFull().then((_) { |
| 116 assertSuggestMethod('y'); | 115 assertSuggestMethod('y', 'X', 'T'); |
| 117 assertNotSuggested('_z'); | 116 assertNotSuggested('_z'); |
| 118 }); | 117 }); |
| 119 } | 118 } |
| 120 | 119 |
| 121 test_setter() { | 120 test_setter() { |
| 122 addTestSource('class A {set b(X x) {} set _c(X x) {}} main() {A a; a.^}'); | 121 addTestSource('class A {set b(X x) {} set _c(X x) {}} main() {A a; a.^}'); |
| 123 return computeFull().then((_) { | 122 return computeFull().then((_) { |
| 124 assertSuggestSetter('b'); | 123 assertSuggestSetter('b'); |
| 125 assertSuggestSetter('_c'); | 124 assertSuggestSetter('_c'); |
| 126 }); | 125 }); |
| 127 } | 126 } |
| 128 | 127 |
| 129 test_setter_imported() { | 128 test_setter_imported() { |
| 130 addSource('/testB.dart', 'lib B; class X {set y(X x) {} set _z(X x) {}}'); | 129 addSource('/testB.dart', 'lib B; class X {set y(X x) {} set _z(X x) {}}'); |
| 131 addTestSource('import "/testB.dart"; main() {X x; x.^}'); | 130 addTestSource('import "/testB.dart"; main() {X x; x.^}'); |
| 132 return computeFull().then((_) { | 131 return computeFull().then((_) { |
| 133 assertSuggestSetter('y'); | 132 assertSuggestSetter('y'); |
| 134 assertNotSuggested('_z'); | 133 assertNotSuggested('_z'); |
| 135 }); | 134 }); |
| 136 } | 135 } |
| 137 } | 136 } |
| OLD | NEW |