Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Test various conditions around instantiating an abstract class. | |
| 6 | |
| 7 // From The Dart Programming Langauge Specification, 11.11.1 "New": | |
| 8 // If q is a constructor of an abstract class then an | |
| 9 // AbstractClassInstantiation- Error is thrown. | |
| 10 | |
| 11 | |
| 12 abstract class Interface { | |
| 13 void foo(); | |
| 14 } | |
| 15 | |
| 16 abstract class AbstractClass { | |
| 17 toString() => 'AbstractClass'; | |
| 18 } | |
| 19 | |
| 20 class ConcreteSubclass extends AbstractClass { | |
| 21 toString() => 'ConcreteSubclass'; | |
| 22 } | |
| 23 | |
| 24 class NonAbstractClass implements Interface { | |
| 25 toString() => 'NonAbstractClass'; | |
| 26 } | |
| 27 | |
| 28 Interface interface() => new Interface(); | |
| 29 | |
| 30 AbstractClass abstractClass() => new AbstractClass(); | |
| 31 | |
| 32 bool isAbstractClassInstantiationError(e) { | |
| 33 return e is AbstractClassInstantiationError; | |
| 34 } | |
| 35 | |
| 36 void main() { | |
| 37 Expect.throws(interface, isAbstractClassInstantiationError, | |
| 38 "expected AbstractClassInstantiationError"); | |
| 39 Expect.throws(abstractClass, isAbstractClassInstantiationError, | |
| 40 "expected AbstractClassInstantiationError"); | |
| 41 Expect.stringEquals('ConcreteSubclass', '${new ConcreteSubclass()}'); | |
|
bakster
2012/10/10 13:56:17
I prefer:
Expect.equals(new ConcreteSubclass() i
| |
| 42 Expect.stringEquals('NonAbstractClass', '${new NonAbstractClass()}'); | |
| 43 } | |
| OLD | NEW |