OCaml の Test::Simple を目コピしてみた その 3
続き。
ʕ•͡ω•ʔ TAPDocument.ml 完全目コピでけたー!
init_document
はなんか初期化しそう。
let init_document doc = let count = count_tests doc in let failures = count_test_failures doc in match doc with | Document(PlanNode(plan)::nodes) -> Document( PlanNode(plan)::nodes @ (if count = plan then [] else [ (create_count_footer count plan) ] ) @ (if failures = 0 then [] else [ (create_failure_footer count failures) ]) ) | Document(nodes) -> Document( nodes @ [ PlanNode(count) ] @ (if failures = 0 then [] else [ (create_failure_footer count failures) ]) )
後は文字列化する関数。
そんでさ、function Document(nodes) ->
は Warning 出るけど、どーすれば回避できるかわかんないって書いたけど、わかった。
let hoge Document nodes = ...
でいいみたい。
引数が複数あってわけわかんない場合は let piyo (Document nodes) =
みたいに括弧つけとこう。
let string_of_status status = match status with | OK -> "ok" | NotOk -> "not ok"
let string_of_diagnostic (Diag lines) = List.map (fun line -> "# " + line + "\n") lines |> List.fold (+) ""
let string_of_directive (Todo s) = "# TODO " + s
let string_of_node node = let emit_diagnostic diag = (match diag with | None -> "\n" | Some diag -> "\n" + (string_of_diagnostic diag)) in match node with | TestCaseNode(status, num, desc, diag) -> (string_of_status status) + " " + num.ToString() + " - " + desc + (emit_diagnostic diag) | TodoTestCaseNode(status, num, desc, dir, diag) -> (string_of_status status) + " " + num.ToString() + " - " + desc + (string_of_directive dir) + (emit_diagnostic diag) | DiagnosticNode(diag) -> (string_of_diagnostic diag) | PlanNode(count) -> "1.." + count.ToString() + "\n"
let string_of_document (Document nodes) = List.map string_of_node nodes |> String.concat ""
ここも。
全部のソースはここに置いてある。