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 void main() { | |
| 29 try { | |
|
kasperl
2012/10/10 08:43:49
Maybe use:
Expect.throws(() => new Interface(),
ahe
2012/10/10 09:27:21
Done.
| |
| 30 new Interface(); | |
| 31 throw 'AbstractClassInstantiationError expected'; | |
| 32 } on AbstractClassInstantiationError { | |
| 33 // OK | |
| 34 } | |
| 35 | |
| 36 try { | |
| 37 new AbstractClass(); | |
| 38 throw 'AbstractClassInstantiationError expected'; | |
| 39 } on AbstractClassInstantiationError { | |
| 40 // OK | |
| 41 } | |
| 42 | |
| 43 Expect.stringEquals('ConcreteSubclass', '${new ConcreteSubclass()}'); | |
| 44 Expect.stringEquals('NonAbstractClass', '${new NonAbstractClass()}'); | |
| 45 } | |
| OLD | NEW |