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. Direct tests against |
| 10 // T cause a dynamic type error though. |
10 | 11 |
11 isCheckedMode() { | 12 isCheckedMode() { |
12 try { | 13 try { |
13 var i = 1; | 14 var i = 1; |
14 String s = i; | 15 String s = i; |
15 return false; | 16 return false; |
16 } catch (e) { | 17 } catch (e) { |
17 return true; | 18 return true; |
18 } | 19 } |
19 } | 20 } |
20 | 21 |
21 testAll() { | 22 testAll() { |
22 { | 23 { |
23 bool got_type_error = false; | 24 bool got_type_error = false; |
24 var x = null; | 25 var x = null; |
25 try { | 26 try { |
26 Expect.isTrue(x is UndeclaredType); // x is null. | 27 Expect.isTrue(x is UndeclaredType); // x is null. |
27 } on TypeError catch (error) { | 28 } on TypeError catch (error) { |
28 got_type_error = true; | 29 got_type_error = true; |
29 } | 30 } |
30 // No type error. | 31 // Type error. |
31 Expect.isFalse(got_type_error); | 32 Expect.isTrue(got_type_error); |
32 } | 33 } |
33 { | 34 { |
34 bool got_type_error = false; | 35 bool got_type_error = false; |
35 var x = 1; | 36 var x = 1; |
36 try { | 37 try { |
37 Expect.isTrue(x is UndeclaredType); // x is not null. | 38 Expect.isTrue(x is UndeclaredType); // x is not null. |
38 } on TypeError catch (error) { | 39 } on TypeError catch (error) { |
39 got_type_error = true; | 40 got_type_error = true; |
40 } | 41 } |
41 // No type error. | 42 // Type error. |
42 Expect.isFalse(got_type_error); | 43 Expect.isTrue(got_type_error); |
43 } | 44 } |
44 { | 45 { |
45 bool got_type_error = false; | 46 bool got_type_error = false; |
46 var x = null; | 47 var x = null; |
47 try { | 48 try { |
48 Expect.isFalse(x is List<UndeclaredType>); // x is null. | 49 Expect.isFalse(x is List<UndeclaredType>); // x is null. |
49 } on TypeError catch (error) { | 50 } on TypeError catch (error) { |
50 got_type_error = true; | 51 got_type_error = true; |
51 } | 52 } |
52 // No type error. | 53 // No type error. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 Expect.isFalse(got_type_error); | 87 Expect.isFalse(got_type_error); |
87 } | 88 } |
88 } | 89 } |
89 | 90 |
90 main() { | 91 main() { |
91 // 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. |
92 for (int i = 0; i < 5; i++) { | 93 for (int i = 0; i < 5; i++) { |
93 testAll(); | 94 testAll(); |
94 } | 95 } |
95 } | 96 } |
OLD | NEW |