assertHasValue

Assert that an array contains a particular value.

void
assertHasValue
(
A
B
)
(,,
string message = "Failed asserting array has value"
,
string file = __FILE__
,
size_t line = __LINE__
)
if (
isArray!(A) ||
isAssociativeArray!(A)
)

Parameters

haystack A

The array to interogate.

needle B

The value 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

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

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

Meta