Feasible Idea?: Range Tester
timotheecour
timothee.cour2 at gmail.com
Fri Mar 22 00:07:01 PDT 2013
>> testing that a conformant range throws a RangeError from
>> popFront when it's empty (as Nick was suggesting) would not be
>> correct at this point
ok what about the following: should work regardless it's
RangeError or an assert(0) in th eparticular implementation of a
range.
----
bool isThrown(E)(lazy E expression){
import std.exception;
import core.exception : RangeError;
try
expression();
catch(RangeError t) return true;
catch(Error t) return true;
return false;
}
unittest(){
int[]x;
assert(isThrown(x[1]));
}
----
More information about the Digitalmars-d
mailing list