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

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

Issue 1243503007: fixes #221, initial sync*, async, async* implementation (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 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) 2014, 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
6 import 'package:expect/expect.dart';
7
8 import 'dart:async';
9
10 topLevelFunction() async { }
11
12 Future<int> topLevelWithParameter(int a) async {
13 return 7 + a;
14 }
15
16 topLevelWithParameterWrongType(int a) async {
17 return 7 + a;
18 }
19
20 var what = 'async getter';
21 Future<String> get topLevelGetter async {
22 return 'I want to be an ${what}';
23 }
24
25 class A {
26 static int staticVar = 1;
27
28 static staticMethod(int param) async => staticVar + param;
29 static get staticGetter async => staticVar + 3;
30
31 int _x;
32 A(this._x);
33
34 operator+(A other) async {
35 return new A(_x + other._x);
36 }
37
38 get value => _x;
39 }
40
41 class B {
42 final _y;
43 const B._internal(this._y);
44
45 B() : _y = null;
46 }
47
48
49 main() {
50 var asyncReturn;
51
52 asyncReturn = topLevelFunction();
53 Expect.isTrue(asyncReturn is Future);
54
55 asyncReturn = topLevelWithParameter(4);
56 Expect.isTrue(asyncReturn is Future);
57 asyncReturn.then((int result) => Expect.equals(result, 11));
58
59 asyncReturn = topLevelGetter;
60 Expect.isTrue(asyncReturn is Future);
61 asyncReturn.then((String result) =>
62 Expect.stringEquals(result, 'I want to be an async getter'));
63
64 asyncReturn = A.staticMethod(2);
65 Expect.isTrue(asyncReturn is Future);
66 asyncReturn.then((int result) => Expect.equals(result, 3));
67
68 asyncReturn = A.staticGetter;
69 Expect.isTrue(asyncReturn is Future);
70 asyncReturn.then((int result) => Expect.equals(result, 4));
71
72 A a = new A(13);
73
74 var b = new A(9);
75 asyncReturn = a + b;
76 Expect.isTrue(asyncReturn is Future);
77 asyncReturn.then((A result) => Expect.equals(result.value, 22));
78
79 var foo = 17;
80 bar(int p1, p2) async {
81 var z = 8;
82 return p2 + z + foo;
83 }
84 asyncReturn = bar(1,2);
85 Expect.isTrue(asyncReturn is Future);
86 asyncReturn.then((int result) => Expect.equals(result, 27));
87
88 var moreNesting = (int shadowP1, String p2, num p3) {
89 var z = 3;
90 aa(int shadowP1) async {
91 return foo + z + p3 + shadowP1;
92 }
93 return aa(6);
94 };
95 asyncReturn = moreNesting(1, "ignore", 2);
96 Expect.isTrue(asyncReturn is Future);
97 asyncReturn.then((int result) => Expect.equals(result, 28));
98
99 var checkAsync = (var someFunc) {
100 var toTest = someFunc();
101 Expect.isTrue(toTest is Future);
102 toTest.then((int result) => Expect.equals(result, 4));
103 };
104 checkAsync(() async => 4);
105 }
OLDNEW
« no previous file with comments | « test/codegen/language/async_switch_test.dart ('k') | test/codegen/language/async_this_bound_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698