f67215f815
Review URL: https://codereview.chromium.org//11017052 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@13517 260f80e4-7a28-3924-810f-c04153c831b5
44 lines
1.3 KiB
Dart
44 lines
1.3 KiB
Dart
// 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';
|
|
}
|
|
|
|
Interface interface() => new Interface();
|
|
|
|
AbstractClass abstractClass() => new AbstractClass();
|
|
|
|
bool isAbstractClassInstantiationError(e) {
|
|
return e is AbstractClassInstantiationError;
|
|
}
|
|
|
|
void main() {
|
|
Expect.throws(interface, isAbstractClassInstantiationError,
|
|
"expected AbstractClassInstantiationError");
|
|
Expect.throws(abstractClass, isAbstractClassInstantiationError,
|
|
"expected AbstractClassInstantiationError");
|
|
Expect.stringEquals('ConcreteSubclass', '${new ConcreteSubclass()}');
|
|
Expect.stringEquals('NonAbstractClass', '${new NonAbstractClass()}');
|
|
}
|