Files
sdk/tests/lib_2/mirrors/delegate_class_test.dart
T
Ben Konyi 64105ee014 Migrated test block 219 to Dart 2.0.
No major changes. Some tests that rely on noSuchMethod needed to have
some 'var's changed to 'dynamic's.

BUG=
R=rnystrom@google.com

Review-Url: https://codereview.chromium.org/3003123002 .
2017-08-30 07:51:59 -07:00

51 lines
1.3 KiB
Dart

// Copyright (c) 2015, 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.delegate_class;
import 'dart:mirrors';
import 'package:expect/expect.dart';
class C {
static method(a, b, c) => "$a-$b-$c";
static methodWithNamed(a, {b: 'B', c}) => "$a-$b-$c";
static methodWithOpt(a, [b, c = 'C']) => "$a-$b-$c";
static get getter => 'g';
static set setter(x) {
field = x * 2;
}
static var field;
}
class Proxy {
var targetMirror;
Proxy(this.targetMirror);
noSuchMethod(invocation) => targetMirror.delegate(invocation);
}
main() {
dynamic proxy = new Proxy(reflectClass(C));
var result;
Expect.equals('X-Y-Z', proxy.method('X', 'Y', 'Z'));
Expect.equals('X-B-null', proxy.methodWithNamed('X'));
Expect.equals('X-Y-null', proxy.methodWithNamed('X', b: 'Y'));
Expect.equals('X-Y-Z', proxy.methodWithNamed('X', b: 'Y', c: 'Z'));
Expect.equals('X-null-C', proxy.methodWithOpt('X'));
Expect.equals('X-Y-C', proxy.methodWithOpt('X', 'Y'));
Expect.equals('X-Y-Z', proxy.methodWithOpt('X', 'Y', 'Z'));
Expect.equals('g', proxy.getter);
Expect.equals(5, proxy.setter = 5);
Expect.equals(10, proxy.field);
Expect.equals(5, proxy.field = 5);
Expect.equals(5, proxy.field);
}