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

Side by Side Diff: tests/lib/mirrors/metadata_test.dart

Issue 22460008: Fix attempt to find metadata of a library with no metadata. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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.metadata_test; 5 library test.metadata_test;
6 6
7 import 'dart:mirrors'; 7 import 'dart:mirrors';
8 8
9 const string = 'a metadata string'; 9 const string = 'a metadata string';
10 10
11 const symbol = const Symbol('symbol'); 11 const symbol = const Symbol('symbol');
12 12
13 const hest = 'hest'; 13 const hest = 'hest';
14 14
15 @symbol @string 15 @symbol @string
16 class MyClass { 16 class MyClass {
17 @hest @hest @symbol 17 @hest @hest @symbol
18 var x; 18 var x;
19 var y; 19 var y;
20 20
21 @string @symbol @string 21 @string @symbol @string
22 myMethod() => 1; 22 myMethod() => 1;
23 myOtherMethod() => 2;
23 } 24 }
24 25
25 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { 26 checkMetadata(DeclarationMirror mirror, List expectedMetadata) {
26 List metadata = mirror.metadata.map((m) => m.reflectee).toList(); 27 List metadata = mirror.metadata.map((m) => m.reflectee).toList();
27 if (metadata == null) { 28 if (metadata == null) {
28 throw 'Null metadata on $mirror'; 29 throw 'Null metadata on $mirror';
29 } 30 }
30 int expectedLength = expectedMetadata.length; 31 int expectedLength = expectedMetadata.length;
31 int actualLength = metadata.length; 32 int actualLength = metadata.length;
32 if (expectedLength != actualLength) { 33 if (expectedLength != actualLength) {
(...skipping 17 matching lines...) Expand all
50 } 51 }
51 52
52 MirrorSystem mirrors = currentMirrorSystem(); 53 MirrorSystem mirrors = currentMirrorSystem();
53 ClassMirror myClassMirror = reflectClass(MyClass); 54 ClassMirror myClassMirror = reflectClass(MyClass);
54 checkMetadata(myClassMirror, [symbol, string]); 55 checkMetadata(myClassMirror, [symbol, string]);
55 LibraryMirror lib = mirrors.findLibrary(const Symbol('test.metadata_test')).fi rst; 56 LibraryMirror lib = mirrors.findLibrary(const Symbol('test.metadata_test')).fi rst;
56 MethodMirror function = lib.functions[const Symbol('main')]; 57 MethodMirror function = lib.functions[const Symbol('main')];
57 checkMetadata(function, [symbol, string, symbol]); 58 checkMetadata(function, [symbol, string, symbol]);
58 MethodMirror method = myClassMirror.methods[const Symbol('myMethod')]; 59 MethodMirror method = myClassMirror.methods[const Symbol('myMethod')];
59 checkMetadata(method, [string, symbol, string]); 60 checkMetadata(method, [string, symbol, string]);
61 method = myClassMirror.methods[const Symbol('myOtherMethod')];
62 checkMetadata(method, []);
60 63
61 VariableMirror xMirror = myClassMirror.variables[const Symbol('x')]; 64 VariableMirror xMirror = myClassMirror.variables[const Symbol('x')];
62 checkMetadata(xMirror, [hest, hest, symbol]); 65 checkMetadata(xMirror, [hest, hest, symbol]);
63 66
64 VariableMirror yMirror = myClassMirror.variables[const Symbol('y')]; 67 VariableMirror yMirror = myClassMirror.variables[const Symbol('y')];
65 checkMetadata(yMirror, []); 68 checkMetadata(yMirror, []);
66 69
67 // TODO(ahe): Test local functions. 70 // TODO(ahe): Test local functions.
68 } 71 }
OLDNEW
« runtime/vm/parser.cc ('K') | « tests/lib/mirrors/library_metadata_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698