New loader ctor in errors unittests.

This commit is contained in:
Ferdinand Majerech 2014-07-31 03:22:13 +02:00
parent 9fe6950df0
commit 601f10bf2f

View file

@ -7,6 +7,8 @@
module dyaml.testerrors; module dyaml.testerrors;
import std.file;
import dyaml.testcommon; import dyaml.testcommon;
@ -16,11 +18,10 @@ import dyaml.testcommon;
/// errorFilename = File name to read from. /// errorFilename = File name to read from.
void testLoaderError(bool verbose, string errorFilename) void testLoaderError(bool verbose, string errorFilename)
{ {
auto file = new File(errorFilename); auto buffer = std.file.read(errorFilename);
scope(exit){file.close();}
Node[] nodes; Node[] nodes;
try{nodes = Loader(file).loadAll();} try { nodes = Loader(buffer).loadAll(); }
catch(YAMLException e) catch(YAMLException e)
{ {
if(verbose) { writeln(typeid(e).toString(), "\n", e); } if(verbose) { writeln(typeid(e).toString(), "\n", e); }
@ -35,16 +36,12 @@ void testLoaderError(bool verbose, string errorFilename)
/// errorFilename = File name to read from. /// errorFilename = File name to read from.
void testLoaderErrorString(bool verbose, string errorFilename) void testLoaderErrorString(bool verbose, string errorFilename)
{ {
//Load file to a buffer, then pass that to the YAML loader. // Load file to a buffer, then pass that to the YAML loader.
auto file = new File(errorFilename); auto buffer = std.file.read(errorFilename);
scope(exit){file.close();}
ubyte[] buffer;
buffer.length = file.available;
file.read(buffer);
try try
{ {
auto nodes = Loader(new MemoryStream(buffer)).loadAll(); auto nodes = Loader(buffer).loadAll();
} }
catch(YAMLException e) catch(YAMLException e)
{ {