assertEmpty

Assert that a range is empty.

  1. void assertEmpty(A array, string message, string file, size_t line)
  2. void assertEmpty(R range, string message, string file, size_t line)
    void
    assertEmpty
    (
    R
    )
    (,
    string message = "Failed asserting empty range"
    ,
    string file = __FILE__
    ,
    size_t line = __LINE__
    )
    if (
    (
    is(R == class) ||
    is(R == struct)
    )
    &&
    isInputRange!(R)
    )

Parameters

range R

The range to interogate.

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

class A
{
	void popFront() {};
	@property bool empty() { return true; };
	@property int front() { return 0; };
}

struct B
{
	void popFront() {};
	enum bool empty = false;
	@property int front() { return 1; };
}

static assert(isInputRange!(A));
static assert(isInputRange!(B));

auto emptyRange = new A();
emptyRange.assertEmpty();

B infiniteRange = B.init;
infiniteRange.takeNone.assertEmpty();

// Assert a DUnitAssertError is thrown if assertEmpty fails.
infiniteRange.assertEmpty().assertThrow!(DUnitAssertError)("Failed asserting empty range");
infiniteRange.take(10).assertEmpty().assertThrow!(DUnitAssertError)("Failed asserting empty range");

Meta