Chromium Code Reviews| Index: tests/lib/mirrors/redirecting_factory_test.dart |
| =================================================================== |
| --- tests/lib/mirrors/redirecting_factory_test.dart (revision 0) |
| +++ tests/lib/mirrors/redirecting_factory_test.dart (revision 0) |
| @@ -0,0 +1,83 @@ |
| +// 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. |
| + |
| +import "dart:mirrors"; |
| +import "package:expect/expect.dart"; |
| +import "stringify.dart"; |
| + |
| +class Class<T> { |
| + final field; |
| + Class(this.field); |
| + |
| + factory Class.factoryNoOptional(a, b) => new Class<T>(a - b); |
| + factory Class.redirectingFactoryNoOptional(a, b) = Class.factoryNoOptional; |
| + |
| + factory Class.factoryUnnamedOptional(a, [b = 42]) => new Class<T>(a - b); |
| + factory Class.redirectingFactoryUnnamedOptional(a, [b]) = |
| + Class.factoryUnnamedOptional; |
| + |
| + factory Class.factoryNamedOptional(a, {b: 0}) { |
| + return new Class<T>(a - b); |
| + } |
| + |
| + factory Class.redirectingFactoryNamedOptional(a, {b: 42}) = |
| + Class.factoryNamedOptional; |
| + |
| + factory Class.factoryMoreNamedOptional(a, {b: 0, c: 2}) { |
| + return new Class<T>(a - b - c); |
| + } |
| + |
| + factory Class.redirectingFactoryMoreNamedOptional(a, {b: 42}) = |
| + Class.factoryMoreNamedOptional; |
| + |
| + factory Class.factoryMoreUnnamedOptional(a, [b = 0, c = 2]) { |
| + return new Class<T>(a - b - c); |
| + } |
| + |
| + factory Class.redirectingFactoryMoreUnnamedOptional(a, [b = 42]) = |
| + Class.factoryMoreUnnamedOptional; |
| +} |
| + |
| +main() { |
| + var classMirror = reflectClass(Class); |
| + |
| + var instanceMirror = classMirror.newInstance(const Symbol(''), [2]); |
| + Expect.equals(2, instanceMirror.reflectee.field); |
| + |
| + instanceMirror = classMirror.newInstance( |
| + const Symbol('redirectingFactoryNoOptional'), [8, 6]); |
| + Expect.equals(2, instanceMirror.reflectee.field); |
| + |
| + instanceMirror = classMirror.newInstance( |
| + const Symbol('redirectingFactoryUnnamedOptional'), [43, 1]); |
| + Expect.equals(42, instanceMirror.reflectee.field); |
| + |
| + instanceMirror = classMirror.newInstance( |
| + const Symbol('redirectingFactoryMoreUnnamedOptional'), [43, 1]); |
| + Expect.equals(40, instanceMirror.reflectee.field); |
| + |
| + // Currently not implemented in dart2js. |
|
ahe
2013/09/17 10:06:03
bool isDart2js = false;
isDart2js = true; /// 01:
ngeoffray
2013/09/17 12:02:24
Done.
|
| + if (false) { |
| + instanceMirror = classMirror.newInstance( |
| + const Symbol('redirectingFactoryUnnamedOptional'), [43]); |
| + Expect.equals(1, instanceMirror.reflectee.field); |
| + |
| + instanceMirror = classMirror.newInstance( |
| + const Symbol('redirectingFactoryNamedOptional'), [43]); |
| + Expect.equals(1, instanceMirror.reflectee.field); |
| + |
| + instanceMirror = classMirror.newInstance( |
| + const Symbol('redirectingFactoryNamedOptional'), |
| + [43], |
| + new Map()..[const Symbol('b')] = 1); |
| + Expect.equals(42, instanceMirror.reflectee.field); |
| + |
| + instanceMirror = classMirror.newInstance( |
| + const Symbol('redirectingFactoryMoreNamedOptional'), |
| + [43], |
| + new Map()..[const Symbol('b')] = 1); |
| + Expect.equals(40, instanceMirror.reflectee.field); |
| + } |
| +} |
| + |