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

Side by Side Diff: tests/corelib_strong/dynamic_nosuchmethod_test.dart

Issue 2987793002: Migrate test block 7 to Dart 2.0. (Closed)
Patch Set: Final review comment, dropping static multitest Created 3 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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 import "package:expect/expect.dart";
6 import 'dart:mirrors';
7
8 // Test that noSuchMethod calls behave as expected for dynamic object invocation s.
9 class BaseClass {
10 final dynamic finalField = "final!";
11
12 baz() => "baz!!";
13 get bla => (() => "bla!!");
14 }
15
16 class ReturnInvocationName extends BaseClass {
17 var _bar;
18
19 ReturnInvocationName(this._bar);
20
21 noSuchMethod(Invocation invocation) {
22 return MirrorSystem.getName(invocation.memberName);
23 }
24
25 bar() {
26 return _bar;
27 }
28 }
29
30 class Foo {}
31
32 main() {
33 dynamic x = new ReturnInvocationName(42);
34 Expect.equals('final!', x.finalField);
35
36 // https://github.com/dart-lang/sdk/issues/28363
37 // Expect.throws(() => x.finalField = "foo",
38 // (e) => e is NoSuchMethodError);
39 Expect.equals('final!', x.finalField);
40
41 Expect.equals('_prototype', x._prototype);
42 Expect.equals('_prototype', x._prototype());
43
44 Expect.equals('prototype', x.prototype);
45 Expect.equals('prototype', x.prototype());
46
47 Expect.equals('constructor', x.constructor);
48 Expect.equals('constructor', x.constructor());
49
50 Expect.equals('__proto__', x.__proto__);
51 Expect.equals('__proto__', x.__proto__);
52
53 Expect.equals(42, x.bar());
54 Expect.equals(42, (x.bar)());
55
56 Expect.equals('unary-', -x);
57 Expect.equals('+', x + 42);
58 Expect.equals('[]', x[4]);
59
60 // Verify that noSuchMethod errors are triggered even when the JS object
61 // happens to have a matching member name.
62 dynamic f = new Foo();
63 Expect.throws(() => f.prototype, (e) => e is NoSuchMethodError);
64 Expect.throws(() => f.prototype(), (e) => e is NoSuchMethodError);
65 Expect.throws(() => f.prototype = 42, (e) => e is NoSuchMethodError);
66
67 Expect.throws(() => f.constructor, (e) => e is NoSuchMethodError);
68 Expect.throws(() => f.constructor(), (e) => e is NoSuchMethodError);
69 Expect.throws(() => f.constructor = 42, (e) => e is NoSuchMethodError);
70
71 Expect.throws(() => f.__proto__, (e) => e is NoSuchMethodError);
72
73 // These are valid JS properties but not Dart methods.
74 Expect.throws(() => f.toLocaleString, (e) => e is NoSuchMethodError);
75
76 Expect.throws(() => f.hasOwnProperty, (e) => e is NoSuchMethodError);
77 }
OLDNEW
« no previous file with comments | « tests/corelib_strong/duration_test.dart ('k') | tests/corelib_strong/error_stack_trace1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698