1 /** 2 * Authors: Tomoya Tanjo 3 * Copyright: © 2021 Tomoya Tanjo 4 * License: Apache-2.0 5 */ 6 module cwl; 7 8 import cwl.schema; 9 10 import salad.parser : import_ = importFromURI; 11 import salad.meta : DocRootType = DocumentRootType; 12 13 alias importFromURI = import_!(cwl.schema); 14 alias DocumentRootType = DocRootType!(cwl.schema); 15 16 unittest 17 { 18 import salad.type : tryMatch; 19 import salad.util : dig; 20 import std.exception : assertNotThrown; 21 import std.path : absolutePath; 22 23 auto uri = "file://"~"examples/bwa-mem-tool.cwl".absolutePath; 24 25 auto cwl = importFromURI(uri).tryMatch!((DocumentRootType r) => r) 26 .assertNotThrown; 27 assert(cwl.tryMatch!(p => p.dig!("class", string)) 28 .assertNotThrown == "CommandLineTool"); 29 30 auto cmd = cwl.tryMatch!((CommandLineTool c) => c) 31 .assertNotThrown; 32 assert(cmd.dig!"cwlVersion"("v1.2") == "v1.0"); 33 assert(cmd.dig!(["inputs", "reference", "type"], CWLType) == "File"); 34 assert(cmd.dig!("hints", Any[])[0] 35 .as!ResourceRequirement 36 .dig!("coresMin", long) == 2); 37 } 38 39 unittest 40 { 41 import salad.type : tryMatch; 42 import salad.util : dig; 43 import std.exception : assertNotThrown; 44 import std.path : absolutePath; 45 46 auto uri = "file://"~"examples/count-lines1-wf.cwl".absolutePath; 47 auto cwl = importFromURI(uri).tryMatch!((DocumentRootType r) => r) 48 .assertNotThrown; 49 assert(cwl.tryMatch!(p => p.dig!("class", string)) 50 .assertNotThrown == "Workflow"); 51 52 auto wf = cwl.tryMatch!((Workflow w) => w) 53 .assertNotThrown; 54 assert(wf.dig!"class"("Invalid") == "Workflow"); 55 assert(wf.dig!"cwlVersion"("v1.2") == "v1.0"); 56 assert(wf.dig!(["inputs", "file1", "type"], CWLType) == "File"); 57 assert(wf.dig!(["outputs", "count_output", "outputSource"], string) == "step2/output"); 58 } 59 60 unittest 61 { 62 import salad.type : tryMatch; 63 import salad.util : dig; 64 import std.exception : assertNotThrown; 65 import std.path : absolutePath; 66 67 auto uri = "file://"~"examples/revsort-packed.cwl".absolutePath; 68 auto cwls = importFromURI(uri).tryMatch!((DocumentRootType[] rs) => rs) 69 .assertNotThrown; 70 assert(cwls.length == 3); 71 72 auto cwl = importFromURI(uri, "#main").tryMatch!((DocumentRootType r) => r) 73 .assertNotThrown; 74 assert(cwl.tryMatch!(p => p.dig!("class", string)) == "Workflow"); 75 76 auto wf = cwl.tryMatch!((Workflow w) => w) 77 .assertNotThrown; 78 assert(wf.dig!("doc", string) == "Reverse the lines in a document, then sort those lines."); 79 }