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

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

Issue 1180903002: null-aware operators in the VM (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: updating test and status files 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 | « tests/language/language_dart2js.status ('k') | no next file » | 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 // SharedOptions=--enable-null-aware-operators
6 // VMOptions=--optimization_counter_threshold=5
7 //
8 // Basic null-aware operator test that invokes the optimizing compiler.
9
10 import "package:expect/expect.dart";
11
12 class C {
13 C(this.f);
14 var f;
15 m(a) => a;
16 }
17
18 bomb() {
19 Expect.fail('Should not be executed');
20 return 100;
21 }
22
23 getNull() => null;
24
25 test() {
26 var c;
27 var d = new C(5);
28 Expect.equals(null, c?.m(bomb()));
29 Expect.equals(null, getNull()?.anything(bomb()));
30 Expect.equals(1, d?.m(1));
31 Expect.equals("C", C?.toString());
32
33 Expect.equals(1, new C(1)?.f);
34 Expect.equals(null, c?.v);
35 Expect.equals(10, c ?? 10);
36 Expect.equals(d, d ?? bomb());
37
38 var e;
39 // The assginment to e is not executed since d != null.
40 d ??= e ??= new C(100);
41 Expect.equals(null, e);
42 e ??= new C(100);
43 Expect.equals(100, e?.f);
44 e?.f ??= 200;
45 Expect.equals(100, e?.f);
46
47 e.f = null;
48 e?.f ??= 200;
49 Expect.equals(200, e?.f);
50
51 c?.f ??= 400;
52 Expect.equals(null, c?.f);
53 Expect.equals(null, c?.f++);
54 e?.f++;
55 Expect.equals(201, e.f);
56
57 var x = 5 ?? bomb();
58 }
59
60 main() {
61 for (int i = 0; i < 10; i++) {
62 test();
63 }
64 }
OLDNEW
« no previous file with comments | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698