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