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

Unified Diff: tests/kernel/unsorted/conditional_test.dart

Issue 2451623006: Reland "Merge more Kernel infrastructure from kernel_sdk SDK fork." (Closed)
Patch Set: Fix Created 4 years, 2 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: tests/kernel/unsorted/conditional_test.dart
diff --git a/tests/kernel/unsorted/conditional_test.dart b/tests/kernel/unsorted/conditional_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c5df2c33e337f27f6d74133305513337cb769739
--- /dev/null
+++ b/tests/kernel/unsorted/conditional_test.dart
@@ -0,0 +1,142 @@
+// Copyright (c) 2016, 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.
+
+// Tests of conditional expressions and statements and negation.
+
+import 'expect.dart';
+
+mkTrue() => true;
+mkFalse() => false;
+
+check(b) {
+ Expect.isTrue(b);
+ return b;
+}
+
+main() {
+ // Check that ?: gets the right answer.
+ Expect.isTrue((mkTrue() ? 0 : 1) == 0);
+ Expect.isTrue((mkFalse() ? 0 : 1) == 1);
+ // Check that it doesn't evaluate all subexpressions.
+ mkTrue() ? Expect.isTrue(true) : Expect.isTrue(false);
+ mkFalse() ? Expect.isTrue(false) : Expect.isTrue(true);
+
+ // Check that && and || get the right answers.
+ Expect.isTrue(mkTrue() && mkTrue());
+ Expect.isTrue(!(mkTrue() && mkFalse()));
+ Expect.isTrue(!(mkFalse() && mkTrue()));
+ Expect.isTrue(!(mkFalse() && mkFalse()));
+ Expect.isTrue(mkTrue() || mkTrue());
+ Expect.isTrue(mkTrue() || mkFalse());
+ Expect.isTrue(mkFalse() || mkTrue());
+ Expect.isTrue(!(mkFalse() || mkFalse()));
+
+ // Check that they don't evaluate both subexpressions.
+ mkTrue() && check(true);
+ mkFalse() && check(false);
+ mkTrue() || check(true);
+ mkFalse() || check(true);
+
+ // Check that if works.
+ if (mkTrue()) {
+ Expect.isTrue(true);
+ } else {
+ Expect.isTrue(false);
+ }
+ if (mkFalse()) {
+ Expect.isTrue(false);
+ } else {
+ Expect.isTrue(true);
+ }
+ if (!mkTrue()) {
+ Expect.isTrue(false);
+ } else {
+ Expect.isTrue(true);
+ }
+ if (!mkFalse()) {
+ Expect.isTrue(true);
+ } else {
+ Expect.isTrue(false);
+ }
+
+ // Check that ?:, &&, and || work for control flow.
+ if (mkTrue() ? mkTrue() : mkFalse()) {
+ Expect.isTrue(true);
+ } else {
+ Expect.isTrue(false);
+ }
+ if (mkTrue() ? mkFalse() : mkTrue()) {
+ Expect.isTrue(false);
+ } else {
+ Expect.isTrue(true);
+ }
+ if (mkFalse() ? mkTrue() : mkFalse()) {
+ Expect.isTrue(false);
+ } else {
+ Expect.isTrue(true);
+ }
+ if (mkFalse() ? mkFalse() : mkTrue()) {
+ Expect.isTrue(true);
+ } else {
+ Expect.isTrue(false);
+ }
+ if (mkTrue() && mkTrue()) {
+ Expect.isTrue(true);
+ } else {
+ Expect.isTrue(false);
+ }
+ if (mkTrue() && mkFalse()) {
+ Expect.isTrue(false);
+ } else {
+ Expect.isTrue(true);
+ }
+ if (mkFalse() && mkTrue()) {
+ Expect.isTrue(false);
+ } else {
+ Expect.isTrue(true);
+ }
+ if (mkFalse() && mkFalse()) {
+ Expect.isTrue(false);
+ } else {
+ Expect.isTrue(true);
+ }
+ if (mkTrue() || mkTrue()) {
+ Expect.isTrue(true);
+ } else {
+ Expect.isTrue(false);
+ }
+ if (mkTrue() || mkFalse()) {
+ Expect.isTrue(true);
+ } else {
+ Expect.isTrue(false);
+ }
+ if (mkFalse() || mkTrue()) {
+ Expect.isTrue(true);
+ } else {
+ Expect.isTrue(false);
+ }
+ if (mkFalse() || mkFalse()) {
+ Expect.isTrue(false);
+ } else {
+ Expect.isTrue(true);
+ }
+
+ // Test empty else branches.
+ if (mkTrue()) {
+ Expect.isTrue(true);
+ }
+ if (mkFalse()) {
+ Expect.isTrue(false);
+ }
+
+ var x = 0;
+ if (mkTrue()) {
+ x = 1;
+ }
+ Expect.isTrue(x == 1);
+ if (mkFalse()) {
+ x = 2;
+ }
+ Expect.isTrue(x == 1);
+}
« no previous file with comments | « tests/kernel/unsorted/closures_test.dart ('k') | tests/kernel/unsorted/constant_evaluator_regression_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698