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 | 4 |
5 import "package:expect/expect.dart"; | |
6 | |
7 // Dart test program for testing default factories. | 5 // Dart test program for testing default factories. |
8 | 6 |
9 abstract class Vehicle { | 7 abstract class Vehicle { |
10 factory Vehicle() = GoogleOne.Vehicle; | 8 factory Vehicle() = GoogleOne.Vehicle; |
11 } | 9 } |
12 | 10 |
13 | 11 |
14 class Bike implements Vehicle, GoogleOne { | 12 class Bike implements Vehicle, GoogleOne { |
15 Bike.redOne() {} | 13 Bike.redOne() {} |
16 } | 14 } |
17 | 15 |
18 | 16 |
19 abstract class SpaceShip { | 17 abstract class SpaceShip { |
20 factory SpaceShip() = GoogleOne; | 18 factory SpaceShip() = GoogleOne; |
21 } | 19 } |
22 | 20 |
23 | 21 |
24 class GoogleOne implements SpaceShip { | 22 class GoogleOne implements SpaceShip { |
25 GoogleOne.internal_() {} | 23 GoogleOne.internal_() {} |
26 factory GoogleOne() { return new GoogleOne.internal_(); } | 24 factory GoogleOne() { return new GoogleOne.internal_(); } |
27 factory GoogleOne.Vehicle() { return new Bike.redOne(); } | 25 factory GoogleOne.Vehicle() { return new Bike.redOne(); } |
28 } | 26 } |
29 | 27 |
30 | 28 |
31 main() { | 29 main() { |
32 Expect.equals(true, (new Bike.redOne()) is Bike); | 30 Expect.equals(true, (new Bike.redOne()) is Bike); |
33 Expect.equals(true, (new SpaceShip()) is GoogleOne); | 31 Expect.equals(true, (new SpaceShip()) is GoogleOne); |
34 Expect.equals(true, (new Vehicle()) is Bike); | 32 Expect.equals(true, (new Vehicle()) is Bike); |
35 } | 33 } |
OLD | NEW |