Sha256: 58a37c2a7713bd9bba4932f4936aa2258fb9b190349159726ba8b53bcd528f66

Contents?: true

Size: 1.62 KB

Versions: 55

Compression:

Stored size: 1.62 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 = [
  "for a non special cased slug convert the parameter to a string" >:: (fun _ctx ->
      assert_equal ~printer:Fn.id "stringified" @@ ocaml_edit_expected ~stringify ~slug:"some-slug" ~value:(`Bool true)
    );

  "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")]
    );
]

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
trackler-2.2.1.19 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.18 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.17 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.16 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.15 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.14 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.13 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.12 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.11 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.10 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.9 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.8 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.7 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.6 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.5 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.4 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.3 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.2 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.1 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml
trackler-2.2.1.0 tracks/ocaml/tools/test-generator/test/ocaml_special_cases_test.ml