From 5ee25afad5eb00e72a56c0f8706f8b5d81865d50 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 21 Sep 2020 13:48:30 -0400 Subject: [PATCH] test: add a test for `update` --- src/core/CCMap.ml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/core/CCMap.ml b/src/core/CCMap.ml index 03639e41..49b59b46 100644 --- a/src/core/CCMap.ml +++ b/src/core/CCMap.ml @@ -103,6 +103,10 @@ module type S = sig ?pp_sep:unit printer -> key printer -> 'a printer -> 'a t printer end +(*$inject + module M = CCMap.Make(String) +*) + module Make(O : Map.OrderedType) = struct module M = Map.Make(O) @@ -175,6 +179,15 @@ module Make(O : Map.OrderedType) = struct | None -> M.remove k m | Some v' -> M.add k v' m + (*$= & ~printer:CCFormat.(to_string @@ Dump.(list (pair string int))) + ["a", 1; "b", 20] \ + (M.of_list ["b", 2; "c", 3] \ + |> M.update "a" (function _ -> Some 1) \ + |> M.update "c" (fun _ -> None) \ + |> M.update "b" (CCOpt.map (fun x -> x * 10)) \ + |> M.to_list |> List.sort CCOrd.compare) + *) + include M let get = find_opt