assertEmpty

Assert that a range is empty.

  1. void assertEmpty(A array, string message = "Failed asserting empty array", string file = __FILE__, size_t line = __LINE__)
  2. void assertEmpty(R range, string message = "Failed asserting empty range", string file = __FILE__, size_t line = __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
Type: R

The range to interogate.

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 class A
2 {
3 	void popFront() {};
4 	@property bool empty() { return true; };
5 	@property int front() { return 0; };
6 }
7 
8 struct B
9 {
10 	void popFront() {};
11 	enum bool empty = false;
12 	@property int front() { return 1; };
13 }
14 
15 static assert(isInputRange!(A));
16 static assert(isInputRange!(B));
17 
18 auto emptyRange = new A();
19 emptyRange.assertEmpty();
20 
21 B infiniteRange = B.init;
22 infiniteRange.takeNone.assertEmpty();
23 
24 // Assert a DUnitAssertError is thrown if assertEmpty fails.
25 infiniteRange.assertEmpty().assertThrow!(DUnitAssertError)("Failed asserting empty range");
26 infiniteRange.take(10).assertEmpty().assertThrow!(DUnitAssertError)("Failed asserting empty range");

Meta