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

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

Issue 459763003: dart2dart: Fix a scoping bug in the translation of loops. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporated review comments. Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/language/for_test.dart ('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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 // Dart test program for testing while statement. 4 // Dart test program for testing while statement.
5 5
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 7
8 class Helper { 8 class Helper {
9 static int f1(bool b) { 9 static int f1(bool b) {
10 while (b) 10 while (b)
11 return 1; 11 return 1;
12 12
13 return 2; 13 return 2;
14 } 14 }
15 15
16 static int f2(bool b) { 16 static int f2(bool b) {
17 while (b) { 17 while (b) {
18 return 1; 18 return 1;
19 } 19 }
20 return 2; 20 return 2;
21 } 21 }
22 22
23 static int f3(int n) { 23 static int f3(int n) {
24 int i = 0; 24 int i = 0;
25 while (i < n) { 25 while (i < n) {
26 i++; 26 i++;
27 } 27 }
28 return i; 28 return i;
29 } 29 }
30
31 static int f4() {
32 // Verify that side effects in the condition are visible after the loop.
33 int i = 0;
34 while (++i < 3) {}
35 return i;
36 }
30 } 37 }
31 38
32 class WhileTest { 39 class WhileTest {
33 static testMain() { 40 static testMain() {
34 Expect.equals(1, Helper.f1(true)); 41 Expect.equals(1, Helper.f1(true));
35 Expect.equals(2, Helper.f1(false)); 42 Expect.equals(2, Helper.f1(false));
36 Expect.equals(1, Helper.f2(true)); 43 Expect.equals(1, Helper.f2(true));
37 Expect.equals(2, Helper.f2(false)); 44 Expect.equals(2, Helper.f2(false));
38 Expect.equals(0, Helper.f3(-2)); 45 Expect.equals(0, Helper.f3(-2));
39 Expect.equals(0, Helper.f3(-1)); 46 Expect.equals(0, Helper.f3(-1));
40 Expect.equals(0, Helper.f3(0)); 47 Expect.equals(0, Helper.f3(0));
41 Expect.equals(1, Helper.f3(1)); 48 Expect.equals(1, Helper.f3(1));
42 Expect.equals(2, Helper.f3(2)); 49 Expect.equals(2, Helper.f3(2));
50 Expect.equals(3, Helper.f4());
43 } 51 }
44 } 52 }
45 53
46 main() { 54 main() {
47 WhileTest.testMain(); 55 WhileTest.testMain();
48 } 56 }
OLDNEW
« no previous file with comments | « tests/language/for_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698