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

Side by Side Diff: tests/corelib/apply3_test.dart

Issue 2978013002: Migrate test block 1 to Dart 2.0. (Closed)
Patch Set: rebase to repatched status/utilities Created 3 years, 5 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 unified diff | Download patch
« no previous file with comments | « tests/corelib/apply2_test.dart ('k') | tests/corelib/apply4_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Test [Function.apply] on user-defined classes that implement [noSuchMethod].
6
7 import "package:expect/expect.dart";
8 import 'dart:mirrors';
9
10 class F {
11 call([p1]) => "call";
12 noSuchMethod(Invocation invocation) => "NSM";
13 }
14
15 class G {
16 call() => '42';
17 noSuchMethod(Invocation invocation) => invocation;
18 }
19
20 class H {
21 call(required, {a}) => required + a;
22 }
23
24 main() {
25 Expect.equals('call', Function.apply(new F(), []));
26 Expect.equals('call', Function.apply(new F(), [1]));
27 Expect.equals('NSM', Function.apply(new F(), [1, 2]));
28 Expect.equals('NSM', Function.apply(new F(), [1, 2, 3]));
29
30 var symbol = const Symbol('a');
31 var requiredParameters = [1];
32 var optionalParameters = new Map()..[symbol] = 42;
33 Invocation i =
34 Function.apply(new G(), requiredParameters, optionalParameters);
35
36 Expect.equals(const Symbol('call'), i.memberName);
37 Expect.listEquals(requiredParameters, i.positionalArguments);
38 Expect.mapEquals(optionalParameters, i.namedArguments);
39 Expect.isTrue(i.isMethod);
40 Expect.isFalse(i.isGetter);
41 Expect.isFalse(i.isSetter);
42 Expect.isFalse(i.isAccessor);
43
44 // Check that changing the passed list and map for parameters does
45 // not affect [i].
46 requiredParameters[0] = 42;
47 optionalParameters[symbol] = 12;
48 Expect.listEquals([1], i.positionalArguments);
49 Expect.mapEquals(new Map()..[symbol] = 42, i.namedArguments);
50
51 // Check that using [i] for invocation yields the same [Invocation]
52 // object.
53 var mirror = reflect(new G());
54 Invocation other = mirror.delegate(i);
55 Expect.equals(i.memberName, other.memberName);
56 Expect.listEquals(i.positionalArguments, other.positionalArguments);
57 Expect.mapEquals(i.namedArguments, other.namedArguments);
58 Expect.equals(i.isMethod, other.isMethod);
59 Expect.equals(i.isGetter, other.isGetter);
60 Expect.equals(i.isSetter, other.isSetter);
61 Expect.equals(i.isAccessor, other.isAccessor);
62
63 // Test that [i] can be used to hit an existing method.
64 Expect.equals(43, new H().call(1, a: 42));
65 Expect.equals(43, Function.apply(new H(), [1], new Map()..[symbol] = 42));
66 mirror = reflect(new H());
67 Expect.equals(43, mirror.delegate(i));
68 Expect.equals(43, mirror.delegate(other));
69 }
OLDNEW
« no previous file with comments | « tests/corelib/apply2_test.dart ('k') | tests/corelib/apply4_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698