| 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.analysis.notification.outline; | 5 library test.analysis.notification.outline; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 10 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 expect(location.offset, testCode.indexOf("B(int p);")); | 249 expect(location.offset, testCode.indexOf("B(int p);")); |
| 250 expect(location.length, "B".length); | 250 expect(location.length, "B".length); |
| 251 } | 251 } |
| 252 expect(element.parameters, "(int p)"); | 252 expect(element.parameters, "(int p)"); |
| 253 expect(element.returnType, isNull); | 253 expect(element.returnType, isNull); |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 }); | 256 }); |
| 257 } | 257 } |
| 258 | 258 |
| 259 test_enum() { |
| 260 addTestFile(''' |
| 261 enum MyEnum { |
| 262 A, B, C |
| 263 } |
| 264 '''); |
| 265 return prepareOutline().then((_) { |
| 266 Outline unitOutline = outline; |
| 267 List<Outline> topOutlines = unitOutline.children; |
| 268 expect(topOutlines, hasLength(1)); |
| 269 // MyEnum |
| 270 { |
| 271 Outline outline_MyEnum = topOutlines[0]; |
| 272 Element element_MyEnum = outline_MyEnum.element; |
| 273 expect(element_MyEnum.kind, ElementKind.ENUM); |
| 274 expect(element_MyEnum.name, "MyEnum"); |
| 275 { |
| 276 Location location = element_MyEnum.location; |
| 277 expect(location.offset, testCode.indexOf("MyEnum {")); |
| 278 expect(location.length, 'MyEnum'.length); |
| 279 } |
| 280 expect(element_MyEnum.parameters, null); |
| 281 expect(element_MyEnum.returnType, null); |
| 282 // MyEnum children |
| 283 List<Outline> outlines_MyEnum = outline_MyEnum.children; |
| 284 expect(outlines_MyEnum, hasLength(3)); |
| 285 _isEnumConstant(outlines_MyEnum[0], 'A'); |
| 286 _isEnumConstant(outlines_MyEnum[1], 'B'); |
| 287 _isEnumConstant(outlines_MyEnum[2], 'C'); |
| 288 } |
| 289 }); |
| 290 } |
| 291 |
| 259 /** | 292 /** |
| 260 * Code like this caused NPE in the past. | 293 * Code like this caused NPE in the past. |
| 261 * | 294 * |
| 262 * https://code.google.com/p/dart/issues/detail?id=21373 | 295 * https://code.google.com/p/dart/issues/detail?id=21373 |
| 263 */ | 296 */ |
| 264 test_invalidGetterInConstructor() { | 297 test_invalidGetterInConstructor() { |
| 265 addTestFile(''' | 298 addTestFile(''' |
| 266 class A { | 299 class A { |
| 267 A() { | 300 A() { |
| 268 get badGetter { | 301 get badGetter { |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 { | 786 { |
| 754 Location location = element.location; | 787 Location location = element.location; |
| 755 expect(location.offset, testCode.indexOf("propB(int v) {}")); | 788 expect(location.offset, testCode.indexOf("propB(int v) {}")); |
| 756 expect(location.length, "propB".length); | 789 expect(location.length, "propB".length); |
| 757 } | 790 } |
| 758 expect(element.parameters, "(int v)"); | 791 expect(element.parameters, "(int v)"); |
| 759 expect(element.returnType, ""); | 792 expect(element.returnType, ""); |
| 760 } | 793 } |
| 761 }); | 794 }); |
| 762 } | 795 } |
| 796 |
| 797 void _isEnumConstant(Outline outline, String name) { |
| 798 Element element = outline.element; |
| 799 expect(element.kind, ElementKind.ENUM_CONSTANT); |
| 800 expect(element.name, name); |
| 801 expect(element.parameters, isNull); |
| 802 expect(element.returnType, isNull); |
| 803 } |
| 763 } | 804 } |
| OLD | NEW |