| 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. Direct tests against | 9 // current lexical scope, then T is mapped to dynamic. Direct tests against |
| 10 // T cause a dynamic type error though. | 10 // T cause a dynamic type error though. |
| 11 | 11 |
| 12 isCheckedMode() { | 12 isCheckedMode() { |
| 13 try { | 13 try { |
| 14 var i = 1; | 14 var i = 1; |
| 15 String s = i; | 15 String s = i; |
| 16 return false; | 16 return false; |
| 17 } catch (e) { | 17 } catch (e) { |
| 18 return true; | 18 return true; |
| 19 } | 19 } |
| 20 } | 20 } |
| 21 | 21 |
| 22 testAll() { | 22 testAll() { |
| 23 { | 23 { |
| 24 bool got_type_error = false; | 24 bool got_type_error = false; |
| 25 var x = null; | 25 var x = null; |
| 26 try { | 26 try { |
| 27 Expect.isTrue(x is UndeclaredType); // x is null. | 27 Expect.isTrue(x is UndeclaredType); // x is null. |
| 28 } on TypeError catch (error) { | 28 } on TypeError catch (error) { |
| 29 got_type_error = true; | 29 got_type_error = true; |
| 30 } | 30 } |
| 31 // Type error. | 31 // Type error. |
| 32 Expect.isTrue(got_type_error); | 32 Expect.isTrue(got_type_error); |
| 33 } | 33 } |
| 34 { | 34 { |
| 35 bool got_type_error = false; | 35 bool got_type_error = false; |
| 36 var x = 1; | 36 var x = 1; |
| 37 try { | 37 try { |
| 38 Expect.isTrue(x is UndeclaredType); // x is not null. | 38 Expect.isTrue(x is UndeclaredType); // x is not null. |
| 39 } on TypeError catch (error) { | 39 } on TypeError catch (error) { |
| 40 got_type_error = true; | 40 got_type_error = true; |
| 41 } | 41 } |
| 42 // Type error. | 42 // Type error. |
| 43 Expect.isTrue(got_type_error); | 43 Expect.isTrue(got_type_error); |
| 44 } | 44 } |
| 45 { | 45 { |
| 46 bool got_type_error = false; | 46 bool got_type_error = false; |
| 47 var x = null; | 47 var x = null; |
| 48 try { | 48 try { |
| 49 Expect.isFalse(x is List<UndeclaredType>); // x is null. | 49 Expect.isFalse(x is List<UndeclaredType>); // x is null. |
| 50 } on TypeError catch (error) { | 50 } on TypeError catch (error) { |
| 51 got_type_error = true; | 51 got_type_error = true; |
| 52 } | 52 } |
| 53 // No type error. | 53 // No type error. |
| 54 Expect.isFalse(got_type_error); | 54 Expect.isFalse(got_type_error); |
| 55 } | 55 } |
| 56 { | 56 { |
| 57 bool got_type_error = false; | 57 bool got_type_error = false; |
| 58 var x = 1; | 58 var x = 1; |
| 59 try { | 59 try { |
| 60 Expect.isFalse(x is List<UndeclaredType>); // x is not a List. | 60 Expect.isFalse(x is List<UndeclaredType>); // x is not a List. |
| 61 } on TypeError catch (error) { | 61 } on TypeError catch (error) { |
| 62 got_type_error = true; | 62 got_type_error = true; |
| 63 } | 63 } |
| 64 // No type error. | 64 // No type error. |
| 65 Expect.isFalse(got_type_error); | 65 Expect.isFalse(got_type_error); |
| 66 } | 66 } |
| 67 { | 67 { |
| 68 bool got_type_error = false; | 68 bool got_type_error = false; |
| 69 var x = new List(); | 69 var x = new List(); |
| 70 try { | 70 try { |
| 71 Expect.isTrue(x is List<UndeclaredType>); // x is a List<dynamic>. | 71 Expect.isTrue(x is List<UndeclaredType>); // x is a List<dynamic>. |
| 72 } on TypeError catch (error) { | 72 } on TypeError catch (error) { |
| 73 got_type_error = true; | 73 got_type_error = true; |
| 74 } | 74 } |
| 75 // No type error. | 75 // No type error. |
| 76 Expect.isFalse(got_type_error); | 76 Expect.isFalse(got_type_error); |
| 77 } | 77 } |
| 78 { | 78 { |
| 79 bool got_type_error = false; | 79 bool got_type_error = false; |
| 80 var x = new List<int>(); | 80 var x = new List<int>(); |
| 81 try { | 81 try { |
| 82 Expect.isTrue(x is List<UndeclaredType>); // x is a List<int>. | 82 Expect.isTrue(x is List<UndeclaredType>); // x is a List<int>. |
| 83 } on TypeError catch (error) { | 83 } on TypeError catch (error) { |
| 84 got_type_error = true; | 84 got_type_error = true; |
| 85 } | 85 } |
| 86 // No type error. | 86 // No type error. |
| 87 Expect.isFalse(got_type_error); | 87 Expect.isFalse(got_type_error); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 main() { | 91 main() { |
| 92 // Repeat type checks so that inlined tests can be tested as well. | 92 // Repeat type checks so that inlined tests can be tested as well. |
| 93 for (int i = 0; i < 5; i++) { | 93 for (int i = 0; i < 5; i++) { |
| 94 testAll(); | 94 testAll(); |
| 95 } | 95 } |
| 96 } | 96 } |
| OLD | NEW |