| 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"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // Test various conditions around instantiating an abstract class. | 7 // Test various conditions around instantiating an abstract class. |
| 8 | 8 |
| 9 // From The Dart Programming Langauge Specification, 11.11.1 "New": | 9 // From The Dart Programming Langauge Specification, 11.11.1 "New": |
| 10 // If q is a constructor of an abstract class then an | 10 // If q is a constructor of an abstract class then an |
| 11 // AbstractClassInstantiation- Error is thrown. | 11 // AbstractClassInstantiation- Error is thrown. |
| 12 | 12 |
| 13 | 13 |
| 14 abstract class Interface { | 14 abstract class Interface { |
| 15 void foo(); /// 03: static type warning | 15 void foo(); //# 03: static type warning |
| 16 } | 16 } |
| 17 | 17 |
| 18 abstract class AbstractClass { | 18 abstract class AbstractClass { |
| 19 toString() => 'AbstractClass'; | 19 toString() => 'AbstractClass'; |
| 20 } | 20 } |
| 21 | 21 |
| 22 class ConcreteSubclass extends AbstractClass { | 22 class ConcreteSubclass extends AbstractClass { |
| 23 toString() => 'ConcreteSubclass'; | 23 toString() => 'ConcreteSubclass'; |
| 24 } | 24 } |
| 25 | 25 |
| 26 class NonAbstractClass implements Interface { | 26 class NonAbstractClass implements Interface { |
| 27 toString() => 'NonAbstractClass'; | 27 toString() => 'NonAbstractClass'; |
| 28 } | 28 } |
| 29 | 29 |
| 30 Interface interface() => new Interface(); /// 01: static type warning | 30 Interface interface() => new Interface(); //# 01: static type warning |
| 31 | 31 |
| 32 AbstractClass abstractClass() => new AbstractClass(); /// 02: static type warnin
g | 32 AbstractClass abstractClass() => new AbstractClass(); //# 02: static type warnin
g |
| 33 | 33 |
| 34 bool isAbstractClassInstantiationError(e) { | 34 bool isAbstractClassInstantiationError(e) { |
| 35 return e is AbstractClassInstantiationError; | 35 return e is AbstractClassInstantiationError; |
| 36 } | 36 } |
| 37 | 37 |
| 38 void main() { | 38 void main() { |
| 39 Expect.throws(interface, isAbstractClassInstantiationError, // /// 01: con
tinued | 39 Expect.throws(interface, isAbstractClassInstantiationError, // //# 01: con
tinued |
| 40 "expected AbstractClassInstantiationError"); // /// 01: con
tinued | 40 "expected AbstractClassInstantiationError"); // //# 01: con
tinued |
| 41 Expect.throws(abstractClass, isAbstractClassInstantiationError, // /// 02: con
tinued | 41 Expect.throws(abstractClass, isAbstractClassInstantiationError, // //# 02: con
tinued |
| 42 "expected AbstractClassInstantiationError"); // /// 02: con
tinued | 42 "expected AbstractClassInstantiationError"); // //# 02: con
tinued |
| 43 Expect.stringEquals('ConcreteSubclass', '${new ConcreteSubclass()}'); | 43 Expect.stringEquals('ConcreteSubclass', '${new ConcreteSubclass()}'); |
| 44 Expect.stringEquals('NonAbstractClass', '${new NonAbstractClass()}'); | 44 Expect.stringEquals('NonAbstractClass', '${new NonAbstractClass()}'); |
| 45 } | 45 } |
| OLD | NEW |