Sha256: 0a8b8efeab994e9dd6d09d97a3f754f3c9da3e8b60dd271cd97cdf9214c0fe6d

Contents?: true

Size: 1.81 KB

Versions: 159

Compression:

Stored size: 1.81 KB

Contents

open Core
open OUnit2
open Model
open Codegen
open Ocaml_special_cases
open Yojson.Basic

let ae exp got _ctxt = assert_equal ~printer:Fn.id exp got

let tuples_printer kvs =
  String.concat ~sep:";" @@ List.map ~f:(fun (k,v) -> "(" ^ k ^ "," ^ v ^ ")") kvs

let stringify = function
  | `Bool true -> "stringified"
  | _ -> failwith "Bad type for stringify"

let ocaml_special_cases_tests = [
  "an optional int parameter is converted to none if it matches the special value" >:: (fun _ctx ->
      assert_equal "None" @@ optional_int ~none:88 (`Int 88)
    );

  "an optional int parameter is converted to (Some value) if it does not match the special value" >:: (fun _ctx ->
      assert_equal "(Some 0)" @@ optional_int ~none:88 (`Int 0)
    );

  "default_value does not provide a default for a list that has the given key already" >:: (fun _ctx ->
      let ps = [("key", "value")] in
      assert_equal ps @@ default_value ~key:"key" ~value:"value2" ps
    );

  "default_value does provides a default for a list that does not have the given key" >:: (fun _ctx ->
      assert_equal [("key", "value")] @@ default_value ~key:"key" ~value:"value" []
    );

  "optional_strings replace value with Some(value)" >:: (fun _ctx ->
      assert_equal ~printer:tuples_printer [("key", "(Some \"value\")"); ("key2", "\"value2\"")]
        @@ optional_strings ~f:(fun x -> x = "key") [("key", `String "value"); ("key2", `String "value2")]
    );

  "option_of_null converts Null to None" >:: (fun _ctx ->
      assert_equal "None" @@ option_of_null `Null
    );
  
  "option_of_null converts String to Some" >:: (fun _ctx ->
      assert_equal "(Some \"abc\")" @@ option_of_null (`String "abc")
    );

  "option_of_null converts List to Some" >:: (fun _ctx ->
      assert_equal "(Some [1; 2; 3])" @@ option_of_null (`List [`Int 1;`Int 2;`Int 3])
    );
]

Version data entries

159 entries across 159 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.179 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.178 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.177 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.176 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.175 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.174 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.173 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.172 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.171 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.170 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.169 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.167 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.166 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.165 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.164 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.163 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.162 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.161 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.160 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml