| OLD | NEW |
| 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 program for testing the instanceof operation. | 4 // Dart test program for testing the instanceof operation. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 // In the type test 'e is T', if T does not denote a type available in the | 8 // In the type test 'e is T', if T does not denote a type available in the |
| 9 // current lexical scope, then T is mapped to dynamic and the test succeeds. | 9 // current lexical scope, then T is mapped to dynamic and the test succeeds. |
| 10 | 10 |
| 11 isCheckedMode() { | 11 isCheckedMode() { |
| 12 try { | 12 try { |
| 13 var i = 1; | 13 var i = 1; |
| 14 String s = i; | 14 String s = i; |
| 15 return false; | 15 return false; |
| 16 } catch (e) { | 16 } catch (e) { |
| 17 return true; | 17 return true; |
| 18 } | 18 } |
| 19 } | 19 } |
| 20 | 20 |
| 21 testAll() { | 21 testAll() { |
| 22 { | 22 { |
| 23 bool got_type_error = false; | 23 bool got_type_error = false; |
| 24 var x = null; | 24 var x = null; |
| 25 try { | 25 try { |
| 26 Expect.isTrue(x is UndeclaredType); // x is null. | 26 x is UndeclaredType; // x is null. |
| 27 } on TypeError catch (error) { | 27 } on TypeError catch (error) { |
| 28 got_type_error = true; | 28 got_type_error = true; |
| 29 } | 29 } |
| 30 // No type error. | 30 Expect.isTrue(got_type_error); |
| 31 Expect.isFalse(got_type_error); | |
| 32 } | 31 } |
| 33 { | 32 { |
| 34 bool got_type_error = false; | 33 bool got_type_error = false; |
| 35 var x = 1; | 34 var x = 1; |
| 36 try { | 35 try { |
| 37 Expect.isTrue(x is UndeclaredType); // x is not null. | 36 x is UndeclaredType; // x is not null. |
| 38 } on TypeError catch (error) { | 37 } on TypeError catch (error) { |
| 39 got_type_error = true; | 38 got_type_error = true; |
| 40 } | 39 } |
| 41 // No type error. | 40 Expect.isTrue(got_type_error); |
| 42 Expect.isFalse(got_type_error); | |
| 43 } | 41 } |
| 44 { | 42 { |
| 45 bool got_type_error = false; | 43 bool got_type_error = false; |
| 46 var x = null; | 44 var x = null; |
| 47 try { | 45 try { |
| 48 Expect.isFalse(x is List<UndeclaredType>); // x is null. | 46 Expect.isFalse(x is List<UndeclaredType>); // x is null. |
| 49 } on TypeError catch (error) { | 47 } on TypeError catch (error) { |
| 50 got_type_error = true; | 48 got_type_error = true; |
| 51 } | 49 } |
| 52 // No type error. | 50 // No type error. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 Expect.isFalse(got_type_error); | 84 Expect.isFalse(got_type_error); |
| 87 } | 85 } |
| 88 } | 86 } |
| 89 | 87 |
| 90 main() { | 88 main() { |
| 91 // Repeat type checks so that inlined tests can be tested as well. | 89 // Repeat type checks so that inlined tests can be tested as well. |
| 92 for (int i = 0; i < 5; i++) { | 90 for (int i = 0; i < 5; i++) { |
| 93 testAll(); | 91 testAll(); |
| 94 } | 92 } |
| 95 } | 93 } |
| OLD | NEW |