assertInstanceOf

Assert that a value is an instance of a type.

void
assertInstanceOf
(
A
B
)
(,
string message = "Failed asserting instance of"
,
string file = __FILE__
,
size_t line = __LINE__
)

Parameters

value B

The value used during the assertion.

message string

The error message to display.

file string

The file name where the error occurred. The value is added automatically at the call site.

line size_t

The line where the error occurred. The value is added automatically at the call site.

Throws

DUnitAssertError if the assertation fails.

Examples

interface A {}
class B : A {}
class C : B {}

auto b = new B();
auto c = new C();

b.assertInstanceOf!(Object)();
b.assertInstanceOf!(A)();
b.assertInstanceOf!(B)();

c.assertInstanceOf!(Object)();
c.assertInstanceOf!(A)();
c.assertInstanceOf!(B)();
c.assertInstanceOf!(C)();

// Assert a DUnitAssertError is thrown if assertInstanceOf fails.
b.assertInstanceOf!(C)().assertThrow!(DUnitAssertError)("Failed asserting instance of");

Meta