Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016, 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 import 'package:analyzer/dart/ast/ast.dart'; | |
| 6 import 'package:analyzer/src/dart/analysis/referenced_names.dart'; | |
| 7 import 'package:test/test.dart'; | |
| 8 import 'package:test_reflective_loader/test_reflective_loader.dart'; | |
| 9 | |
| 10 import '../../../generated/parser_test.dart'; | |
| 11 | |
| 12 main() { | |
| 13 defineReflectiveSuite(() { | |
| 14 defineReflectiveTests(ReferencedNamesBuilderTest); | |
| 15 }); | |
| 16 } | |
| 17 | |
| 18 @reflectiveTest | |
| 19 class ReferencedNamesBuilderTest { | |
|
Brian Wilkerson
2016/11/18 17:55:51
I might be missing something, but it seems to be m
| |
| 20 test_class_constructor() { | |
| 21 Set<String> names = _computeReferencedNames(''' | |
| 22 class U { | |
| 23 U.named(A a, B b) { | |
| 24 C c = null; | |
| 25 } | |
| 26 } | |
| 27 '''); | |
| 28 expect(names, unorderedEquals(['A', 'B', 'C'])); | |
| 29 } | |
| 30 | |
| 31 test_class_field() { | |
| 32 Set<String> names = _computeReferencedNames(''' | |
| 33 class U { | |
| 34 A f = new B(); | |
| 35 } | |
| 36 '''); | |
| 37 expect(names, unorderedEquals(['A', 'B'])); | |
| 38 } | |
| 39 | |
| 40 test_class_getter() { | |
| 41 Set<String> names = _computeReferencedNames(''' | |
| 42 class U { | |
| 43 A get a => new B(); | |
| 44 } | |
| 45 '''); | |
| 46 expect(names, unorderedEquals(['A', 'B'])); | |
| 47 } | |
| 48 | |
| 49 test_class_members() { | |
| 50 Set<String> names = _computeReferencedNames(''' | |
| 51 class U { | |
| 52 int a; | |
| 53 int get b; | |
| 54 set c(_) {} | |
| 55 m(D d) { | |
| 56 a; | |
| 57 b; | |
| 58 c = 1; | |
| 59 m(); | |
| 60 } | |
| 61 } | |
| 62 '''); | |
| 63 expect(names, unorderedEquals(['int', 'D'])); | |
| 64 } | |
| 65 | |
| 66 test_class_members_dontHideQualified() { | |
| 67 Set<String> names = _computeReferencedNames(''' | |
| 68 class U { | |
| 69 int a; | |
| 70 int get b; | |
| 71 set c(_) {} | |
| 72 m(D d) { | |
| 73 d.a; | |
| 74 d.b; | |
| 75 d.c; | |
| 76 } | |
| 77 } | |
| 78 '''); | |
| 79 expect(names, unorderedEquals(['int', 'D', 'a', 'b', 'c'])); | |
| 80 } | |
| 81 | |
| 82 test_class_method() { | |
| 83 Set<String> names = _computeReferencedNames(''' | |
| 84 class U { | |
| 85 A m(B p) { | |
| 86 C v = 0; | |
| 87 } | |
| 88 } | |
| 89 '''); | |
| 90 expect(names, unorderedEquals(['A', 'B', 'C'])); | |
| 91 } | |
| 92 | |
| 93 test_class_method_localVariables() { | |
| 94 Set<String> names = _computeReferencedNames(''' | |
| 95 class U { | |
| 96 A m() { | |
| 97 B b = null; | |
| 98 b; | |
| 99 { | |
| 100 C c = null; | |
| 101 b; | |
| 102 c; | |
| 103 } | |
| 104 d; | |
| 105 } | |
| 106 } | |
| 107 '''); | |
| 108 expect(names, unorderedEquals(['A', 'B', 'C', 'd'])); | |
| 109 } | |
| 110 | |
| 111 test_class_method_parameters() { | |
| 112 Set<String> names = _computeReferencedNames(''' | |
| 113 class U { | |
| 114 m(A a) { | |
| 115 a; | |
| 116 b; | |
| 117 } | |
| 118 } | |
| 119 '''); | |
| 120 expect(names, unorderedEquals(['A', 'b'])); | |
| 121 } | |
| 122 | |
| 123 test_class_method_typeParameters() { | |
| 124 Set<String> names = _computeReferencedNames(''' | |
| 125 class U { | |
| 126 A m<T>(B b, T t) { | |
| 127 C c = 0; | |
| 128 } | |
| 129 } | |
| 130 '''); | |
| 131 expect(names, unorderedEquals(['A', 'B', 'C'])); | |
| 132 } | |
| 133 | |
| 134 test_class_setter() { | |
| 135 Set<String> names = _computeReferencedNames(''' | |
| 136 class U { | |
| 137 set a(A a) { | |
| 138 B b = null; | |
| 139 } | |
| 140 } | |
| 141 '''); | |
| 142 expect(names, unorderedEquals(['A', 'B'])); | |
| 143 } | |
| 144 | |
| 145 test_class_typeParameters() { | |
| 146 Set<String> names = _computeReferencedNames(''' | |
| 147 class U<T> { | |
| 148 T f = new A<T>(); | |
| 149 } | |
| 150 '''); | |
| 151 expect(names, unorderedEquals(['A'])); | |
| 152 } | |
| 153 | |
| 154 test_instantiatedNames_importPrefix() { | |
| 155 Set<String> names = _computeReferencedNames(''' | |
| 156 import 'a.dart' as p1; | |
| 157 import 'b.dart' as p2; | |
| 158 main() { | |
| 159 new p1.A(); | |
| 160 new p1.A.c1(); | |
| 161 new p1.B(); | |
| 162 new p2.C(); | |
| 163 new D(); | |
| 164 new D.c2(); | |
| 165 } | |
| 166 '''); | |
| 167 expect(names, unorderedEquals(['A', 'B', 'C', 'D', 'c1', 'c2'])); | |
| 168 } | |
| 169 | |
| 170 test_localFunction() { | |
| 171 Set<String> names = _computeReferencedNames(''' | |
| 172 f(A a) { | |
| 173 g(B b) {} | |
| 174 } | |
| 175 '''); | |
| 176 expect(names, unorderedEquals(['A', 'B'])); | |
| 177 } | |
| 178 | |
| 179 test_superToSubs_importPrefix() { | |
| 180 Set<String> names = _computeReferencedNames(''' | |
| 181 import 'a.dart' as p1; | |
| 182 import 'b.dart' as p2; | |
| 183 class U extends p1.A with p2.B implements p2.C {} | |
| 184 '''); | |
| 185 expect(names, unorderedEquals(['A', 'B', 'C'])); | |
| 186 } | |
| 187 | |
| 188 test_topLevelVariable() { | |
| 189 Set<String> names = _computeReferencedNames(''' | |
| 190 A v = new B(c); | |
| 191 '''); | |
| 192 expect(names, unorderedEquals(['A', 'B', 'c'])); | |
| 193 } | |
| 194 | |
| 195 test_topLevelVariable_multiple() { | |
| 196 Set<String> names = _computeReferencedNames(''' | |
| 197 A v1 = new B(c), v2 = new D<E>(f); | |
| 198 '''); | |
| 199 expect(names, unorderedEquals(['A', 'B', 'c', 'D', 'E', 'f'])); | |
| 200 } | |
| 201 | |
| 202 test_unit_classTypeAlias() { | |
| 203 Set<String> names = _computeReferencedNames(''' | |
| 204 class U = A with B implements C; | |
| 205 '''); | |
| 206 expect(names, unorderedEquals(['A', 'B', 'C'])); | |
| 207 } | |
| 208 | |
| 209 test_unit_classTypeAlias_typeParameters() { | |
| 210 Set<String> names = _computeReferencedNames(''' | |
| 211 class U<T1, T2 extends D> = A<T1> with B<T2> implements C<T1, T2>; | |
| 212 '''); | |
| 213 expect(names, unorderedEquals(['A', 'B', 'C', 'D'])); | |
| 214 } | |
| 215 | |
| 216 test_unit_function() { | |
| 217 Set<String> names = _computeReferencedNames(''' | |
| 218 A f(B b) { | |
| 219 C c = 0; | |
| 220 } | |
| 221 '''); | |
| 222 expect(names, unorderedEquals(['A', 'B', 'C'])); | |
| 223 } | |
| 224 | |
| 225 test_unit_function_doc() { | |
| 226 Set<String> names = _computeReferencedNames(''' | |
| 227 /** | |
| 228 * Documentation [C.d] reference. | |
| 229 */ | |
| 230 A f(B b) {} | |
| 231 '''); | |
| 232 expect(names, unorderedEquals(['A', 'B', 'C', 'd'])); | |
| 233 } | |
| 234 | |
| 235 test_unit_function_localFunctions() { | |
| 236 Set<String> names = _computeReferencedNames(''' | |
| 237 A f() { | |
| 238 B b = null; | |
| 239 C g() {} | |
| 240 g(); | |
| 241 } | |
| 242 '''); | |
| 243 expect(names, unorderedEquals(['A', 'B', 'C'])); | |
| 244 } | |
| 245 | |
| 246 test_unit_function_localsDontHideQualified() { | |
| 247 Set<String> names = _computeReferencedNames(''' | |
| 248 f(A a, B b) { | |
| 249 var v = 0; | |
| 250 a.v; | |
| 251 a.b; | |
| 252 } | |
| 253 '''); | |
| 254 expect(names, unorderedEquals(['A', 'B', 'v', 'b'])); | |
| 255 } | |
| 256 | |
| 257 test_unit_function_localVariables() { | |
| 258 Set<String> names = _computeReferencedNames(''' | |
| 259 A f() { | |
| 260 B b = null; | |
| 261 b; | |
| 262 { | |
| 263 C c = null; | |
| 264 b; | |
| 265 c; | |
| 266 } | |
| 267 d; | |
| 268 } | |
| 269 '''); | |
| 270 expect(names, unorderedEquals(['A', 'B', 'C', 'd'])); | |
| 271 } | |
| 272 | |
| 273 test_unit_function_parameters() { | |
| 274 Set<String> names = _computeReferencedNames(''' | |
| 275 A f(B b) { | |
| 276 C c = 0; | |
| 277 b; | |
| 278 } | |
| 279 '''); | |
| 280 expect(names, unorderedEquals(['A', 'B', 'C'])); | |
| 281 } | |
| 282 | |
| 283 test_unit_function_typeParameters() { | |
| 284 Set<String> names = _computeReferencedNames(''' | |
| 285 A f<T>(B b, T t) { | |
| 286 C c = 0; | |
| 287 } | |
| 288 '''); | |
| 289 expect(names, unorderedEquals(['A', 'B', 'C'])); | |
| 290 } | |
| 291 | |
| 292 test_unit_functionTypeAlias() { | |
| 293 Set<String> names = _computeReferencedNames(''' | |
| 294 typedef A F(B B, C c(D d)); | |
| 295 '''); | |
| 296 expect(names, unorderedEquals(['A', 'B', 'C', 'D'])); | |
| 297 } | |
| 298 | |
| 299 test_unit_functionTypeAlias_typeParameters() { | |
| 300 Set<String> names = _computeReferencedNames(''' | |
| 301 typedef A F<T>(B b, T t); | |
| 302 '''); | |
| 303 expect(names, unorderedEquals(['A', 'B'])); | |
| 304 } | |
| 305 | |
| 306 test_unit_getter() { | |
| 307 Set<String> names = _computeReferencedNames(''' | |
| 308 A get aaa { | |
| 309 return new B(); | |
| 310 } | |
| 311 '''); | |
| 312 expect(names, unorderedEquals(['A', 'B'])); | |
| 313 } | |
| 314 | |
| 315 test_unit_setter() { | |
| 316 Set<String> names = _computeReferencedNames(''' | |
| 317 set aaa(A a) { | |
| 318 B b = null; | |
| 319 } | |
| 320 '''); | |
| 321 expect(names, unorderedEquals(['A', 'B'])); | |
| 322 } | |
| 323 | |
| 324 Set<String> _computeReferencedNames(String code) { | |
| 325 CompilationUnit unit = | |
| 326 ParserTestCase.parseCompilationUnit2(code, parseGenericMethods: true); | |
| 327 return computeReferencedNames(unit); | |
| 328 } | |
| 329 } | |
| OLD | NEW |