diff --git a/src/CWL/Decode.fs b/src/CWL/Decode.fs index 26a7a108..d9d4ddd5 100644 --- a/src/CWL/Decode.fs +++ b/src/CWL/Decode.fs @@ -19,9 +19,9 @@ module Decode = { Glob = glob } ) - let outputBindingDecoder: (YAMLiciousTypes.YAMLElement -> OutputBinding) = + let outputBindingDecoder: (YAMLiciousTypes.YAMLElement -> OutputBinding option) = Decode.object(fun get -> - let outputBinding = get.Required.Field "outputBinding" outputBindingGlobDecoder + let outputBinding = get.Optional.Field "outputBinding" outputBindingGlobDecoder outputBinding ) @@ -41,6 +41,30 @@ module Decode = | _ -> failwith "Invalid CWL type" ) + let cwlTypeStringMatcher t = + match t with + | "File" -> File (FileInstance ()) + | "Directory" -> Directory (DirectoryInstance ()) + | "Dirent" -> Dirent { Entry = ""; Entryname = None; Writable = None } + | "string" -> String + | "int" -> Int + | "long" -> Long + | "float" -> Float + | "double" -> Double + | "boolean" -> Boolean + | "File[]" -> Array (File (FileInstance ())) + | "Directory[]" -> Array (Directory (DirectoryInstance ())) + | "Dirent[]" -> Array (Dirent { Entry = ""; Entryname = None; Writable = None }) + | "string[]" -> Array String + | "int[]" -> Array Int + | "long[]" -> Array Long + | "float[]" -> Array Float + | "double[]" -> Array Double + | "boolean[]" -> Array Boolean + | "stdout" -> Stdout + | "null" -> Null + | _ -> failwith "Invalid CWL type" + let cwlTypeDecoder: (YAMLiciousTypes.YAMLElement -> CWLType) = Decode.object (fun get -> let cwlType = @@ -55,28 +79,7 @@ module Decode = ) match cwlType with | Some t -> - match t with - | "File" -> File (FileInstance ()) - | "Directory" -> Directory (DirectoryInstance ()) - | "Dirent" -> Dirent { Entry = ""; Entryname = None; Writable = None } - | "string" -> String - | "int" -> Int - | "long" -> Long - | "float" -> Float - | "double" -> Double - | "boolean" -> Boolean - | "File[]" -> Array (File (FileInstance ())) - | "Directory[]" -> Array (Directory (DirectoryInstance ())) - | "Dirent[]" -> Array (Dirent { Entry = ""; Entryname = None; Writable = None }) - | "string[]" -> Array String - | "int[]" -> Array Int - | "long[]" -> Array Long - | "float[]" -> Array Float - | "double[]" -> Array Double - | "boolean[]" -> Array Boolean - | "stdout" -> Stdout - | "null" -> Null - | _ -> failwith "Invalid CWL type" + cwlTypeStringMatcher t | None -> let cwlTypeArray = get.Required.Field "type" cwlArrayTypeDecoder cwlTypeArray @@ -89,12 +92,18 @@ module Decode = for key in dict.Keys do let value = dict.[key] let outputBinding = outputBindingDecoder value - let cwlType = cwlTypeDecoder value - Output( - key, - cwlType, - outputBinding - ) + let cwlType = + match value with + | YAMLElement.Object [YAMLElement.Value v] -> cwlTypeStringMatcher v.Value + | _ -> cwlTypeDecoder value + let output = + Output( + key, + cwlType + ) + if outputBinding.IsSome then + DynObj.setValueOpt output "outputBinding" outputBinding + output |] ) @@ -258,7 +267,10 @@ module Decode = for key in dict.Keys do let value = dict.[key] let inputBinding = inputBindingDecoder value - let cwlType = cwlTypeDecoder value + let cwlType = + match value with + | YAMLElement.Object [YAMLElement.Value v] -> cwlTypeStringMatcher v.Value + | _ -> cwlTypeDecoder value let input = Input( key, diff --git a/tests/CWL/Outputs.Tests.fs b/tests/CWL/Outputs.Tests.fs index b28c3d81..f4c331b3 100644 --- a/tests/CWL/Outputs.Tests.fs +++ b/tests/CWL/Outputs.Tests.fs @@ -14,7 +14,7 @@ let decodeOutput = let testOutput = testList "outputs with basetypes and array" [ testCase "Length" <| fun _ -> - let expected = 4 + let expected = 5 let actual = decodeOutput.Length Expect.isTrue (expected = actual) @@ -43,7 +43,7 @@ let testOutput = testList "Directory" [ let directoryItem = decodeOutput.[1] testCase "Name" <| fun _ -> - let expected = "example" + let expected = "example1" let actual = directoryItem.Name Expect.isTrue (expected = actual) @@ -61,8 +61,29 @@ let testOutput = (expected = actual) $"Expected: {expected}\nActual: {actual}" ] + testList "Directory 2" [ + let directoryItem = decodeOutput.[2] + testCase "Name" <| fun _ -> + let expected = "example2" + let actual = directoryItem.Name + Expect.isTrue + (expected = actual) + $"Expected: {expected}\nActual: {actual}" + testCase "Type" <| fun _ -> + let expected = Directory (DirectoryInstance()) + let actual = directoryItem.Type.Value + Expect.isTrue + (expected = actual) + $"Expected: {expected}\nActual: {actual}" + testCase "OutputBinding" <| fun _ -> + let expected = None + let actual = directoryItem.OutputBinding + Expect.isTrue + (expected = actual) + $"Expected: {expected}\nActual: {actual}" + ] testList "File Array" [ - let fileArrayItem = decodeOutput.[2] + let fileArrayItem = decodeOutput.[3] testCase "Name" <| fun _ -> let expected = "exampleArray1" let actual = fileArrayItem.Name @@ -83,7 +104,7 @@ let testOutput = $"Expected: {expected}\nActual: {actual}" ] testList "File Array 2" [ - let fileArrayItem = decodeOutput.[3] + let fileArrayItem = decodeOutput.[4] testCase "Name" <| fun _ -> let expected = "exampleArray2" let actual = fileArrayItem.Name diff --git a/tests/TestingUtils/TestObjects.CWL/Inputs.fs b/tests/TestingUtils/TestObjects.CWL/Inputs.fs index 4e3bcb45..907617af 100644 --- a/tests/TestingUtils/TestObjects.CWL/Inputs.fs +++ b/tests/TestingUtils/TestObjects.CWL/Inputs.fs @@ -1,8 +1,7 @@ module TestObjects.CWL.Inputs let inputs ="""inputs: - arcDirectory: - type: Directory + arcDirectory: Directory firstArg: type: File inputBinding: diff --git a/tests/TestingUtils/TestObjects.CWL/Outputs.fs b/tests/TestingUtils/TestObjects.CWL/Outputs.fs index 3a0b239e..8f7f1ad3 100644 --- a/tests/TestingUtils/TestObjects.CWL/Outputs.fs +++ b/tests/TestingUtils/TestObjects.CWL/Outputs.fs @@ -5,10 +5,11 @@ let outputs ="""outputs: type: File outputBinding: glob: ./arc/runs/fsResult1/result.csv - example: + example1: type: Directory outputBinding: glob: ./arc/runs/fsResult1/example.csv + example2: Directory exampleArray1: type: File[] outputBinding: