1 2 // Copyright Ferdinand Majerech 2011. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 module dyaml.testreader; 8 9 10 version(unittest) 11 { 12 13 import dyaml.testcommon; 14 import dyaml.reader; 15 16 17 // Try reading entire file through Reader, expecting an error (the file is invalid). 18 // 19 // Params: verbose = Print verbose output? 20 // data = Stream to read. 21 void runReader(const bool verbose, void[] fileData) 22 { 23 try 24 { 25 auto reader = new Reader(cast(ubyte[])fileData); 26 while(reader.peek() != '\0') { reader.forward(); } 27 } 28 catch(ReaderException e) 29 { 30 if(verbose) { writeln(typeid(e).toString(), "\n", e); } 31 return; 32 } 33 assert(false, "Expected an exception"); 34 } 35 36 37 /// Stream error unittest. Tries to read invalid input files, expecting errors. 38 /// 39 /// Params: verbose = Print verbose output? 40 /// errorFilename = File name to read from. 41 void testStreamError(bool verbose, string errorFilename) 42 { 43 import std.file; 44 runReader(verbose, std.file.read(errorFilename)); 45 } 46 47 unittest 48 { 49 writeln("D:YAML Reader unittest"); 50 run("testStreamError", &testStreamError, ["stream-error"]); 51 } 52 53 } // version(unittest)