Chromium Code Reviews| Index: tests/lib/mirrors/invoke_subscript_test.dart |
| diff --git a/tests/lib/mirrors/invoke_subscript_test.dart b/tests/lib/mirrors/invoke_subscript_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..813a41026a4e7cdad87ec35de4b354e0240065e3 |
| --- /dev/null |
| +++ b/tests/lib/mirrors/invoke_subscript_test.dart |
| @@ -0,0 +1,103 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library test.invoke_subscript_test; |
| + |
| +import 'dart:mirrors'; |
| +import 'package:expect/expect.dart'; |
| + |
| +class Super { |
| + inheritedMethod(a, b) => a + b; |
| + staticFunctionInSuper(x) => x; |
| +} |
| + |
| +class Class extends Super { |
| + var field = 'f'; |
| + get getter => 'g'; |
| + set setter(v) => 's'; |
| + method(x, y, z) => '$x-$y-$z'; |
| + methodWithNamed(x, {y, z:'Z'}) => '$x+$y+$z'; |
| + methodWithOptPos(x, [y, z='Z']) => '$x*$y*$z'; |
| + |
| + static var staticField = 'sf'; |
| + static get staticGetter => 'sg'; |
| + static set staticSetter(v) => 'ss'; |
| + static staticFunction(x, y, z) => '$x-$y-$z'; |
| + static staticFunctionWithNamed(x, {y, z:'Z'}) => '$x+$y+$z'; |
| + static staticFunctionWithOptPos(x, [y, z='Z']) => '$x*$y*$z'; |
| + |
| +} |
| + |
| +var toplevelField ='tf'; |
| +get toplevelGetter => 'tg'; |
| +set toplevelSetter(v) => 'ts'; |
| +toplevelFunction(x, y, z) => '$x-$y-$z'; |
| +toplevelFunctionWithNamed(x, {y, z:'Z'}) => '$x+$y+$z'; |
| +toplevelFunctionWithOptPos(x, [y, z='Z']) => '$x*$y*$z'; |
| + |
| +main() { |
|
ahe
2013/10/29 10:25:24
Could you add some tests of what happens for im[#m
rmacnak
2013/10/29 18:03:38
Already have im[#doesntExist].
|
| + InstanceMirror im = reflect(new Class()); |
| + Expect.equals('A-B-C', im[#method]('A', 'B', 'C').reflectee); |
| + Expect.throws(() => im[#method]('A', 'B', 'C', 'D'), |
| + (e) => e is NoSuchMethodError, |
| + 'Wrong arity'); |
| + Expect.equals(7, im[#inheritedMethod](3, 4).reflectee); |
| + Expect.isNull(im[#field]); |
| + Expect.isNull(im[#getter]); |
| + Expect.isNull(im[#setter]); |
| + Expect.isNull(im[#doesntExist]); |
| + Expect.isNull(im[#staticFunction]); |
| + |
| + ClassMirror cm = reflectClass(Class); |
| + Expect.equals('A-B-C', cm[#staticFunction]('A', 'B', 'C').reflectee); |
| + Expect.throws(() => im[#staticFunction]('A', 'B', 'C', 'D'), |
| + (e) => e is NoSuchMethodError, |
| + 'Wrong arity'); |
| + Expect.isNull(cm[#staticField]); |
| + Expect.isNull(cm[#staticGetter]); |
| + Expect.isNull(cm[#staticSetter]); |
| + Expect.isNull(cm[#staticDoesntExist]); |
| + Expect.isNull(cm[#staticFunctionInSuper]); |
| + Expect.isNull(cm[#method]); |
| + |
| + LibraryMirror lm = cm.owner; |
| + Expect.equals('A-B-C', lm[#toplevelFunction]('A', 'B', 'C').reflectee); |
| + Expect.throws(() => im[#toplevelFunction]('A', 'B', 'C', 'D'), |
| + (e) => e is NoSuchMethodError, |
| + 'Wrong arity'); |
| + |
| + Expect.isNull(cm[#toplevelField]); |
| + Expect.isNull(cm[#toplevelGetter]); |
| + Expect.isNull(cm[#toplevelSetter]); |
| + Expect.isNull(cm[#toplevelDoesntExist]); |
| + |
| + // dart2js might stop testing here. |
| + |
| + Expect.equals('A+B+Z', im[#methodWithNamed]('A', y: 'B').reflectee); |
| + Expect.equals('A*B*Z', im[#methodWithOptPos]('A', 'B').reflectee); |
| + Expect.throws(() => im[#methodWithNamed]('A', w: 'D'), |
| + (e) => e is NoSuchMethodError, |
| + 'Wrong arity'); |
| + Expect.throws(() => im[#method](), |
| + (e) => e is NoSuchMethodError, |
| + 'Wrong arity'); |
| + |
| + Expect.equals('A+B+Z', cm[#staticFunctionWithNamed]('A', y: 'B').reflectee); |
| + Expect.equals('A*B*Z', cm[#staticFunctionWithOptPos]('A', 'B').reflectee); |
| + Expect.throws(() => im[#staticFunctionWithNamed]('A', w: 'D'), |
| + (e) => e is NoSuchMethodError, |
| + 'Wrong arity'); |
| + Expect.throws(() => im[#staticFunctionWithOptPos](), |
| + (e) => e is NoSuchMethodError, |
| + 'Wrong arity'); |
| + |
| + Expect.equals('A+B+Z', lm[#toplevelFunctionWithNamed]('A', y: 'B').reflectee); |
| + Expect.equals('A*B*Z', lm[#toplevelFunctionWithOptPos]('A', 'B').reflectee); |
| + Expect.throws(() => im[#toplevelFunctionWithNamed]('A', w: 'D'), |
| + (e) => e is NoSuchMethodError, |
| + 'Wrong arity'); |
| + Expect.throws(() => im[#toplevelFunctionWithOptPos](), |
| + (e) => e is NoSuchMethodError, |
| + 'Wrong arity'); |
| +} |