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

Unified Diff: tests/language/dangling_else_test.dart

Issue 10837236: Fix dangling else. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 8 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
« no previous file with comments | « lib/compiler/implementation/js/printer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/dangling_else_test.dart
diff --git a/tests/language/dangling_else_test.dart b/tests/language/dangling_else_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d6d3bdb7771926740b1474853568e369274c5d22
--- /dev/null
+++ b/tests/language/dangling_else_test.dart
@@ -0,0 +1,82 @@
+// Copyright (c) 2012, 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 dangling else. The VM should not have any problems, but dart2js or
+// dart2dart could get this wrong.
+
+nestedIf1(notTrue) {
+ if (notTrue) return 'bad input';
+ if (notTrue) {
+ if (notTrue) {
+ return 'bad';
+ }
+ } else {
+ return 'good';
+ }
+ return 'bug';
+}
+
+nestedIf2(notTrue) {
+ if (notTrue) return 'bad input';
+ if (notTrue) {
+ if (notTrue) {
+ return 'bad';
+ } else {
+ if (notTrue) {
+ return 'bad';
+ }
+ }
+ } else {
+ return 'good';
+ }
+ return 'bug';
+}
+
+nestedWhile(notTrue) {
+ if (notTrue) return 'bad input';
+ if (notTrue) {
+ while(notTrue) {
+ if (notTrue) {
+ return 'bad';
+ }
+ }
+ } else {
+ return 'good';
+ }
+ return 'bug';
+}
+
+nestedFor(notTrue) {
+ if (notTrue) return 'bad input';
+ if (notTrue) {
+ for (int i = 0; i < 3; i++) {
+ if (i == 0) {
+ return 'bad';
+ }
+ }
+ } else {
+ return 'good';
+ }
+ return 'bug';
+}
+
+nestedLabeledStatement(notTrue) {
+ if (notTrue) return 'bad input';
+ if (notTrue) {
+ label:
+ if (notTrue) {
+ break label;
+ }
+ } else {
+ return 'good';
+ }
+ return 'bug';
+}
+
+main() {
+ Expect.equals('good', nestedIf1(false));
+ Expect.equals('good', nestedIf2(false));
+ Expect.equals('good', nestedWhile(false));
+ Expect.equals('good', nestedFor(false));
+ Expect.equals('good', nestedLabeledStatement(false));
+}
« no previous file with comments | « lib/compiler/implementation/js/printer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698