Sha256: 948c1604030c099822d973b05db50b553d656902cb8ac7b10a9c186e6d41c263

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

open Core.Std

open Model

let optional_int ~(none: int) = function
  | Int n when n = none -> "None"
  | Int n -> "(Some " ^ Int.to_string n ^ ")"
  | _ -> failwith "can't handle non-int parameter"

let default_value ~(key: string) ~(value: string) (parameters: (string * string) list): (string * string) list =
  if List.exists ~f:(fun (k, _) -> k = key) parameters
  then parameters
  else (key, value) :: parameters

let optional_string ~(f: string -> bool) (parameters: (string * string) list): (string * string) list =
  let replace parameter =
    let (k, v) = parameter in
    if f k
    then (k, "(Some \"" ^ v ^ "\")")
    else parameter in
  List.map ~f:replace parameters

let fixup ~(stringify: parameter -> string) ~(slug: string) ~(key: string) ~(value: parameter) = match (slug, key) with
  | ("hamming", "expected") -> optional_int (-1) value
  | _ -> stringify value

let edit ~(slug: string) (parameters: (string * string) list) = match (slug, parameters) with
  | ("hello-world", ps) -> default_value ~key:"name" ~value:"None"
    @@ optional_string ~f:(fun _x -> true)
    @@ parameters
  | (_, ps) -> ps

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trackler-2.0.1.1 tracks/ocaml/tools/test-generator/src/special_cases.ml
trackler-2.0.1.0 tracks/ocaml/tools/test-generator/src/special_cases.ml
trackler-2.0.0.10 tracks/ocaml/tools/test-generator/src/special_cases.ml