OLD | NEW |
---|---|
(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 // VMOptions=--enable_async | |
6 | |
7 import 'package:expect/expect.dart'; | |
8 | |
9 import 'dart:async'; | |
10 | |
11 int globalVariable = 1; | |
12 int topLevelFoo(int param) => 1; | |
13 int get topLevelGetter => globalVariable; | |
14 int set topLevelSetter(val) { | |
15 globalVariable = val; | |
16 } | |
17 | |
18 class C { | |
19 static int staticField = 1; | |
20 static int get staticGetter => staticField; | |
21 static int set staticSetter(val) { | |
22 staticField = val; | |
23 } | |
24 static int staticFoo(int param) => param; | |
25 | |
26 int field = 1; | |
27 int get getter => field; | |
28 int set setter(val) { | |
29 field = val; | |
30 } | |
31 int foo(int param) => param; | |
32 } | |
33 | |
34 dummy() => 1; | |
35 | |
36 staticMembers() async { | |
37 var a = C.staticField + await dummy(); | |
38 Expect.equals(a, 2); | |
39 var f = (C.staticField = 1) + await dummy(); | |
40 Expect.equals(f, 2); | |
41 var b = C.staticGetter + await dummy(); | |
42 Expect.equals(b, 2); | |
43 var c = (C.staticSetter = 1) + await dummy(); | |
44 Expect.equals(c, 2); | |
45 var d = C.staticFoo(2) + await dummy(); | |
46 Expect.equals(d, 3); | |
47 var e = C.staticField + | |
48 C.staticGetter + | |
49 (C.staticSetter = 1) + | |
50 C.staticFoo(1) + | |
51 await dummy(); | |
52 Expect.equals(e, 5); | |
53 } | |
54 | |
55 topLevelMembers() async { | |
56 var a = globalVariable + await dummy(); | |
57 Expect.equals(a, 2); | |
58 var b = topLevelGetter + await dummy(); | |
59 Expect.equals(b, 2); | |
60 var c = (topLevelSetter = 1) + await dummy(); | |
61 Expect.equals(c, 2); | |
62 var d = topLevelFoo(1) + await dummy(); | |
63 Expect.equals(d, 2); | |
64 var e = globalVariable + | |
65 topLevelGetter + | |
66 (topLevelSetter = 1) + | |
67 topLevelFoo(1) + | |
68 await dummy(); | |
69 Expect.equals(e, 5); | |
70 } | |
71 | |
72 instanceMembers() async { | |
73 var inst = new C(); | |
74 var a = inst.field + await dummy(); | |
75 Expect.equals(a, 2); | |
76 var b = inst.getter + await dummy(); | |
77 Expect.equals(b, 2); | |
78 var c = (inst.setter = 1) + await dummy(); | |
79 Expect.equals(c, 2); | |
80 var d = inst.foo(1) + await dummy(); | |
81 Expect.equals(d, 2); | |
82 var e = inst.field + | |
83 inst.getter + | |
84 (inst.setter = 1) + | |
85 inst.foo(1) + | |
86 await dummy(); | |
87 Expect.equals(e, 5); | |
88 } | |
89 | |
90 others() async { | |
91 var a = "${globalVariable} ${await dummy()} " + await "someString"; | |
92 Expect.equals(a, "1 1 someString"); | |
93 try { | |
94 var c = new C(); | |
95 var d = c.nooooo() + await bar(); | |
96 } catch (e) {} | |
97 var cnt = 2; | |
98 var b = [1,2,3]; | |
99 b[cnt] = await dummy(); | |
100 Expect.equals(b[cnt], 1); | |
101 var e = b[0] + await dummy(); | |
102 Expect.equals(e, 2); | |
103 } | |
104 | |
105 conditionals() async { | |
106 var a = false; | |
107 var b = true; | |
108 var c = (a || b) || await dummy(); | |
hausner
2014/08/07 21:48:43
dummy() returns 1, so I don't expect this to pass
Michael Lippautz (Google)
2014/08/08 18:12:18
b is true, so await dummy() will never get evaluat
| |
109 Expect.isTrue(c); | |
110 var d = (a || b) ? a : await dummy(); | |
111 Expect.isFalse(d); | |
112 var e = (a is int) ? await dummy() : 2; | |
113 Expect.equals(e, 2); | |
114 try { | |
115 var f = (a is intt) ? await dummy() : 2; | |
116 } catch(e) {} | |
117 } | |
118 | |
119 main() { | |
120 staticMembers(); | |
121 topLevelMembers(); | |
122 instanceMembers(); | |
123 conditionals(); | |
124 others(); | |
125 } | |
126 | |
OLD | NEW |