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