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

Side by Side Diff: test/codegen/language/no_such_method_mock_test.dart

Issue 2158173003: fix #603, support mock objects (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 // Dart test program testing that NoSuchMethod is properly called.
5
6 import "package:expect/expect.dart";
7
8 class Cat {
9 bool eatFood(String food) => true;
10 int scratch(String furniture) => 100;
11 }
12
13 class MockCat implements Cat {
14 dynamic noSuchMethod(Invocation invocation) {
15 return (invocation.positionalArguments[0] as String).isNotEmpty;
16 }
17 }
18
19 void main() {
20 MockCat mock = new MockCat();
21 Expect.isTrue((mock as dynamic).eatFood("food"));
22 Expect.isFalse(mock.eatFood(""));
23
24 // In strong mode this will be a runtime type error:
25 // bool is not an int. VM will fail with noSuchMethod +.
26 Expect.throws(() => mock.scratch("couch") + 0);
27 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698