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

The array to interogate.

needle
Type: B

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

Meta