dyaml/source/dyaml/test/reader.d

58 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.test.reader;
2011-08-16 12:53:13 +00:00
version(unittest)
{
import dyaml.test.common;
2011-08-16 12:53:13 +00:00
import dyaml.reader;
// Try reading entire file through Reader, expecting an error (the file is invalid).
2014-07-21 23:13:01 +00:00
//
// Params: data = Stream to read.
void runReader(ubyte[] fileData) @safe
2011-08-16 12:53:13 +00:00
{
try
{
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)
{
printException(e);
2011-08-16 12:53:13 +00:00
return;
}
assert(false, "Expected an exception");
}
/// Stream error unittest. Tries to read invalid input files, expecting errors.
2014-07-21 23:13:01 +00:00
///
/// Params: errorFilename = File name to read from.
void testStreamError(string errorFilename) @safe
{
runReader(readData(errorFilename));
}
// TODO: remove when a @safe ubyte[] file read can be done.
ubyte[] readData(string filename) @trusted
2011-08-16 12:53:13 +00:00
{
import std.file;
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"]);
}
} // version(unittest)