Files
sdk/tests/language/abstract_runtime_error_test.dart
T
Bob Nystrom 14011f47e3 Resurrect deleted language tests.
They're back from the grave, and ready to party!

Change-Id: I088134a9be7ecabf1fbf751c015a656a15cabff9
Reviewed-on: https://dart-review.googlesource.com/12821
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: William Hesse <whesse@google.com>
2017-10-11 17:47:11 +00:00

45 lines
1.5 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.
import "package:expect/expect.dart";
// Test various conditions around instantiating an abstract class.
// From The Dart Programming Language 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(); //# 03: static type warning
}
abstract class AbstractClass {
toString() => 'AbstractClass';
}
class ConcreteSubclass extends AbstractClass {
toString() => 'ConcreteSubclass';
}
class NonAbstractClass implements Interface {
toString() => 'NonAbstractClass';
}
Interface interface() => new Interface(); //# 01: static type warning
AbstractClass abstractClass() => new AbstractClass(); //# 02: static type warning
bool isAbstractClassInstantiationError(e) {
return e is AbstractClassInstantiationError;
}
void main() {
Expect.throws(interface, isAbstractClassInstantiationError, // //# 01: continued
"expected AbstractClassInstantiationError"); // //# 01: continued
Expect.throws(abstractClass, isAbstractClassInstantiationError, // //# 02: continued
"expected AbstractClassInstantiationError"); // //# 02: continued
Expect.stringEquals('ConcreteSubclass', '${new ConcreteSubclass()}');
Expect.stringEquals('NonAbstractClass', '${new NonAbstractClass()}');
}