| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Dart test program for testing the instanceof operation. |
| 5 // Regression test for issue 5216. |
| 6 |
| 7 class Foo<T> { |
| 8 bool isT() => "a string" is T; |
| 9 bool isNotT() => "a string" is! T; |
| 10 bool isListT() => [0, 1, 2] is List<T>; |
| 11 bool isNotListT() => [0, 1, 2] is! List<T>; |
| 12 bool isAlsoListT() => <int>[0, 1, 2] is List<T>; |
| 13 bool isNeitherListT() => <int>[0, 1, 2] is! List<T>; |
| 14 } |
| 15 |
| 16 testFooString() { |
| 17 var o = new Foo<String>(); |
| 18 Expect.isTrue(o.isT()); |
| 19 Expect.isTrue(!o.isNotT()); |
| 20 Expect.isTrue(o.isListT()); |
| 21 Expect.isTrue(!o.isNotListT()); |
| 22 Expect.isTrue(!o.isAlsoListT()); |
| 23 Expect.isTrue(o.isNeitherListT()); |
| 24 for (var i = 0; i < 4000; i++) { |
| 25 // Make sure methods are optimized. |
| 26 o.isT(); |
| 27 o.isNotT(); |
| 28 o.isListT(); |
| 29 o.isNotListT(); |
| 30 o.isAlsoListT(); |
| 31 o.isNeitherListT(); |
| 32 } |
| 33 Expect.isTrue(o.isT()); |
| 34 Expect.isTrue(!o.isNotT()); |
| 35 Expect.isTrue(o.isListT()); |
| 36 Expect.isTrue(!o.isNotListT()); |
| 37 Expect.isTrue(!o.isAlsoListT()); |
| 38 Expect.isTrue(o.isNeitherListT()); |
| 39 } |
| 40 |
| 41 testFooInt() { |
| 42 var o = new Foo<int>(); |
| 43 Expect.isTrue(!o.isT()); |
| 44 Expect.isTrue(o.isNotT()); |
| 45 Expect.isTrue(o.isListT()); |
| 46 Expect.isTrue(!o.isNotListT()); |
| 47 Expect.isTrue(o.isAlsoListT()); |
| 48 Expect.isTrue(!o.isNeitherListT()); |
| 49 for (var i = 0; i < 4000; i++) { |
| 50 // Make sure methods are optimized. |
| 51 o.isT(); |
| 52 o.isNotT(); |
| 53 o.isListT(); |
| 54 o.isNotListT(); |
| 55 o.isAlsoListT(); |
| 56 o.isNeitherListT(); |
| 57 } |
| 58 Expect.isTrue(!o.isT()); |
| 59 Expect.isTrue(o.isNotT()); |
| 60 Expect.isTrue(o.isListT()); |
| 61 Expect.isTrue(!o.isNotListT()); |
| 62 Expect.isTrue(o.isAlsoListT()); |
| 63 Expect.isTrue(!o.isNeitherListT()); |
| 64 } |
| 65 |
| 66 main() { |
| 67 testFooString(); |
| 68 testFooInt(); |
| 69 } |
| OLD | NEW |