dyaml/test/src/reader.d

50 lines
1.3 KiB
D
Raw Normal View History

2011-08-16 12:53:13 +00:00
// Copyright Ferdinand Majerech 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
module dyaml.testreader;
import dyaml.testcommon;
import dyaml.reader;
2014-07-21 23:13:01 +00:00
// Try reading entire stream through Reader, expecting an error (the stream is invalid).
//
// Params: verbose = Print verbose output?
// data = Stream to read.
void runReader(const bool verbose, Stream stream)
2011-08-16 12:53:13 +00:00
{
try
{
auto reader = new Reader(stream);
2014-07-21 23:13:01 +00:00
while(reader.peek() != '\0') { reader.forward(); }
2011-08-16 12:53:13 +00:00
}
catch(ReaderException e)
{
2014-07-21 23:13:01 +00:00
if(verbose) { writeln(typeid(e).toString(), "\n", e); }
2011-08-16 12:53:13 +00:00
return;
}
assert(false, "Expected an exception");
}
2014-07-21 23:13:01 +00:00
/// Stream error unittest. Tries to read invalid input streams, expecting errors.
///
/// Params: verbose = Print verbose output?
/// errorFilename = File name to read from.
2011-08-16 12:53:13 +00:00
void testStreamError(bool verbose, string errorFilename)
{
auto file = new File(errorFilename);
2014-07-21 23:13:01 +00:00
scope(exit) { file.close(); }
2011-08-16 12:53:13 +00:00
runReader(verbose, file);
}
2014-07-21 23:13:01 +00:00
unittest
2011-08-16 12:53:13 +00:00
{
writeln("D:YAML Reader unittest");
run("testStreamError", &testStreamError, ["stream-error"]);
}