assertHasKey

Assert that an associative array contains a particular key.

void
assertHasKey
(
A
B
)
(,,
string message = "Failed asserting array has key"
,
string file = __FILE__
,
size_t line = __LINE__
)
if (
isAssociativeArray!(A)
)

Parameters

haystack A

The associative array to interogate.

needle B

The key the array should contain.

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

["foo":1, "bar":2, "baz":3, "qux":4].assertHasKey("foo");
[1:"foo", 2:"bar", 3:"baz", 4:"qux"].assertHasKey(1);

// Assert a DUnitAssertError is thrown if assertHasKey fails.
["foo":"bar"].assertHasKey("baz").assertThrow!(DUnitAssertError)("Failed asserting array has key");

Meta