1 module app; 2 3 import std.string:format; 4 5 import file2d.writer.binary; 6 import file2d.writer.text; 7 8 /// 9 enum FileType 10 { 11 binary, text 12 } 13 14 /// 15 string createModule(FileType fileType, in ubyte[] content, string moduleName, string variableName, int bytesPerLine, bool trailingComma) pure 16 { 17 import std.array; 18 19 auto ap = appender!string; 20 21 ap.put(format("module %s;\n\n", moduleName)); 22 switch(fileType) with(FileType) 23 { 24 case binary: 25 ap.put(convertToBinary(content, variableName, bytesPerLine, trailingComma)); 26 break; 27 case text: 28 ap.put(convertToText(content, variableName)); 29 break; 30 default: 31 assert(0, "Invalid File Type"); 32 } 33 34 return ap.data; 35 } 36 37 unittest 38 { 39 import std.file; 40 41 auto input = readText("test/example.txt"); 42 auto correctRes = readText("test/generatedText.d"); 43 auto generatedRes = createModule(FileType.text, cast(ubyte[])input, "generatedText", "data", 20, false); 44 45 assert(generatedRes == correctRes); 46 } 47 48 unittest 49 { 50 import std.file; 51 52 auto input = readText("test/example.txt"); 53 auto correctRes = readText("test/generatedBinary.d"); 54 auto generatedRes = createModule(FileType.binary, cast(ubyte[])input, "generatedBinary", "dataBin", 20, false); 55 56 assert(generatedRes == correctRes, format("%s",generatedRes)); 57 }