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

The associative array to interogate.

needle
Type: B

The key the array should contain.

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 ["foo":1, "bar":2, "baz":3, "qux":4].assertHasKey("foo");
2 [1:"foo", 2:"bar", 3:"baz", 4:"qux"].assertHasKey(1);
3 
4 // Assert a DUnitAssertError is thrown if assertHasKey fails.
5 ["foo":"bar"].assertHasKey("baz").assertThrow!(DUnitAssertError)("Failed asserting array has key");

Meta