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)
|
|
|
|
|
2018-02-28 00:24:05 +00:00
|
|
|
module dyaml.test.reader;
|
2011-08-16 12:53:13 +00:00
|
|
|
|
|
|
|
|
2014-08-06 12:17:07 +00:00
|
|
|
version(unittest)
|
|
|
|
{
|
|
|
|
|
2018-02-28 00:24:05 +00:00
|
|
|
import dyaml.test.common;
|
2011-08-16 12:53:13 +00:00
|
|
|
import dyaml.reader;
|
|
|
|
|
|
|
|
|
2014-07-31 00:32:23 +00:00
|
|
|
// Try reading entire file through Reader, expecting an error (the file is invalid).
|
2014-07-21 23:13:01 +00:00
|
|
|
//
|
2018-04-16 23:02:42 +00:00
|
|
|
// Params: data = Stream to read.
|
|
|
|
void runReader(ubyte[] fileData) @safe
|
2011-08-16 12:53:13 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-07-31 00:32:23 +00:00
|
|
|
auto reader = new Reader(cast(ubyte[])fileData);
|
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)
|
|
|
|
{
|
2018-04-16 23:02:42 +00:00
|
|
|
printException(e);
|
2011-08-16 12:53:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(false, "Expected an exception");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-31 00:32:23 +00:00
|
|
|
/// Stream error unittest. Tries to read invalid input files, expecting errors.
|
2014-07-21 23:13:01 +00:00
|
|
|
///
|
2018-04-16 23:02:42 +00:00
|
|
|
/// Params: errorFilename = File name to read from.
|
|
|
|
void testStreamError(string errorFilename) @safe
|
2018-03-24 00:14:35 +00:00
|
|
|
{
|
2018-04-16 23:02:42 +00:00
|
|
|
runReader(readData(errorFilename));
|
2018-03-24 00:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: remove when a @safe ubyte[] file read can be done.
|
|
|
|
ubyte[] readData(string filename) @trusted
|
2011-08-16 12:53:13 +00:00
|
|
|
{
|
2014-07-31 00:32:23 +00:00
|
|
|
import std.file;
|
2018-03-24 00:14:35 +00:00
|
|
|
return cast(ubyte[])std.file.read(filename);
|
2011-08-16 12:53:13 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 21:35:16 +00:00
|
|
|
@safe unittest
|
2011-08-16 12:53:13 +00:00
|
|
|
{
|
2018-04-30 22:11:36 +00:00
|
|
|
printProgress("D:YAML Reader unittest");
|
2011-08-16 12:53:13 +00:00
|
|
|
run("testStreamError", &testStreamError, ["stream-error"]);
|
|
|
|
}
|
2014-08-06 12:17:07 +00:00
|
|
|
|
|
|
|
} // version(unittest)
|