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

Unified Diff: runtime/tests/vm/dart/isolate_mirror_local_test.dart

Issue 10916252: Implement more of the mirrors library, primarily stuff to do with types. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: runtime/tests/vm/dart/isolate_mirror_local_test.dart
===================================================================
--- runtime/tests/vm/dart/isolate_mirror_local_test.dart (revision 11702)
+++ runtime/tests/vm/dart/isolate_mirror_local_test.dart (working copy)
@@ -4,6 +4,8 @@
//
// Dart test program for checking implemention of MirrorSystem when
// inspecting the current isolate.
+//
+// VMOptions=--enable_type_checks
#library('isolate_mirror_local_test');
@@ -29,7 +31,7 @@
// Top-level getter and setter.
int get myVar() { return 5; }
-int set myVar(x) {}
+void set myVar(x) {}
// This function will be invoked reflectively.
int function(int x) {
@@ -37,11 +39,15 @@
return x + 1;
}
+typedef void FuncType(String a);
+
+FuncType myFunc = null;
+
_stringCompare(String a, String b) => a.compareTo(b);
sort(list) => list.sort(_stringCompare);
String buildMethodString(MethodMirror func) {
- var result = '${func.simpleName}';
+ var result = '${func.simpleName} return(${func.returnType.simpleName})';
if (func.isPrivate) {
result = '$result private';
}
@@ -82,7 +88,7 @@
}
String buildVariableString(VariableMirror variable) {
- var result = '${variable.simpleName}';
+ var result = '${variable.simpleName} type(${variable.type.simpleName})';
if (variable.isPrivate) {
result = '$result private';
}
@@ -122,6 +128,8 @@
List keys = lib_mirror.members.getKeys();
sort(keys);
Expect.equals('['
+ 'FuncType, '
+ 'GenericClass, '
'MyClass, '
'MyException, '
'MyInterface, '
@@ -137,6 +145,7 @@
'main, '
'methodWithError, '
'methodWithException, '
+ 'myFunc, '
'myVar, '
'myVar=, '
'sort, '
@@ -156,6 +165,7 @@
keys = lib_mirror.classes.getKeys();
sort(keys);
Expect.equals('['
+ 'GenericClass, '
'MyClass, '
'MyException, '
'MyInterface, '
@@ -205,49 +215,77 @@
'exit_port, '
'expectedTests, '
'final_global_var, '
- 'global_var]',
+ 'global_var, '
+ 'myFunc]',
'$keys');
ClassMirror cls_mirror = lib_mirror.members['MyClass'];
+ ClassMirror generic_cls_mirror = lib_mirror.members['GenericClass'];
// Test function mirrors.
MethodMirror func = lib_mirror.members['function'];
Expect.isTrue(func is MethodMirror);
- Expect.equals('function toplevel static method', buildMethodString(func));
+ Expect.equals('function return(int) toplevel static method',
+ buildMethodString(func));
func = lib_mirror.members['myVar'];
Expect.isTrue(func is MethodMirror);
- Expect.equals('myVar toplevel static getter', buildMethodString(func));
+ Expect.equals('myVar return(int) toplevel static getter',
+ buildMethodString(func));
func = lib_mirror.members['myVar='];
Expect.isTrue(func is MethodMirror);
- Expect.equals('myVar= toplevel static setter', buildMethodString(func));
+ Expect.equals('myVar= return(void) toplevel static setter',
+ buildMethodString(func));
func = cls_mirror.members['method'];
Expect.isTrue(func is MethodMirror);
- Expect.equals('method method', buildMethodString(func));
+ Expect.equals('method return(int) method', buildMethodString(func));
func = cls_mirror.members['MyClass'];
gbracha 2012/09/12 01:36:40 Is this supposed to find the constructor of MyClas
turnidge 2012/09/12 19:55:20 Ok, reworked the meanings of 'members', 'construct
Expect.isTrue(func is MethodMirror);
- Expect.equals('MyClass constructor', buildMethodString(func));
+ Expect.equals('MyClass return(Dynamic) constructor', buildMethodString(func));
gbracha 2012/09/12 01:36:40 What does it mean for a constructor to return Dyna
turnidge 2012/09/12 19:55:20 I patched up Dart_FunctionReturnType to say the re
func = cls_mirror.members['MyClass.named'];
Expect.isTrue(func is MethodMirror);
- Expect.equals('MyClass.named constructor', buildMethodString(func));
+ Expect.equals('MyClass.named return(Dynamic) constructor',
+ buildMethodString(func));
+ func = generic_cls_mirror.members['method'];
+ Expect.isTrue(func is MethodMirror);
+ Expect.equals('method return(T) method', buildMethodString(func));
+
// Test variable mirrors.
VariableMirror variable = lib_mirror.members['global_var'];
Expect.isTrue(variable is VariableMirror);
- Expect.equals('global_var toplevel static', buildVariableString(variable));
+ Expect.equals('global_var type(int) toplevel static',
+ buildVariableString(variable));
variable = lib_mirror.members['final_global_var'];
Expect.isTrue(variable is VariableMirror);
- Expect.equals('final_global_var toplevel static final',
+ Expect.equals('final_global_var type(int) toplevel static final',
buildVariableString(variable));
variable = cls_mirror.members['value'];
Expect.isTrue(variable is VariableMirror);
- Expect.equals('value final', buildVariableString(variable));
+ Expect.equals('value type(Dynamic) final', buildVariableString(variable));
+
+ // Test type variable mirrors.
+ var type_var = generic_cls_mirror.members['method'].returnType;
+ Expect.isTrue(type_var is TypeVariableMirror);
+ Expect.equals('GenericClass', type_var.owner.simpleName);
+ Expect.equals('Dynamic', type_var.upperBound.simpleName);
+
gbracha 2012/09/12 01:36:40 Actually, the upper bound of a type variable defau
turnidge 2012/09/12 19:55:20 Added a fix in parser.cc for this.
+ // Test typedef mirrors.
+ var typedef_mirror = lib_mirror.members['myFunc'].type;
+ Expect.isTrue(typedef_mirror is TypedefMirror);
+ Expect.equals('isolate_mirror_local_test', typedef_mirror.owner.simpleName);
+
+ // Test function type mirrors.
+ var func_cls_mirror = typedef_mirror.referent;
+ Expect.isTrue(func_cls_mirror is FunctionTypeMirror);
+ Expect.equals('void (dart:core.String)', func_cls_mirror.simpleName);
+ Expect.equals('void', func_cls_mirror.returnType.simpleName);
}
void testLibrariesMap(Map libraries) {
@@ -363,6 +401,12 @@
}
}
+class GenericClass<T> {
+ T method(int arg) {
+ return null;
+ }
+}
+
void testCustomInstanceMirror(InstanceMirror mirror) {
Expect.isTrue(mirror.hasReflectee);
bool saw_exception = false;

Powered by Google App Engine
This is Rietveld 408576698