Reader unittest fixes.

This commit is contained in:
Ferdinand Majerech 2014-07-22 01:13:01 +02:00
parent 9bf9a0c278
commit 405a61891f

View file

@ -11,38 +11,34 @@ import dyaml.testcommon;
import dyaml.reader; import dyaml.reader;
/** // Try reading entire stream through Reader, expecting an error (the stream is invalid).
* Try reading entire stream through Reader, expecting an error (the stream is invalid). //
* // Params: verbose = Print verbose output?
* Params: verbose = Print verbose output? // data = Stream to read.
* data = Stream to read. void runReader(const bool verbose, Stream stream)
*/
void runReader(in bool verbose, Stream stream)
{ {
try try
{ {
auto reader = new Reader(stream); auto reader = new Reader(stream);
while(reader.peek() != '\0'){reader.forward();} while(reader.peek() != '\0') { reader.forward(); }
} }
catch(ReaderException e) catch(ReaderException e)
{ {
if(verbose){writeln(typeid(e).toString(), "\n", e);} if(verbose) { writeln(typeid(e).toString(), "\n", e); }
return; return;
} }
assert(false, "Expected an exception"); assert(false, "Expected an exception");
} }
/** /// Stream error unittest. Tries to read invalid input streams, expecting errors.
* Stream error unittest. Tries to read invalid input streams, expecting errors. ///
* /// Params: verbose = Print verbose output?
* Params: verbose = Print verbose output? /// errorFilename = File name to read from.
* errorFilename = File name to read from.
*/
void testStreamError(bool verbose, string errorFilename) void testStreamError(bool verbose, string errorFilename)
{ {
auto file = new File(errorFilename); auto file = new File(errorFilename);
scope(exit){file.close();} scope(exit) { file.close(); }
runReader(verbose, file); runReader(verbose, file);
} }