Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: tests/compiler/dart2js/metadata_test.dart

Issue 1383503002: Add Resolution and Parsing interfaces for computeType, ensureResolved and parseNode. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add TODOs. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 import 'package:async_helper/async_helper.dart'; 5 import 'package:async_helper/async_helper.dart';
6 import 'package:compiler/src/constants/values.dart' 6 import 'package:compiler/src/constants/values.dart'
7 show PrimitiveConstantValue; 7 show PrimitiveConstantValue;
8 import 'package:expect/expect.dart'; 8 import 'package:expect/expect.dart';
9 import 'compiler_helper.dart'; 9 import 'compiler_helper.dart';
10 import 'package:compiler/src/parser/partial_elements.dart' show 10 import 'package:compiler/src/parser/partial_elements.dart' show
(...skipping 18 matching lines...) Expand all
29 var source1 = """const native = 'xyz'; 29 var source1 = """const native = 'xyz';
30 @native 30 @native
31 $declaration 31 $declaration
32 main() {}"""; 32 main() {}""";
33 33
34 compileAndCheck(source1, name, (compiler, element) { 34 compileAndCheck(source1, name, (compiler, element) {
35 compiler.enqueuer.resolution.queueIsClosed = false; 35 compiler.enqueuer.resolution.queueIsClosed = false;
36 Expect.equals(1, element.metadata.length, 36 Expect.equals(1, element.metadata.length,
37 'Unexpected metadata count on $element.'); 37 'Unexpected metadata count on $element.');
38 PartialMetadataAnnotation annotation = element.metadata.first; 38 PartialMetadataAnnotation annotation = element.metadata.first;
39 annotation.ensureResolved(compiler); 39 annotation.ensureResolved(compiler.resolution);
40 PrimitiveConstantValue value = 40 PrimitiveConstantValue value =
41 compiler.constants.getConstantValue(annotation.constant); 41 compiler.constants.getConstantValue(annotation.constant);
42 Expect.stringEquals('xyz', value.primitiveValue.slowToString()); 42 Expect.stringEquals('xyz', value.primitiveValue.slowToString());
43 43
44 checkPosition(annotation, annotation.cachedNode, source1, compiler); 44 checkPosition(annotation, annotation.cachedNode, source1, compiler);
45 }); 45 });
46 46
47 // Ensure that each repeated annotation has a unique instance of 47 // Ensure that each repeated annotation has a unique instance of
48 // [MetadataAnnotation]. 48 // [MetadataAnnotation].
49 var source2 = """const native = 'xyz'; 49 var source2 = """const native = 'xyz';
50 @native @native 50 @native @native
51 $declaration 51 $declaration
52 main() {}"""; 52 main() {}""";
53 53
54 compileAndCheck(source2, name, (compiler, element) { 54 compileAndCheck(source2, name, (compiler, element) {
55 compiler.enqueuer.resolution.queueIsClosed = false; 55 compiler.enqueuer.resolution.queueIsClosed = false;
56 Expect.equals(2, element.metadata.length); 56 Expect.equals(2, element.metadata.length);
57 PartialMetadataAnnotation annotation1 = element.metadata.elementAt(0); 57 PartialMetadataAnnotation annotation1 = element.metadata.elementAt(0);
58 PartialMetadataAnnotation annotation2 = element.metadata.elementAt(1); 58 PartialMetadataAnnotation annotation2 = element.metadata.elementAt(1);
59 annotation1.ensureResolved(compiler); 59 annotation1.ensureResolved(compiler.resolution);
60 annotation2.ensureResolved(compiler); 60 annotation2.ensureResolved(compiler.resolution);
61 Expect.isFalse(identical(annotation1, annotation2), 61 Expect.isFalse(identical(annotation1, annotation2),
62 'expected unique instances'); 62 'expected unique instances');
63 Expect.notEquals(annotation1, annotation2, 'expected unequal instances'); 63 Expect.notEquals(annotation1, annotation2, 'expected unequal instances');
64 PrimitiveConstantValue value1 = 64 PrimitiveConstantValue value1 =
65 compiler.constants.getConstantValue(annotation1.constant); 65 compiler.constants.getConstantValue(annotation1.constant);
66 PrimitiveConstantValue value2 = 66 PrimitiveConstantValue value2 =
67 compiler.constants.getConstantValue(annotation2.constant); 67 compiler.constants.getConstantValue(annotation2.constant);
68 Expect.identical(value1, value2, 'expected same compile-time constant'); 68 Expect.identical(value1, value2, 'expected same compile-time constant');
69 Expect.stringEquals('xyz', value1.primitiveValue.slowToString()); 69 Expect.stringEquals('xyz', value1.primitiveValue.slowToString());
70 Expect.stringEquals('xyz', value2.primitiveValue.slowToString()); 70 Expect.stringEquals('xyz', value2.primitiveValue.slowToString());
71 71
72 checkPosition(annotation1, annotation1.cachedNode, source2, compiler); 72 checkPosition(annotation1, annotation1.cachedNode, source2, compiler);
73 checkPosition(annotation2, annotation2.cachedNode, source2, compiler); 73 checkPosition(annotation2, annotation2.cachedNode, source2, compiler);
74 }); 74 });
75 75
76 if (isTopLevelOnly) return; 76 if (isTopLevelOnly) return;
77 77
78 // Ensure that a compile-time constant can be resolved from an 78 // Ensure that a compile-time constant can be resolved from an
79 // annotation. 79 // annotation.
80 var source3 = """const native = 'xyz'; 80 var source3 = """const native = 'xyz';
81 class Foo { 81 class Foo {
82 @native 82 @native
83 $declaration 83 $declaration
84 } 84 }
85 main() {}"""; 85 main() {}""";
86 86
87 compileAndCheck(source3, 'Foo', (compiler, element) { 87 compileAndCheck(source3, 'Foo', (compiler, element) {
88 compiler.enqueuer.resolution.queueIsClosed = false; 88 compiler.enqueuer.resolution.queueIsClosed = false;
89 Expect.equals(0, element.metadata.length); 89 Expect.equals(0, element.metadata.length);
90 element.ensureResolved(compiler); 90 element.ensureResolved(compiler.resolution);
91 Expect.equals(0, element.metadata.length); 91 Expect.equals(0, element.metadata.length);
92 element = element.lookupLocalMember(name); 92 element = element.lookupLocalMember(name);
93 Expect.equals(1, element.metadata.length); 93 Expect.equals(1, element.metadata.length);
94 PartialMetadataAnnotation annotation = element.metadata.first; 94 PartialMetadataAnnotation annotation = element.metadata.first;
95 annotation.ensureResolved(compiler); 95 annotation.ensureResolved(compiler.resolution);
96 PrimitiveConstantValue value = 96 PrimitiveConstantValue value =
97 compiler.constants.getConstantValue(annotation.constant); 97 compiler.constants.getConstantValue(annotation.constant);
98 Expect.stringEquals('xyz', value.primitiveValue.slowToString()); 98 Expect.stringEquals('xyz', value.primitiveValue.slowToString());
99 99
100 checkPosition(annotation, annotation.cachedNode, source3, compiler); 100 checkPosition(annotation, annotation.cachedNode, source3, compiler);
101 }); 101 });
102 102
103 // Ensure that each repeated annotation has a unique instance of 103 // Ensure that each repeated annotation has a unique instance of
104 // [MetadataAnnotation]. 104 // [MetadataAnnotation].
105 var source4 = """const native = 'xyz'; 105 var source4 = """const native = 'xyz';
106 class Foo { 106 class Foo {
107 @native @native 107 @native @native
108 $declaration 108 $declaration
109 } 109 }
110 main() {}"""; 110 main() {}""";
111 111
112 compileAndCheck(source4, 'Foo', (compiler, element) { 112 compileAndCheck(source4, 'Foo', (compiler, element) {
113 compiler.enqueuer.resolution.queueIsClosed = false; 113 compiler.enqueuer.resolution.queueIsClosed = false;
114 Expect.equals(0, element.metadata.length); 114 Expect.equals(0, element.metadata.length);
115 element.ensureResolved(compiler); 115 element.ensureResolved(compiler.resolution);
116 Expect.equals(0, element.metadata.length); 116 Expect.equals(0, element.metadata.length);
117 element = element.lookupLocalMember(name); 117 element = element.lookupLocalMember(name);
118 Expect.equals(2, element.metadata.length); 118 Expect.equals(2, element.metadata.length);
119 PartialMetadataAnnotation annotation1 = element.metadata.elementAt(0); 119 PartialMetadataAnnotation annotation1 = element.metadata.elementAt(0);
120 PartialMetadataAnnotation annotation2 = element.metadata.elementAt(1); 120 PartialMetadataAnnotation annotation2 = element.metadata.elementAt(1);
121 annotation1.ensureResolved(compiler); 121 annotation1.ensureResolved(compiler.resolution);
122 annotation2.ensureResolved(compiler); 122 annotation2.ensureResolved(compiler.resolution);
123 Expect.isFalse(identical(annotation1, annotation2), 123 Expect.isFalse(identical(annotation1, annotation2),
124 'expected unique instances'); 124 'expected unique instances');
125 Expect.notEquals(annotation1, annotation2, 'expected unequal instances'); 125 Expect.notEquals(annotation1, annotation2, 'expected unequal instances');
126 PrimitiveConstantValue value1 = 126 PrimitiveConstantValue value1 =
127 compiler.constants.getConstantValue(annotation1.constant); 127 compiler.constants.getConstantValue(annotation1.constant);
128 PrimitiveConstantValue value2 = 128 PrimitiveConstantValue value2 =
129 compiler.constants.getConstantValue(annotation2.constant); 129 compiler.constants.getConstantValue(annotation2.constant);
130 Expect.identical(value1, value2, 'expected same compile-time constant'); 130 Expect.identical(value1, value2, 'expected same compile-time constant');
131 Expect.stringEquals('xyz', value1.primitiveValue.slowToString()); 131 Expect.stringEquals('xyz', value1.primitiveValue.slowToString());
132 Expect.stringEquals('xyz', value2.primitiveValue.slowToString()); 132 Expect.stringEquals('xyz', value2.primitiveValue.slowToString());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 asyncTest(() => compiler.runCompiler(uri).then((_) { 168 asyncTest(() => compiler.runCompiler(uri).then((_) {
169 compiler.enqueuer.resolution.queueIsClosed = false; 169 compiler.enqueuer.resolution.queueIsClosed = false;
170 LibraryElement element = compiler.libraryLoader.lookupLibrary(uri); 170 LibraryElement element = compiler.libraryLoader.lookupLibrary(uri);
171 Expect.isNotNull(element, 'Cannot find $uri'); 171 Expect.isNotNull(element, 'Cannot find $uri');
172 172
173 List<MetadataAnnotation> metadata = extractMetadata(element); 173 List<MetadataAnnotation> metadata = extractMetadata(element);
174 Expect.equals(1, metadata.length); 174 Expect.equals(1, metadata.length);
175 175
176 PartialMetadataAnnotation annotation = metadata.first; 176 PartialMetadataAnnotation annotation = metadata.first;
177 annotation.ensureResolved(compiler); 177 annotation.ensureResolved(compiler.resolution);
178 PrimitiveConstantValue value = 178 PrimitiveConstantValue value =
179 compiler.constants.getConstantValue(annotation.constant); 179 compiler.constants.getConstantValue(annotation.constant);
180 Expect.stringEquals('xyz', value.primitiveValue.slowToString()); 180 Expect.stringEquals('xyz', value.primitiveValue.slowToString());
181 181
182 checkPosition(annotation, annotation.cachedNode, source, compiler); 182 checkPosition(annotation, annotation.cachedNode, source, compiler);
183 })); 183 }));
184 } 184 }
185 185
186 var source; 186 var source;
187 187
(...skipping 28 matching lines...) Expand all
216 compileAndCheckLibrary(source, 216 compileAndCheckLibrary(source,
217 (e) => e.compilationUnits.first.partTag.metadata); 217 (e) => e.compilationUnits.first.partTag.metadata);
218 } 218 }
219 219
220 void main() { 220 void main() {
221 testClassMetadata(); 221 testClassMetadata();
222 testTopLevelMethodMetadata(); 222 testTopLevelMethodMetadata();
223 testTopLevelFieldMetadata(); 223 testTopLevelFieldMetadata();
224 testLibraryTags(); 224 testLibraryTags();
225 } 225 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/least_upper_bound_test.dart ('k') | tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698