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
Type: B

The value used during the assertion.

message
Type: string

The error message to display.

file
Type: string

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

line
Type: size_t

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

Throws

DUnitAssertError if the assertation fails.

Examples

1 interface A {}
2 class B : A {}
3 class C : B {}
4 
5 auto b = new B();
6 auto c = new C();
7 
8 b.assertInstanceOf!(Object)();
9 b.assertInstanceOf!(A)();
10 b.assertInstanceOf!(B)();
11 
12 c.assertInstanceOf!(Object)();
13 c.assertInstanceOf!(A)();
14 c.assertInstanceOf!(B)();
15 c.assertInstanceOf!(C)();
16 
17 // Assert a DUnitAssertError is thrown if assertInstanceOf fails.
18 b.assertInstanceOf!(C)().assertThrow!(DUnitAssertError)("Failed asserting instance of");

Meta