DFortune

Unix fortune-cookie parser written in D
git clone git://xatko.vsos.ethz.ch/DFortune.git
Log | Files | Refs

commit 3c94880ac4d1aedd042a12e915d314790f2a88b8
parent 9cbe35da0343c0fad89ae5ec0ef8c3d15f528069
Author: Dominik Schmidt <das1993@hotmail.com>
Date:   Sun,  9 Aug 2015 14:31:26 +0200

Unit-tests and contracts.

Diffstat:
dfortune.d | 12+++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/dfortune.d b/dfortune.d @@ -75,7 +75,11 @@ class Fortune : RandomAccessFinite!(string){ return bigEndianToNative!(uint,uint.sizeof)(b); } - public string readFortune(uint i){ + public string readFortune(uint i) + in{ + assert(table.isOpen && content.isOpen, "Fortunes must be opened before reading"); + } + body{ uint pos=getOffset(i); uint end=getOffset(i+1)-3; //-3 to exclude \n%\n content.seek(pos); @@ -177,6 +181,9 @@ class Fortune : RandomAccessFinite!(string){ @property Fortune save(){ return clone(); } + unittest{ + static assert(isRandomAccessRange!(Fortune)); + } } struct Fortunes{ @@ -270,4 +277,7 @@ struct Fortunes{ void popFront(){ pos++; } + unittest{ + static assert(isRandomAccessRange!(Fortunes)); + } }