| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, 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 // Test that instanceof works correctly with type variables. | |
| 5 | |
| 6 part of GenericInstanceofTest.dart; | |
| 7 | |
| 8 class Foo<T> { | |
| 9 Foo() {} | |
| 10 | |
| 11 bool isT(x) { | |
| 12 // Untyped parameter to ensure that the static type | |
| 13 // does not affect the result. | |
| 14 return x is T; | |
| 15 } | |
| 16 | |
| 17 bool isListT(x) { | |
| 18 return x is List<T>; | |
| 19 } | |
| 20 } | |
| 21 | |
| 22 class GenericInstanceof { | |
| 23 static void testMain() { | |
| 24 // Using Object instead of String to ensure that the static type | |
| 25 // does not affect the result. | |
| 26 Foo<Object> fooObject = new Foo<String>(); | |
| 27 Expect.equals(true, fooObject.isT("string")); | |
| 28 Expect.equals(false, fooObject.isT(1)); | |
| 29 | |
| 30 Foo<String> fooString = new Foo<String>(); | |
| 31 Expect.equals(true, fooString.isT("string")); | |
| 32 Expect.equals(false, fooString.isT(1)); | |
| 33 | |
| 34 // Not providing a type argument to ensure that the static type | |
| 35 // does not affect the result. | |
| 36 { | |
| 37 Foo foo = new Foo<String>(); | |
| 38 Expect.equals(true, foo.isT("string")); | |
| 39 Expect.equals(false, foo.isT(1)); | |
| 40 } | |
| 41 { | |
| 42 Foo foo = new Foo(); | |
| 43 Expect.equals(true, foo.isT(new List(5))); | |
| 44 Expect.equals(true, foo.isT(new List<Object>(5))); | |
| 45 Expect.equals(true, foo.isT(new List<int>(5))); | |
| 46 Expect.equals(true, foo.isT(new List<num>(5))); | |
| 47 Expect.equals(true, foo.isT(new List<String>(5))); | |
| 48 } | |
| 49 { | |
| 50 Foo foo = new Foo<List>(); | |
| 51 Expect.equals(true, foo.isT(new List(5))); | |
| 52 Expect.equals(true, foo.isT(new List<Object>(5))); | |
| 53 Expect.equals(true, foo.isT(new List<int>(5))); | |
| 54 Expect.equals(true, foo.isT(new List<num>(5))); | |
| 55 Expect.equals(true, foo.isT(new List<String>(5))); | |
| 56 } | |
| 57 { | |
| 58 Foo foo = new Foo<List<Object>>(); | |
| 59 Expect.equals(true, foo.isT(new List(5))); | |
| 60 Expect.equals(true, foo.isT(new List<Object>(5))); | |
| 61 Expect.equals(true, foo.isT(new List<int>(5))); | |
| 62 Expect.equals(true, foo.isT(new List<num>(5))); | |
| 63 Expect.equals(true, foo.isT(new List<String>(5))); | |
| 64 } | |
| 65 { | |
| 66 Foo foo = new Foo<List<int>>(); | |
| 67 Expect.equals(true, foo.isT(new List(5))); | |
| 68 Expect.equals(false, foo.isT(new List<Object>(5))); | |
| 69 Expect.equals(true, foo.isT(new List<int>(5))); | |
| 70 Expect.equals(false, foo.isT(new List<num>(5))); | |
| 71 Expect.equals(false, foo.isT(new List<String>(5))); | |
| 72 } | |
| 73 { | |
| 74 Foo foo = new Foo<List<num>>(); | |
| 75 Expect.equals(true, foo.isT(new List(5))); | |
| 76 Expect.equals(false, foo.isT(new List<Object>(5))); | |
| 77 Expect.equals(true, foo.isT(new List<int>(5))); | |
| 78 Expect.equals(true, foo.isT(new List<num>(5))); | |
| 79 Expect.equals(false, foo.isT(new List<String>(5))); | |
| 80 } | |
| 81 { | |
| 82 Foo foo = new Foo<List<String>>(); | |
| 83 Expect.equals(true, foo.isT(new List(5))); | |
| 84 Expect.equals(false, foo.isT(new List<Object>(5))); | |
| 85 Expect.equals(false, foo.isT(new List<int>(5))); | |
| 86 Expect.equals(false, foo.isT(new List<num>(5))); | |
| 87 Expect.equals(true, foo.isT(new List<String>(5))); | |
| 88 } | |
| 89 { | |
| 90 Foo foo = new Foo(); | |
| 91 Expect.equals(true, foo.isListT(new List(5))); | |
| 92 Expect.equals(true, foo.isListT(new List<Object>(5))); | |
| 93 Expect.equals(true, foo.isListT(new List<int>(5))); | |
| 94 Expect.equals(true, foo.isListT(new List<num>(5))); | |
| 95 Expect.equals(true, foo.isListT(new List<String>(5))); | |
| 96 } | |
| 97 { | |
| 98 Foo foo = new Foo<Object>(); | |
| 99 Expect.equals(true, foo.isListT(new List(5))); | |
| 100 Expect.equals(true, foo.isListT(new List<Object>(5))); | |
| 101 Expect.equals(true, foo.isListT(new List<int>(5))); | |
| 102 Expect.equals(true, foo.isListT(new List<num>(5))); | |
| 103 Expect.equals(true, foo.isListT(new List<String>(5))); | |
| 104 } | |
| 105 { | |
| 106 Foo foo = new Foo<int>(); | |
| 107 Expect.equals(true, foo.isListT(new List(5))); | |
| 108 Expect.equals(false, foo.isListT(new List<Object>(5))); | |
| 109 Expect.equals(true, foo.isListT(new List<int>(5))); | |
| 110 Expect.equals(false, foo.isListT(new List<num>(5))); | |
| 111 Expect.equals(false, foo.isListT(new List<String>(5))); | |
| 112 } | |
| 113 { | |
| 114 Foo foo = new Foo<num>(); | |
| 115 Expect.equals(true, foo.isListT(new List(5))); | |
| 116 Expect.equals(false, foo.isListT(new List<Object>(5))); | |
| 117 Expect.equals(true, foo.isListT(new List<int>(5))); | |
| 118 Expect.equals(true, foo.isListT(new List<num>(5))); | |
| 119 Expect.equals(false, foo.isListT(new List<String>(5))); | |
| 120 } | |
| 121 { | |
| 122 Foo foo = new Foo<String>(); | |
| 123 Expect.equals(true, foo.isListT(new List(5))); | |
| 124 Expect.equals(false, foo.isListT(new List<Object>(5))); | |
| 125 Expect.equals(false, foo.isListT(new List<int>(5))); | |
| 126 Expect.equals(false, foo.isListT(new List<num>(5))); | |
| 127 Expect.equals(true, foo.isListT(new List<String>(5))); | |
| 128 } | |
| 129 } | |
| 130 } | |
| OLD | NEW |