| 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 // Regression test for issue 5216. | 5 // Regression test for issue 5216. |
| 6 // VMOptions=--optimization-counter-threshold=10 --no-use-osr | 6 // VMOptions=--optimization-counter-threshold=10 --no-use-osr |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 | 9 |
| 10 class Foo<T> { | 10 class Foo<T> { |
| 11 bool isT() => "a string" is T; | 11 bool isT() => "a string" is T; |
| 12 bool isNotT() => "a string" is! T; | 12 bool isNotT() => "a string" is! T; |
| 13 bool isListT() => [0, 1, 2] is List<T>; | 13 bool isListT() => [0, 1, 2] is List<T>; |
| 14 bool isNotListT() => [0, 1, 2] is! List<T>; | 14 bool isNotListT() => [0, 1, 2] is! List<T>; |
| 15 bool isAlsoListT() => <int>[0, 1, 2] is List<T>; | 15 bool isAlsoListT() => <int>[0, 1, 2] is List<T>; |
| 16 bool isNeitherListT() => <int>[0, 1, 2] is! List<T>; | 16 bool isNeitherListT() => <int>[0, 1, 2] is! List<T>; |
| 17 } | 17 } |
| 18 | 18 |
| 19 testFooString() { | 19 testFooString() { |
| 20 var o = new Foo<String>(); | 20 var o = new Foo<String>(); |
| 21 Expect.isTrue(o.isT()); | 21 Expect.isTrue(o.isT()); |
| 22 Expect.isTrue(!o.isNotT()); | 22 Expect.isTrue(!o.isNotT()); |
| 23 Expect.isTrue(o.isListT()); | 23 Expect.isTrue(o.isListT()); |
| 24 Expect.isTrue(!o.isNotListT()); | 24 Expect.isTrue(!o.isNotListT()); |
| 25 Expect.isTrue(!o.isAlsoListT()); // /// 01: ok | 25 Expect.isTrue(!o.isAlsoListT()); // //# 01: ok |
| 26 Expect.isTrue(o.isNeitherListT()); // /// 01: ok | 26 Expect.isTrue(o.isNeitherListT()); // //# 01: ok |
| 27 for (var i = 0; i < 20; i++) { | 27 for (var i = 0; i < 20; i++) { |
| 28 // Make sure methods are optimized. | 28 // Make sure methods are optimized. |
| 29 o.isT(); | 29 o.isT(); |
| 30 o.isNotT(); | 30 o.isNotT(); |
| 31 o.isListT(); | 31 o.isListT(); |
| 32 o.isNotListT(); | 32 o.isNotListT(); |
| 33 o.isAlsoListT(); // /// 01: ok | 33 o.isAlsoListT(); // //# 01: ok |
| 34 o.isNeitherListT(); // /// 01: ok | 34 o.isNeitherListT(); // //# 01: ok |
| 35 } | 35 } |
| 36 Expect.isTrue(o.isT(), "1"); | 36 Expect.isTrue(o.isT(), "1"); |
| 37 Expect.isTrue(!o.isNotT(), "2"); | 37 Expect.isTrue(!o.isNotT(), "2"); |
| 38 Expect.isTrue(o.isListT(), "3"); | 38 Expect.isTrue(o.isListT(), "3"); |
| 39 Expect.isTrue(!o.isNotListT(), "4"); | 39 Expect.isTrue(!o.isNotListT(), "4"); |
| 40 Expect.isTrue(!o.isAlsoListT(), "5"); // /// 01: ok | 40 Expect.isTrue(!o.isAlsoListT(), "5"); // //# 01: ok |
| 41 Expect.isTrue(o.isNeitherListT(), "6"); // /// 01: ok | 41 Expect.isTrue(o.isNeitherListT(), "6"); // //# 01: ok |
| 42 } | 42 } |
| 43 | 43 |
| 44 testFooInt() { | 44 testFooInt() { |
| 45 var o = new Foo<int>(); | 45 var o = new Foo<int>(); |
| 46 Expect.isTrue(!o.isT()); | 46 Expect.isTrue(!o.isT()); |
| 47 Expect.isTrue(o.isNotT()); | 47 Expect.isTrue(o.isNotT()); |
| 48 Expect.isTrue(o.isListT()); | 48 Expect.isTrue(o.isListT()); |
| 49 Expect.isTrue(!o.isNotListT()); | 49 Expect.isTrue(!o.isNotListT()); |
| 50 Expect.isTrue(o.isAlsoListT()); | 50 Expect.isTrue(o.isAlsoListT()); |
| 51 Expect.isTrue(!o.isNeitherListT()); | 51 Expect.isTrue(!o.isNeitherListT()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 63 Expect.isTrue(o.isListT()); | 63 Expect.isTrue(o.isListT()); |
| 64 Expect.isTrue(!o.isNotListT()); | 64 Expect.isTrue(!o.isNotListT()); |
| 65 Expect.isTrue(o.isAlsoListT()); | 65 Expect.isTrue(o.isAlsoListT()); |
| 66 Expect.isTrue(!o.isNeitherListT()); | 66 Expect.isTrue(!o.isNeitherListT()); |
| 67 } | 67 } |
| 68 | 68 |
| 69 main() { | 69 main() { |
| 70 testFooString(); | 70 testFooString(); |
| 71 testFooInt(); | 71 testFooInt(); |
| 72 } | 72 } |
| OLD | NEW |