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

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

Issue 1510863004: Report compile-time error on disallowed metadata values. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years 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
« no previous file with comments | « tests/compiler/dart2js/mirrors_helper.dart ('k') | tests/lib/lib.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import "package:async_helper/async_helper.dart"; 6 import "package:async_helper/async_helper.dart";
7 import 'package:compiler/src/mirrors/source_mirrors.dart'; 7 import 'package:compiler/src/mirrors/source_mirrors.dart';
8 import 'package:compiler/src/mirrors/mirrors_util.dart'; 8 import 'package:compiler/src/mirrors/mirrors_util.dart';
9 import 'package:compiler/src/mirrors/analyze.dart'; 9 import 'package:compiler/src/mirrors/analyze.dart';
10 import 'package:compiler/src/filenames.dart' 10 import 'package:compiler/src/filenames.dart'
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 var fooMa = fooM.parameters[0]; 162 var fooMa = fooM.parameters[0];
163 Expect.isNotNull(fooMa); 163 Expect.isNotNull(fooMa);
164 Expect.isTrue(fooMa is ParameterMirror); 164 Expect.isTrue(fooMa is ParameterMirror);
165 165
166 ////////////////////////////////////////////////////////////////////////////// 166 //////////////////////////////////////////////////////////////////////////////
167 // Metadata tests 167 // Metadata tests
168 ////////////////////////////////////////////////////////////////////////////// 168 //////////////////////////////////////////////////////////////////////////////
169 169
170 var metadataList = fooClass.metadata; 170 var metadataList = fooClass.metadata;
171 Expect.isNotNull(metadataList); 171 Expect.isNotNull(metadataList);
172 Expect.equals(16, metadataList.length); 172 Expect.equals(14, metadataList.length);
173 var metadataListIndex = 0; 173 var metadataListIndex = 0;
174 var metadata; 174 var metadata;
175 175
176 var dartMirrorsLibrary = system.libraries[DART_MIRRORS_URI]; 176 var dartMirrorsLibrary = system.libraries[DART_MIRRORS_URI];
177 Expect.isNotNull(dartMirrorsLibrary); 177 Expect.isNotNull(dartMirrorsLibrary);
178 var commentType = dartMirrorsLibrary.declarations[#Comment]; 178 var commentType = dartMirrorsLibrary.declarations[#Comment];
179 Expect.isNotNull(commentType); 179 Expect.isNotNull(commentType);
180 180
181 // /// Singleline doc comment. 181 // /// Singleline doc comment.
182 metadata = metadataList[metadataListIndex++]; 182 metadata = metadataList[metadataListIndex++];
183 Expect.isTrue(metadata is InstanceMirror); 183 Expect.isTrue(metadata is InstanceMirror);
184 Expect.isFalse(metadata.hasReflectee); 184 Expect.isFalse(metadata.hasReflectee);
185 Expect.throws(() => metadata.reflectee, (_) => true); 185 Expect.throws(() => metadata.reflectee, (_) => true);
186 Expect.isTrue(metadata is CommentInstanceMirror, 186 Expect.isTrue(metadata is CommentInstanceMirror,
187 "Unexpected metadata: $metadata"); 187 "Unexpected metadata: $metadata");
188 Expect.equals(commentType.originalDeclaration, metadata.type); 188 Expect.equals(commentType.originalDeclaration, metadata.type);
189 Expect.isTrue(metadata.isDocComment); 189 Expect.isTrue(metadata.isDocComment);
190 Expect.stringEquals( 190 Expect.stringEquals(
191 "/// Singleline doc comment.", metadata.text); 191 "/// Singleline doc comment.", metadata.text);
192 Expect.stringEquals( 192 Expect.stringEquals(
193 "Singleline doc comment.", metadata.trimmedText); 193 "Singleline doc comment.", metadata.trimmedText);
194 194
195 // @Metadata 195 // @Metadata(null)
196 metadata = metadataList[metadataListIndex++]; 196 metadata = metadataList[metadataListIndex++];
197 var metadataType = metadata.type;
197 Expect.isTrue(metadata is InstanceMirror); 198 Expect.isTrue(metadata is InstanceMirror);
198 Expect.isFalse(metadata.hasReflectee); 199 Expect.isFalse(metadata.hasReflectee);
199 Expect.throws(() => metadata.reflectee, (_) => true); 200 Expect.throws(() => metadata.reflectee, (_) => true);
200 Expect.isTrue(metadata is TypeInstanceMirror); 201 Expect.isTrue(metadataType.isOriginalDeclaration);
201 var metadataType = metadata.representedType; 202 InstanceMirror data = metadata.getField(#data);
202 Expect.isNotNull(metadataType); 203 Expect.isNotNull(data);
203 Expect.equals(#Metadata, metadataType.simpleName); 204 Expect.isTrue(data.hasReflectee);
204 205 Expect.isNull(data.reflectee);
205 // // This is intentionally the type literal.
206 metadata = metadataList[metadataListIndex++];
207 Expect.isTrue(metadata is InstanceMirror);
208 Expect.isFalse(metadata.hasReflectee);
209 Expect.throws(() => metadata.reflectee, (_) => true);
210 Expect.isTrue(metadata is CommentInstanceMirror);
211 Expect.equals(commentType.originalDeclaration, metadata.type);
212 Expect.isFalse(metadata.isDocComment);
213 Expect.stringEquals(
214 "// This is intentionally the type literal.", metadata.text);
215 Expect.stringEquals(
216 "This is intentionally the type literal.", metadata.trimmedText);
217 206
218 // Singleline comment 1. 207 // Singleline comment 1.
219 metadata = metadataList[metadataListIndex++]; 208 metadata = metadataList[metadataListIndex++];
220 Expect.isTrue(metadata is InstanceMirror); 209 Expect.isTrue(metadata is InstanceMirror);
221 Expect.isFalse(metadata.hasReflectee); 210 Expect.isFalse(metadata.hasReflectee);
222 Expect.throws(() => metadata.reflectee, (_) => true); 211 Expect.throws(() => metadata.reflectee, (_) => true);
223 Expect.isTrue(metadata is CommentInstanceMirror); 212 Expect.isTrue(metadata is CommentInstanceMirror);
224 Expect.equals(commentType.originalDeclaration, metadata.type); 213 Expect.equals(commentType.originalDeclaration, metadata.type);
225 Expect.isFalse(metadata.isDocComment); 214 Expect.isFalse(metadata.isDocComment);
226 Expect.stringEquals( 215 Expect.stringEquals(
227 "// Singleline comment 1.", metadata.text); 216 "// Singleline comment 1.", metadata.text);
228 Expect.stringEquals( 217 Expect.stringEquals(
229 "Singleline comment 1.", metadata.trimmedText); 218 "Singleline comment 1.", metadata.trimmedText);
230 219
231 // Singleline comment 2. 220 // Singleline comment 2.
232 metadata = metadataList[metadataListIndex++]; 221 metadata = metadataList[metadataListIndex++];
233 Expect.isTrue(metadata is InstanceMirror); 222 Expect.isTrue(metadata is InstanceMirror);
234 Expect.isFalse(metadata.hasReflectee); 223 Expect.isFalse(metadata.hasReflectee);
235 Expect.throws(() => metadata.reflectee, (_) => true); 224 Expect.throws(() => metadata.reflectee, (_) => true);
236 Expect.isTrue(metadata is CommentInstanceMirror); 225 Expect.isTrue(metadata is CommentInstanceMirror);
237 Expect.equals(commentType.originalDeclaration, metadata.type); 226 Expect.equals(commentType.originalDeclaration, metadata.type);
238 Expect.isFalse(metadata.isDocComment); 227 Expect.isFalse(metadata.isDocComment);
239 Expect.stringEquals( 228 Expect.stringEquals(
240 "// Singleline comment 2.", metadata.text); 229 "// Singleline comment 2.", metadata.text);
241 Expect.stringEquals( 230 Expect.stringEquals(
242 "Singleline comment 2.", metadata.trimmedText); 231 "Singleline comment 2.", metadata.trimmedText);
243 232
244 // @Metadata(null)
245 metadata = metadataList[metadataListIndex++];
246 Expect.isTrue(metadata is InstanceMirror);
247 Expect.isFalse(metadata.hasReflectee);
248 Expect.throws(() => metadata.reflectee, (_) => true);
249 Expect.equals(metadataType.originalDeclaration, metadata.type);
250 InstanceMirror data = metadata.getField(#data);
251 Expect.isNotNull(data);
252 Expect.isTrue(data.hasReflectee);
253 Expect.isNull(data.reflectee);
254
255 // @Metadata(true) 233 // @Metadata(true)
256 metadata = metadataList[metadataListIndex++]; 234 metadata = metadataList[metadataListIndex++];
257 Expect.isTrue(metadata is InstanceMirror); 235 Expect.isTrue(metadata is InstanceMirror);
258 Expect.isFalse(metadata.hasReflectee); 236 Expect.isFalse(metadata.hasReflectee);
259 Expect.throws(() => metadata.reflectee, (_) => true); 237 Expect.throws(() => metadata.reflectee, (_) => true);
260 Expect.equals(metadataType.originalDeclaration, metadata.type); 238 Expect.equals(metadataType.originalDeclaration, metadata.type);
261 data = metadata.getField(#data); 239 data = metadata.getField(#data);
262 Expect.isNotNull(data); 240 Expect.isNotNull(data);
263 Expect.isTrue(data.hasReflectee); 241 Expect.isTrue(data.hasReflectee);
264 Expect.isTrue(data.reflectee); 242 Expect.isTrue(data.reflectee);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 ////////////////////////////////////////////////////////////////////////////// 369 //////////////////////////////////////////////////////////////////////////////
392 // Location test 370 // Location test
393 ////////////////////////////////////////////////////////////////////////////// 371 //////////////////////////////////////////////////////////////////////////////
394 372
395 var fooClassLocation = fooClass.location; 373 var fooClassLocation = fooClass.location;
396 Expect.isNotNull(fooClassLocation); 374 Expect.isNotNull(fooClassLocation);
397 // Expect the location to start with the first metadata, not including the 375 // Expect the location to start with the first metadata, not including the
398 // leading comment. 376 // leading comment.
399 Expect.equals(376, fooClassLocation.offset, "Unexpected offset"); 377 Expect.equals(376, fooClassLocation.offset, "Unexpected offset");
400 // Expect the location to end with the class body. 378 // Expect the location to end with the class body.
401 Expect.equals(351, fooClassLocation.length, "Unexpected length"); 379 Expect.equals(298, fooClassLocation.length, "Unexpected length");
402 Expect.equals(18, fooClassLocation.line, "Unexpected line"); 380 Expect.equals(18, fooClassLocation.line, "Unexpected line");
403 Expect.equals(1, fooClassLocation.column, "Unexpected column"); 381 Expect.equals(1, fooClassLocation.column, "Unexpected column");
404 382
405 } 383 }
406 384
407 // Testing abstract class Bar: 385 // Testing abstract class Bar:
408 // 386 //
409 // abstract class Bar<E> { 387 // abstract class Bar<E> {
410 // 388 //
411 // } 389 // }
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 Expect.isTrue(privateFactoryConstructor.isPrivate); 965 Expect.isTrue(privateFactoryConstructor.isPrivate);
988 Expect.isFalse(privateFactoryConstructor.isConstConstructor); 966 Expect.isFalse(privateFactoryConstructor.isConstConstructor);
989 Expect.isFalse(privateFactoryConstructor.isRedirectingConstructor); 967 Expect.isFalse(privateFactoryConstructor.isRedirectingConstructor);
990 Expect.isFalse(privateFactoryConstructor.isGenerativeConstructor); 968 Expect.isFalse(privateFactoryConstructor.isGenerativeConstructor);
991 Expect.isTrue(privateFactoryConstructor.isFactoryConstructor); 969 Expect.isTrue(privateFactoryConstructor.isFactoryConstructor);
992 970
993 var metadata = privateClass.metadata; 971 var metadata = privateClass.metadata;
994 Expect.isNotNull(metadata); 972 Expect.isNotNull(metadata);
995 Expect.equals(0, metadata.length); 973 Expect.equals(0, metadata.length);
996 } 974 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mirrors_helper.dart ('k') | tests/lib/lib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698