dart-sdk/tests/lib/mirrors/delegate_call_through_getter_test.dart
Ryan Macnak 00b2e580a3 [test] Fork mirrors tests.
Bug: https://github.com/dart-lang/sdk/issues/40045
Change-Id: I597259b38684de87016f1e136723d24f4ac05420
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132440
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2020-01-22 18:46:23 +00:00

47 lines
1.4 KiB
Dart

// 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_call_through_getter;
import 'dart:mirrors';
import 'package:expect/expect.dart';
class FakeFunctionCall {
call(x, y) => '1 $x $y';
}
class FakeFunctionNSM {
noSuchMethod(msg) => msg.positionalArguments.join(', ');
}
class C {
get fakeFunctionCall => new FakeFunctionCall();
get fakeFunctionNSM => new FakeFunctionNSM();
get closure => (x, y) => '2 $this $x $y';
get closureOpt => (x, y, [z, w]) => '3 $this $x $y $z $w';
get closureNamed => (x, y, {z, w}) => '4 $this $x $y $z $w';
get notAClosure => 'Not a closure';
noSuchMethod(msg) => 'DNU';
toString() => 'C';
}
class Forwarder {
dynamic noSuchMethod(Invocation msg) => reflect(new C()).delegate(msg);
}
main() {
dynamic f = new Forwarder();
Expect.equals('1 5 6', f.fakeFunctionCall(5, 6));
Expect.equals('7, 8', f.fakeFunctionNSM(7, 8));
Expect.equals('2 C 9 10', f.closure(9, 10));
Expect.equals('3 C 11 12 13 null', f.closureOpt(11, 12, 13));
Expect.equals('4 C 14 15 null 16', f.closureNamed(14, 15, w: 16));
Expect.equals('DNU', f.doesNotExist(17, 18));
Expect.throwsNoSuchMethodError(() => f.closure('wrong arity'));
Expect.throwsNoSuchMethodError(() => f.notAClosure());
}