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

Unified Diff: test/codegen/language/nullaware_opt_test.dart

Issue 1316723003: implement null aware ops, fixes #249 (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 side-by-side diff with in-line comments
Download patch
Index: test/codegen/language/nullaware_opt_test.dart
diff --git a/test/codegen/language/nullaware_opt_test.dart b/test/codegen/language/nullaware_opt_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5446171d775930479cf74f11f49eaf5ff4a7cb35
--- /dev/null
+++ b/test/codegen/language/nullaware_opt_test.dart
@@ -0,0 +1,70 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// VMOptions=--optimization_counter_threshold=5
+//
+// Basic null-aware operator test that invokes the optimizing compiler.
+
+import "package:expect/expect.dart";
+
+class C {
+ C(this.f);
+ var f;
+ m(a) => a;
+}
+
+bomb() {
+ Expect.fail('Should not be executed');
+ return 100;
+}
+
+getNull() => null;
+
+test() {
+ var c;
+ var d = new C(5);
+ Expect.equals(null, c?.m(bomb()));
+ Expect.equals(null, getNull()?.anything(bomb()));
+ Expect.equals(1, d?.m(1));
+
+ Expect.equals(1, new C(1)?.f);
+ Expect.equals(null, c?.v);
+ Expect.equals(10, c ?? 10);
+ Expect.equals(d, d ?? bomb());
+
+ var e;
+ // The assignment to e is not executed since d != null.
+ d ??= e ??= new C(100);
+ Expect.equals(null, e);
+ e ??= new C(100);
+ Expect.equals(100, e?.f);
+ e?.f ??= 200;
+ Expect.equals(100, e?.f);
+
+ e.f = null;
+ e?.f ??= 200;
+ Expect.equals(200, e?.f);
+
+ c?.f ??= 400;
+ Expect.equals(null, c?.f);
+ Expect.equals(null, c?.f++);
+ e?.f++;
+ Expect.equals(201, e.f);
+
+ var x = 5 ?? bomb();
+}
+
+// Check that instructions without result do not crash.
+test2() {
+ var c;
+ c?.v;
+ c?.m(bomb());
+}
+
+main() {
+ for (int i = 0; i < 10; i++) {
+ test();
+ test2();
+ }
+}
« no previous file with comments | « test/codegen/language/if_null_assignment_static_test.dart ('k') | test/codegen/language/super_conditional_operator_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698