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 // Test that instanceof works correctly with type variables. | 4 // Test that instanceof works correctly with type variables. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 // Test that partially typed generic instances are correctly constructed. | 8 // Test that partially typed generic instances are correctly constructed. |
9 | 9 |
10 // Test factory case. | 10 // Test factory case. |
11 class Foo<K, V> { | 11 class Foo<K, V> { |
12 Foo() { } | 12 Foo() {} |
13 | 13 |
14 factory Foo.fac() { | 14 factory Foo.fac() { |
15 return new Foo<K, V>(); | 15 return new Foo<K, V>(); |
16 } | 16 } |
17 | 17 |
18 FooString() { | 18 FooString() { |
19 return new Foo<K, String>.fac(); | 19 return new Foo<K, String>.fac(); |
20 } | 20 } |
21 } | 21 } |
22 | 22 |
23 // Test constructor case. | 23 // Test constructor case. |
24 class Moo<K, V> { | 24 class Moo<K, V> { |
25 Moo() { } | 25 Moo() {} |
26 | 26 |
27 MooString() { | 27 MooString() { |
28 return new Moo<K, String>(); | 28 return new Moo<K, String>(); |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 testAll () { | 32 testAll() { |
33 var foo_int_num = new Foo<int, num>(); | 33 var foo_int_num = new Foo<int, num>(); |
34 Expect.isTrue(foo_int_num is Foo<int, num>); | 34 Expect.isTrue(foo_int_num is Foo<int, num>); |
35 Expect.isTrue(foo_int_num is !Foo<int, String>); | 35 Expect.isTrue(foo_int_num is! Foo<int, String>); |
36 // foo_int_num.FooString() returns a Foo<int, String> | 36 // foo_int_num.FooString() returns a Foo<int, String> |
37 Expect.isTrue(foo_int_num.FooString() is !Foo<int, num>); | 37 Expect.isTrue(foo_int_num.FooString() is! Foo<int, num>); |
38 Expect.isTrue(foo_int_num.FooString() is Foo<int, String>); | 38 Expect.isTrue(foo_int_num.FooString() is Foo<int, String>); |
39 | 39 |
40 var foo_raw = new Foo(); | 40 var foo_raw = new Foo(); |
41 Expect.isTrue(foo_raw is Foo<int, num>); | 41 Expect.isTrue(foo_raw is Foo<int, num>); |
42 Expect.isTrue(foo_raw is Foo<int, String>); | 42 Expect.isTrue(foo_raw is Foo<int, String>); |
43 // foo_raw.FooString() returns a Foo<dynamic, String> | 43 // foo_raw.FooString() returns a Foo<dynamic, String> |
44 Expect.isTrue(foo_raw.FooString() is !Foo<int, num>); | 44 Expect.isTrue(foo_raw.FooString() is! Foo<int, num>); |
45 Expect.isTrue(foo_raw.FooString() is Foo<int, String>); | 45 Expect.isTrue(foo_raw.FooString() is Foo<int, String>); |
46 | 46 |
47 var moo_int_num = new Moo<int, num>(); | 47 var moo_int_num = new Moo<int, num>(); |
48 Expect.isTrue(moo_int_num is Moo<int, num>); | 48 Expect.isTrue(moo_int_num is Moo<int, num>); |
49 Expect.isTrue(moo_int_num is !Moo<int, String>); | 49 Expect.isTrue(moo_int_num is! Moo<int, String>); |
50 // moo_int_num.MooString() returns a Moo<int, String> | 50 // moo_int_num.MooString() returns a Moo<int, String> |
51 Expect.isTrue(moo_int_num.MooString() is !Moo<int, num>); | 51 Expect.isTrue(moo_int_num.MooString() is! Moo<int, num>); |
52 Expect.isTrue(moo_int_num.MooString() is Moo<int, String>); | 52 Expect.isTrue(moo_int_num.MooString() is Moo<int, String>); |
53 | 53 |
54 var moo_raw = new Moo(); | 54 var moo_raw = new Moo(); |
55 Expect.isTrue(moo_raw is Moo<int, num>); | 55 Expect.isTrue(moo_raw is Moo<int, num>); |
56 Expect.isTrue(moo_raw is Moo<int, String>); | 56 Expect.isTrue(moo_raw is Moo<int, String>); |
57 // moo_raw.MooString() returns a Moo<dynamic, String> | 57 // moo_raw.MooString() returns a Moo<dynamic, String> |
58 Expect.isTrue(moo_raw.MooString() is !Moo<int, num>); | 58 Expect.isTrue(moo_raw.MooString() is! Moo<int, num>); |
59 Expect.isTrue(moo_raw.MooString() is Moo<int, String>); | 59 Expect.isTrue(moo_raw.MooString() is Moo<int, String>); |
60 } | 60 } |
61 | 61 |
62 | |
63 main() { | 62 main() { |
64 // Repeat type checks so that inlined tests can be tested as well. | 63 // Repeat type checks so that inlined tests can be tested as well. |
65 for (int i = 0; i < 5; i++) { | 64 for (int i = 0; i < 5; i++) { |
66 testAll(); | 65 testAll(); |
67 } | 66 } |
68 } | 67 } |
OLD | NEW |