| 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.dart.local; | 5 library test.services.completion.dart.local; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/services/completion/local_computer.dart'; | 7 import 'package:analysis_server/src/services/completion/local_computer.dart'; |
| 8 import '../../reflective_tests.dart'; | 8 import '../../reflective_tests.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 test_catch() { | 35 test_catch() { |
| 36 addTestSource('class A {a() {try{} on E catch (e) {^}}}'); | 36 addTestSource('class A {a() {try{} on E catch (e) {^}}}'); |
| 37 expect(computeFast(), isTrue); | 37 expect(computeFast(), isTrue); |
| 38 assertSuggestParameter('e', 'E'); | 38 assertSuggestParameter('e', 'E'); |
| 39 } | 39 } |
| 40 | 40 |
| 41 test_catch2() { | 41 test_catch2() { |
| 42 addTestSource('class A {a() {try{} catch (e, s) {^}}}'); | 42 addTestSource('class A {a() {try{} catch (e, s) {^}}}'); |
| 43 expect(computeFast(), isTrue); | 43 expect(computeFast(), isTrue); |
| 44 assertSuggestParameter('e', null); | 44 assertSuggestParameter('e', null); |
| 45 assertSuggestParameter('s', null); | 45 assertSuggestParameter('s', 'StackTrace'); |
| 46 } | 46 } |
| 47 | 47 |
| 48 test_compilationUnit_declarations() { | 48 test_compilationUnit_declarations() { |
| 49 addTestSource('class A {^} class B {} A T;'); | 49 addTestSource('@deprecated class A {^} class _B {} A T;'); |
| 50 expect(computeFast(), isTrue); | 50 expect(computeFast(), isTrue); |
| 51 assertSuggestClass('A'); | 51 var a = assertSuggestClass('A'); |
| 52 assertSuggestClass('B'); | 52 expect(a.element.isDeprecated, isTrue); |
| 53 expect(a.element.isPrivate, isFalse); |
| 54 var b = assertSuggestClass('_B'); |
| 55 expect(b.element.isDeprecated, isFalse); |
| 56 expect(b.element.isPrivate, isTrue); |
| 53 assertSuggestTopLevelVar('T', 'A'); | 57 assertSuggestTopLevelVar('T', 'A'); |
| 54 } | 58 } |
| 55 | 59 |
| 56 test_compilationUnit_directives() { | 60 test_compilationUnit_directives() { |
| 57 addTestSource('import "boo.dart" as x; class A {^}'); | 61 addTestSource('import "boo.dart" as x; class A {^}'); |
| 58 expect(computeFast(), isTrue); | 62 expect(computeFast(), isTrue); |
| 59 assertSuggestLibraryPrefix('x'); | 63 assertSuggestLibraryPrefix('x'); |
| 60 } | 64 } |
| 61 | 65 |
| 62 test_field_name() { | 66 test_field_name() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 76 expect(computeFast(), isTrue); | 80 expect(computeFast(), isTrue); |
| 77 assertSuggestLocalVariable('i', 'int'); | 81 assertSuggestLocalVariable('i', 'int'); |
| 78 } | 82 } |
| 79 | 83 |
| 80 test_forEach() { | 84 test_forEach() { |
| 81 addTestSource('main(args) {for (foo in bar) {^}}'); | 85 addTestSource('main(args) {for (foo in bar) {^}}'); |
| 82 expect(computeFast(), isTrue); | 86 expect(computeFast(), isTrue); |
| 83 assertSuggestLocalVariable('foo', null); | 87 assertSuggestLocalVariable('foo', null); |
| 84 } | 88 } |
| 85 | 89 |
| 90 test_forEach2() { |
| 91 addTestSource('main(args) {for (int foo in bar) {^}}'); |
| 92 expect(computeFast(), isTrue); |
| 93 assertSuggestLocalVariable('foo', 'int'); |
| 94 } |
| 95 |
| 86 test_function() { | 96 test_function() { |
| 87 addTestSource('String foo(List args) {x.then((R b) {^});}'); | 97 addTestSource('String foo(List args) {x.then((R b) {^});}'); |
| 88 expect(computeFast(), isTrue); | 98 expect(computeFast(), isTrue); |
| 89 assertSuggestFunction('foo', 'String'); | 99 var f = assertSuggestFunction('foo', 'String', false); |
| 100 expect(f.element.isPrivate, isFalse); |
| 90 assertSuggestParameter('args', 'List'); | 101 assertSuggestParameter('args', 'List'); |
| 91 assertSuggestParameter('b', 'R'); | 102 assertSuggestParameter('b', 'R'); |
| 92 } | 103 } |
| 93 | 104 |
| 105 test_getters() { |
| 106 addTestSource('class A {@deprecated X get f => 0; Z a() {^} get _g => 1;}'); |
| 107 expect(computeFast(), isTrue); |
| 108 var a = assertSuggestMethod('a', 'A', 'Z'); |
| 109 expect(a.element.isDeprecated, isFalse); |
| 110 expect(a.element.isPrivate, isFalse); |
| 111 var f = assertSuggestGetter('f', 'X'); |
| 112 expect(f.element.isDeprecated, isTrue); |
| 113 expect(f.element.isPrivate, isFalse); |
| 114 var g = assertSuggestGetter('_g', null); |
| 115 expect(g.element.isDeprecated, isFalse); |
| 116 expect(g.element.isPrivate, isTrue); |
| 117 } |
| 118 |
| 94 test_local_name() { | 119 test_local_name() { |
| 95 addTestSource('class A {a() {var f; A ^}}'); | 120 addTestSource('class A {a() {var f; A ^}}'); |
| 96 expect(computeFast(), isTrue); | 121 expect(computeFast(), isTrue); |
| 97 assertNotSuggested('A'); | 122 assertNotSuggested('A'); |
| 98 assertNotSuggested('a'); | 123 assertNotSuggested('a'); |
| 99 assertNotSuggested('f'); | 124 assertNotSuggested('f'); |
| 100 } | 125 } |
| 101 | 126 |
| 102 test_local_name2() { | 127 test_local_name2() { |
| 103 addTestSource('class A {a() {var f; var ^}}'); | 128 addTestSource('class _A {a() {var f; var ^}}'); |
| 104 expect(computeFast(), isTrue); | 129 expect(computeFast(), isTrue); |
| 105 assertNotSuggested('A'); | 130 assertNotSuggested('A'); |
| 106 assertNotSuggested('a'); | 131 assertNotSuggested('a'); |
| 107 assertNotSuggested('f'); | 132 assertNotSuggested('f'); |
| 108 } | 133 } |
| 109 | 134 |
| 110 test_members() { | 135 test_members() { |
| 111 addTestSource('class A {X f; Z a() {^} var g;}'); | 136 addTestSource('class A {@deprecated X f; Z _a() {^} var _g;}'); |
| 112 expect(computeFast(), isTrue); | 137 expect(computeFast(), isTrue); |
| 113 assertSuggestMethodName('a', 'A', 'Z'); | 138 var a = assertSuggestMethod('_a', 'A', 'Z'); |
| 114 assertSuggestField('f', 'A', 'X'); | 139 expect(a.element.isDeprecated, isFalse); |
| 115 assertSuggestField('g', 'A', null); | 140 expect(a.element.isPrivate, isTrue); |
| 141 var f = assertSuggestGetter('f', 'X'); |
| 142 expect(f.element.isDeprecated, isTrue); |
| 143 expect(f.element.isPrivate, isFalse); |
| 144 var g = assertSuggestGetter('_g', null); |
| 145 expect(g.element.isDeprecated, isFalse); |
| 146 expect(g.element.isPrivate, isTrue); |
| 116 } | 147 } |
| 117 | 148 |
| 118 test_methodParam_named() { | 149 test_methodParam_named() { |
| 119 addTestSource('class A {Z a(X x, {y: boo}) {^}}'); | 150 addTestSource('class A {@deprecated Z a(X x, {y: boo}) {^}}'); |
| 120 expect(computeFast(), isTrue); | 151 expect(computeFast(), isTrue); |
| 121 assertSuggestMethodName('a', 'A', 'Z'); | 152 var a = assertSuggestMethod('a', 'A', 'Z'); |
| 153 expect(a.element.isDeprecated, isTrue); |
| 154 expect(a.element.isPrivate, isFalse); |
| 122 assertSuggestParameter('x', 'X'); | 155 assertSuggestParameter('x', 'X'); |
| 123 assertSuggestParameter('y', 'boo'); | 156 assertSuggestParameter('y', null); |
| 124 } | 157 } |
| 125 | 158 |
| 126 test_methodParam_positional() { | 159 test_methodParam_positional() { |
| 127 addTestSource('class A {Z a(X x, [int y=1]) {^}}'); | 160 addTestSource('class A {Z a(X x, [int y=1]) {^}}'); |
| 128 expect(computeFast(), isTrue); | 161 expect(computeFast(), isTrue); |
| 129 assertSuggestMethodName('a', 'A', 'Z'); | 162 assertSuggestMethod('a', 'A', 'Z'); |
| 130 assertSuggestParameter('x', 'X'); | 163 assertSuggestParameter('x', 'X'); |
| 131 assertSuggestParameter('y', 'int'); | 164 assertSuggestParameter('y', 'int'); |
| 132 } | 165 } |
| 133 | 166 |
| 134 test_topLevelVar_name() { | 167 test_topLevelVar_name() { |
| 135 addTestSource('class A {} B ^'); | 168 addTestSource('class A {} B ^'); |
| 136 expect(computeFast(), isTrue); | 169 expect(computeFast(), isTrue); |
| 137 assertNotSuggested('A'); | 170 assertNotSuggested('A'); |
| 138 } | 171 } |
| 139 | 172 |
| 140 test_topLevelVar_name2() { | 173 test_topLevelVar_name2() { |
| 141 addTestSource('class A {} var ^'); | 174 addTestSource('class A {} var ^'); |
| 142 expect(computeFast(), isTrue); | 175 expect(computeFast(), isTrue); |
| 143 assertNotSuggested('A'); | 176 assertNotSuggested('A'); |
| 144 } | 177 } |
| 145 | 178 |
| 146 test_variableDeclaration() { | 179 test_variableDeclaration() { |
| 147 addTestSource('main() {int a = 1, b = 2 + ^;}'); | 180 addTestSource('main() {int a = 1, b = 2 + ^;}'); |
| 148 expect(computeFast(), isTrue); | 181 expect(computeFast(), isTrue); |
| 149 assertSuggestLocalVariable('a', 'int'); | 182 assertSuggestLocalVariable('a', 'int'); |
| 150 assertNotSuggested('b'); | 183 assertNotSuggested('b'); |
| 151 } | 184 } |
| 152 } | 185 } |
| OLD | NEW |