OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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.src.task.strong_mode_test; | 5 library test.src.task.strong_mode_test; |
6 | 6 |
7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
10 import 'package:analyzer/src/task/dart.dart'; | 10 import 'package:analyzer/src/task/dart.dart'; |
11 import 'package:analyzer/src/task/strong_mode.dart'; | 11 import 'package:analyzer/src/task/strong_mode.dart'; |
12 import 'package:analyzer/task/dart.dart'; | 12 import 'package:analyzer/task/dart.dart'; |
13 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
14 | 14 |
15 import '../../reflective_tests.dart'; | 15 import '../../reflective_tests.dart'; |
16 import '../../utils.dart'; | 16 import '../../utils.dart'; |
17 import '../context/abstract_context.dart'; | 17 import '../context/abstract_context.dart'; |
18 | 18 |
19 main() { | 19 main() { |
20 initializeTestEnvironment(); | 20 initializeTestEnvironment(); |
21 runReflectiveTests(InferrenceFinderTest); | |
22 runReflectiveTests(InstanceMemberInferrerTest); | 21 runReflectiveTests(InstanceMemberInferrerTest); |
23 runReflectiveTests(VariableGathererTest); | 22 runReflectiveTests(VariableGathererTest); |
24 } | 23 } |
25 | 24 |
26 @reflectiveTest | 25 @reflectiveTest |
27 class InferrenceFinderTest extends AbstractContextTest { | |
28 void test_creation() { | |
29 InferrenceFinder finder = new InferrenceFinder(); | |
30 expect(finder, isNotNull); | |
31 expect(finder.classes, isEmpty); | |
32 expect(finder.staticVariables, isEmpty); | |
33 } | |
34 | |
35 void test_visit() { | |
36 Source source = addSource( | |
37 '/test.dart', | |
38 r''' | |
39 const c = 1; | |
40 final f = ''; | |
41 var v = const A(); | |
42 int i; | |
43 class A { | |
44 static final fa = 0; | |
45 static int fi; | |
46 const A(); | |
47 } | |
48 class B extends A { | |
49 static const cb = 1; | |
50 static vb = 0; | |
51 const ci = 2; | |
52 final fi = ''; | |
53 var vi; | |
54 } | |
55 class C = Object with A; | |
56 typedef int F(int x); | |
57 '''); | |
58 LibrarySpecificUnit librarySpecificUnit = | |
59 new LibrarySpecificUnit(source, source); | |
60 computeResult(librarySpecificUnit, RESOLVED_UNIT5); | |
61 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | |
62 InferrenceFinder finder = new InferrenceFinder(); | |
63 unit.accept(finder); | |
64 expect(finder.classes, hasLength(3)); | |
65 expect(finder.staticVariables, hasLength(6)); | |
66 } | |
67 } | |
68 | |
69 @reflectiveTest | |
70 class InstanceMemberInferrerTest extends AbstractContextTest { | 26 class InstanceMemberInferrerTest extends AbstractContextTest { |
71 InstanceMemberInferrer get createInferrer => | 27 InstanceMemberInferrer get createInferrer => |
72 new InstanceMemberInferrer(context.typeProvider); | 28 new InstanceMemberInferrer(context.typeProvider); |
73 | 29 |
74 /** | 30 /** |
75 * Add a source with the given [content] and return the result of resolving | 31 * Add a source with the given [content] and return the result of resolving |
76 * the source. | 32 * the source. |
77 */ | 33 */ |
78 CompilationUnitElement resolve(String content) { | 34 CompilationUnitElement resolve(String content) { |
79 Source source = addSource('/test.dart', content); | 35 Source source = addSource('/test.dart', content); |
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 } | 901 } |
946 } | 902 } |
947 } | 903 } |
948 '''); | 904 '''); |
949 CompilationUnit unit = context.resolveCompilationUnit2(source, source); | 905 CompilationUnit unit = context.resolveCompilationUnit2(source, source); |
950 VariableGatherer gatherer = new VariableGatherer(filter); | 906 VariableGatherer gatherer = new VariableGatherer(filter); |
951 unit.accept(gatherer); | 907 unit.accept(gatherer); |
952 return gatherer.results; | 908 return gatherer.results; |
953 } | 909 } |
954 } | 910 } |
OLD | NEW |