1 module dud.testdata; 2 3 import std.algorithm.iteration : filter, map, each; 4 import std.algorithm.searching : canFind; 5 import std.array : array, empty; 6 import std.format : formattedWrite; 7 import std..string : split, indexOf; 8 import std.stdio : File; 9 import std.file : exists, readText, dirEntries, SpanMode; 10 11 enum dubsdlfilename = "../dubsdlfilelist.txt"; 12 enum dubjsonfilename = "../dubjsonfilelist.txt"; 13 14 immutable string[] knownBad = [ 15 "dtiled-0.3.0/dtiled" 16 ]; 17 18 bool isKnownBad(string s) @safe pure { 19 return canFind!((string a, string b) => b.indexOf(a) == -1)(knownBad, s); 20 } 21 22 unittest { 23 assert( isKnownBad("helloWorlddtiled-3.0/dtiled")); 24 assert(!isKnownBad("helloWorlddtiled-0.3.0/dtiled")); 25 assert(!isKnownBad("../testpackages/dtiled-0.3.0/dtiled/dub.sdl")); 26 } 27 28 void writeDubSDLFileList(string[] fns) { 29 auto f = File(dubsdlfilename, "w"); 30 auto ltw = f.lockingTextWriter(); 31 fns 32 .filter!(isKnownBad) 33 .each!(it => formattedWrite(ltw, "%s\n", it)); 34 } 35 36 string[] readDubSDLFileList() { 37 return readText(dubsdlfilename) 38 .split("\n") 39 .filter!(it => !it.empty) 40 .filter!(isKnownBad) 41 .array; 42 } 43 44 string[] allDubSDLFiles() { 45 if(exists(dubsdlfilename)) { 46 return readDubSDLFileList(); 47 } 48 string[] dubs = dirEntries("../testpackages/", "dub.sdl", SpanMode.depth) 49 .map!(it => it.name) 50 .filter!(isKnownBad) 51 .array; 52 writeDubSDLFileList(dubs); 53 return dubs; 54 } 55 56 void writeDubJSONFileList(string[] fns) { 57 auto f = File(dubjsonfilename, "w"); 58 auto ltw = f.lockingTextWriter(); 59 fns 60 .filter!(isKnownBad) 61 .each!(it => formattedWrite(ltw, "%s\n", it)); 62 } 63 64 string[] readDubJSONFileList() { 65 return readText(dubjsonfilename) 66 .split("\n") 67 .filter!(it => !it.empty) 68 .filter!(isKnownBad) 69 .array; 70 } 71 72 string[] allDubJSONFiles() { 73 if(exists(dubjsonfilename)) { 74 return readDubJSONFileList(); 75 } 76 string[] dubs = dirEntries("../testpackages/", "dub.json", SpanMode.depth) 77 .map!(it => it.name) 78 .filter!(isKnownBad) 79 .array; 80 writeDubJSONFileList(dubs); 81 return dubs; 82 }