Chromium Code Reviews| Index: dart/tests/language/abstract_runtime_error_test.dart |
| diff --git a/dart/tests/language/abstract_runtime_error_test.dart b/dart/tests/language/abstract_runtime_error_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0b5e2980ffbf1af1cb2e12918a8e98124420d9b5 |
| --- /dev/null |
| +++ b/dart/tests/language/abstract_runtime_error_test.dart |
| @@ -0,0 +1,45 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// Test various conditions around instantiating an abstract class. |
| + |
| +// From The Dart Programming Langauge Specification, 11.11.1 "New": |
| +// If q is a constructor of an abstract class then an |
| +// AbstractClassInstantiation- Error is thrown. |
| + |
| + |
| +abstract class Interface { |
| + void foo(); |
| +} |
| + |
| +abstract class AbstractClass { |
| + toString() => 'AbstractClass'; |
| +} |
| + |
| +class ConcreteSubclass extends AbstractClass { |
| + toString() => 'ConcreteSubclass'; |
| +} |
| + |
| +class NonAbstractClass implements Interface { |
| + toString() => 'NonAbstractClass'; |
| +} |
| + |
| +void main() { |
| + try { |
|
kasperl
2012/10/10 08:43:49
Maybe use:
Expect.throws(() => new Interface(),
ahe
2012/10/10 09:27:21
Done.
|
| + new Interface(); |
| + throw 'AbstractClassInstantiationError expected'; |
| + } on AbstractClassInstantiationError { |
| + // OK |
| + } |
| + |
| + try { |
| + new AbstractClass(); |
| + throw 'AbstractClassInstantiationError expected'; |
| + } on AbstractClassInstantiationError { |
| + // OK |
| + } |
| + |
| + Expect.stringEquals('ConcreteSubclass', '${new ConcreteSubclass()}'); |
| + Expect.stringEquals('NonAbstractClass', '${new NonAbstractClass()}'); |
| +} |