gedaiu / fluent-asserts

DLang fluent assertions done right
http://fluentasserts.szabobogdan.com/
MIT License
43 stars 6 forks source link

`equal` for ranges compile errors #11

Closed AntonMeep closed 7 years ago

AntonMeep commented 7 years ago

equal() called for InputRange fails on compilation This code:

struct Range {
    int n;
    int front() {
        return n;
    }
    void popFront() {
        ++n;
    }
    bool empty() {
        return n == 3;
    }
}

auto r = Range();
r.should.equal([0,1,2]);

Fails:

core/fluentasserts/core/array.d(25,49): Error: no property 'length' for type 'Range'
core/fluentasserts/core/array.d(28,55): Error: no [] operator overload for type Range
equalforranges.d(32,16): Error: template instance fluentasserts.core.array.ShouldList!(Range).ShouldList.equal!int error instantiating

But it sucessfully compiles, if I use array function from std.array:

r.array.should.equal([0,1,2]);

What about new overload of equal() for ranges? std.range.primitives can help with it. This function could just convert range to array (if range is not infinite, of course) and pass it to existing function.