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.38 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.37 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.36 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.35 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.34 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.33 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.32 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.31 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.30 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.29 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.28 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.27 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.26 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.25 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.24 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.23 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.22 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.21 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.20 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml