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

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: add test 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
« no previous file with comments | « test/browser/language_tests.js ('k') | test/codegen_expected/language/flatten_test_01_multi.js » ('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) 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
20 class MockCat2 extends MockCat {
21 // this apparently works.
22 noSuchMethod(_);
23 }
24
25 class MockCat3 extends MockCat2 implements Cat {
26 bool eatFood(String food, {double amount});
27 int scratch(String furniture, [String furniture2]);
28
29 dynamic noSuchMethod(Invocation invocation) {
30 return (invocation.positionalArguments[0] as String).isNotEmpty &&
31 invocation.namedArguments[#amount] > 0.5;
32 }
33 }
34
35
36 class MockWithGenerics {
37 /*=T*/ doStuff/*<T>*/(/*=T*/ t);
38
39 noSuchMethod(i) => i.positionalArguments[0] + 100;
40 }
41
42
43 void main() {
44 MockCat mock = new MockCat();
45 Expect.isTrue((mock as dynamic).eatFood("cat food"));
46 Expect.isFalse(mock.eatFood(""));
47
48 // In strong mode this will be a runtime type error:
49 // bool is not an int. VM will fail with noSuchMethod +.
50 Expect.throws(() => mock.scratch("couch") + 0);
51
52 var mock2 = new MockCat2();
53 Expect.isTrue(mock2.eatFood("cat food"));
54
55 var mock3 = new MockCat3();
56 Expect.isTrue(mock3.eatFood("cat food", amount: 0.9));
57 Expect.isFalse(mock3.eatFood("cat food", amount: 0.3));
58
59 var g = new MockWithGenerics();
60 Expect.equals(g.doStuff(42), 142);
61 Expect.throws(() => g.doStuff('hi'));
62 }
OLDNEW
« no previous file with comments | « test/browser/language_tests.js ('k') | test/codegen_expected/language/flatten_test_01_multi.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698