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

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

Issue 10891020: Update almost all tests (except co19) to use the new try-catch syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge. Created 8 years, 3 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/type_vm_test.dart ('k') | tests/lib/math/math2_test.dart » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 for type checks involving the void type. 4 // Dart test for type checks involving the void type.
5 5
6 isCheckedMode() { 6 isCheckedMode() {
7 try { 7 try {
8 var i = 1; 8 var i = 1;
9 String s = i; 9 String s = i;
10 return false; 10 return false;
11 } catch(var e) { 11 } catch (e) {
12 return true; 12 return true;
13 } 13 }
14 } 14 }
15 15
16 void f() { return; } 16 void f() { return; }
17 17
18 void f_null() { return null; } 18 void f_null() { return null; }
19 19
20 void f_1() { return 1; } 20 void f_1() { return 1; }
21 21
22 void f_dyn_null() { 22 void f_dyn_null() {
23 var x = null; 23 var x = null;
24 return x; 24 return x;
25 } 25 }
26 26
27 void f_dyn_1() { 27 void f_dyn_1() {
28 var x = 1; 28 var x = 1;
29 return x; 29 return x;
30 } 30 }
31 31
32 void f_f() { return f(); } 32 void f_f() { return f(); }
33 33
34 void test(int n, void func(), bool must_get_error) { 34 void test(int n, void func(), bool must_get_error) {
35 // Test as closure call. 35 // Test as closure call.
36 { 36 {
37 bool got_type_error = false; 37 bool got_type_error = false;
38 try { 38 try {
39 var x = func(); 39 var x = func();
40 } catch (TypeError error) { 40 } on TypeError catch (error) {
41 got_type_error = true; 41 got_type_error = true;
42 } 42 }
43 // Never a type error in production mode. 43 // Never a type error in production mode.
44 if (isCheckedMode()) { 44 if (isCheckedMode()) {
45 Expect.isTrue(got_type_error == must_get_error); 45 Expect.isTrue(got_type_error == must_get_error);
46 } else { 46 } else {
47 Expect.isFalse(got_type_error); 47 Expect.isFalse(got_type_error);
48 } 48 }
49 } 49 }
50 // Test as direct call. 50 // Test as direct call.
51 { 51 {
52 bool got_type_error = false; 52 bool got_type_error = false;
53 try { 53 try {
54 var x; 54 var x;
55 switch (n) { 55 switch (n) {
56 case 0: x = f(); break; 56 case 0: x = f(); break;
57 case 1: x = f_null(); break; 57 case 1: x = f_null(); break;
58 case 2: x = f_1(); break; 58 case 2: x = f_1(); break;
59 case 3: x = f_dyn_null(); break; 59 case 3: x = f_dyn_null(); break;
60 case 4: x = f_dyn_1(); break; 60 case 4: x = f_dyn_1(); break;
61 case 5: x = f_f(); break; 61 case 5: x = f_f(); break;
62 } 62 }
63 } catch (TypeError error) { 63 } on TypeError catch (error) {
64 got_type_error = true; 64 got_type_error = true;
65 } 65 }
66 // Never a type error in production mode. 66 // Never a type error in production mode.
67 if (isCheckedMode()) { 67 if (isCheckedMode()) {
68 Expect.isTrue(got_type_error == must_get_error); 68 Expect.isTrue(got_type_error == must_get_error);
69 } else { 69 } else {
70 Expect.isFalse(got_type_error); 70 Expect.isFalse(got_type_error);
71 } 71 }
72 } 72 }
73 } 73 }
74 74
75 main() { 75 main() {
76 test(0, f, false); 76 test(0, f, false);
77 test(1, f_null, false); 77 test(1, f_null, false);
78 test(2, f_1, true); 78 test(2, f_1, true);
79 test(3, f_dyn_null, false); 79 test(3, f_dyn_null, false);
80 test(4, f_dyn_1, true); 80 test(4, f_dyn_1, true);
81 test(5, f_f, false); 81 test(5, f_f, false);
82 } 82 }
83 83
84 84
OLDNEW
« no previous file with comments | « tests/language/type_vm_test.dart ('k') | tests/lib/math/math2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698