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

Side by Side Diff: tests/language/conditional_property_increment_decrement_test.dart

Issue 1177043010: Add tests for e?.v++, e?.v--, ++e?.v, and --e?.v. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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 | « no previous file | tests/language/language.status » ('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) 2015, 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 // Verify semantics of the ?. operator when it appears in a postincrement or
6 // preincrement expression (or a postdecrement or predecrement expression).
7
8 // SharedOptions=--enable-null-aware-operators
9
10 import "package:expect/expect.dart";
11
12 class C {
13 int v;
14 C(this.v);
15 static var staticField;
16 }
17
18 class D {
19 E v;
20 D(this.v);
21 }
22
23 class E {
24 G operator+(int i) => new I();
25 G operator-(int i) => new I();
26 }
27
28 class F {}
29
30 class G extends E implements F {}
31
32 class H {}
33
34 class I extends G implements H {}
35
36 C nullC() => null;
37
38 main() {
39 // Make sure the "none" test fails if assignment to "?." is not implemented.
40 // This makes status files easier to maintain.
41 nullC()?.v = 1;
42
43 // e1?.v++ is equivalent to ((x) => x == null ? null : x.v++)(e1).
44 Expect.equals(null, nullC()?.v++); /// 01: ok
45 { C c = new C(1); Expect.equals(1, c?.v++); Expect.equals(2, c.v); } /// 02: o k
46
47 // The static type of e1?.v++ is the same as the static type of e1.v.
48 { E e1 = new E(); D d = new D(e1); E e2 = d?.v++; Expect.identical(e1, e2); } /// 03: ok
49 { G g = new G(); D d = new D(g); F f = d?.v++; Expect.identical(f, g); } /// 0 4: static type warning
50
51 // e1?.v-- is equivalent to ((x) => x == null ? null : x.v--)(e1).
52 Expect.equals(null, nullC()?.v--); /// 05: ok
53 { C c = new C(1); Expect.equals(1, c?.v--); Expect.equals(0, c.v); } /// 06: o k
54
55 // The static type of e1?.v-- is the same as the static type of e1.v.
56 { E e1 = new E(); D d = new D(e1); E e2 = d?.v--; Expect.identical(e1, e2); } /// 07: ok
57 { G g = new G(); D d = new D(g); F f = d?.v--; Expect.identical(f, g); } /// 0 8: static type warning
58
59 // ++e1?.v is equivalent to e1?.v += 1.
60 Expect.equals(null, ++nullC()?.v); /// 09: ok
61 { C c = new C(1); Expect.equals(2, ++c?.v); Expect.equals(2, c.v); } /// 10: o k
62
63 // The static type of ++e1?.v is the same as the static type of e1.v + 1.
64 { D d = new D(new E()); F f = ++d?.v; Expect.identical(d.v, f); } /// 11: ok
65 { D d = new D(new E()); H h = ++d?.v; Expect.identical(d.v, h); } /// 12: stat ic type warning
66
67 // --e1?.v is equivalent to e1?.v += 1.
68 Expect.equals(null, --nullC()?.v); /// 13: ok
69 { C c = new C(1); Expect.equals(0, --c?.v); Expect.equals(0, c.v); } /// 14: o k
70
71 // The static type of --e1?.v is the same as the static type of e1.v - 1.
72 { D d = new D(new E()); F f = --d?.v; Expect.identical(d.v, f); } /// 15: ok
73 { D d = new D(new E()); H h = --d?.v; Expect.identical(d.v, h); } /// 16: stat ic type warning
74 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698