Skip to content

Commit

Permalink
Manually implement show and pp for Node types.
Browse files Browse the repository at this point in the history
  • Loading branch information
zoj613 committed Jul 9, 2024
1 parent b094229 commit 3eb0420
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/node.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module GroupNode = struct
type t =
| Root
| Cons of t * string
[@@deriving show]

let create parent name =
if rep_ok name then
Expand Down Expand Up @@ -87,14 +86,16 @@ module GroupNode = struct
| _, Root -> false
| v, Cons (parent, _) -> parent = v

let show n = to_path n
let show = to_path

let pp fmt t =
Format.fprintf fmt "%s" @@ show t
end

module ArrayNode = struct
type t =
{parent : GroupNode.t
;name : string}
[@@deriving show]

let create parent name =
if rep_ok name then
Expand Down Expand Up @@ -145,4 +146,7 @@ module ArrayNode = struct
let to_metakey p = to_key p ^ "/zarr.json"

let show = to_path

let pp fmt t =
Format.fprintf fmt "%s" @@ show t
end
6 changes: 4 additions & 2 deletions test/test_node.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ let array_node = [
let s = "/some/dir/moredirs/path/pname" in
let n = ArrayNode.of_path s |> Result.get_ok in
assert_equal "pname" @@ ArrayNode.name n;
assert_equal ~printer:Fun.id s @@ ArrayNode.to_path n;
assert_equal ~printer:Fun.id s @@ ArrayNode.show n;

(* parent tests *)
assert_equal
Expand All @@ -138,8 +138,10 @@ let array_node = [
ArrayNode.parent (ArrayNode.of_path "/nodename" |> Result.get_ok);

(* equality tests *)
let n' = (ArrayNode.of_path s |> Result.get_ok) in
assert_equal
true @@ ArrayNode.(n = (ArrayNode.of_path s |> Result.get_ok));
~printer:ArrayNode.show n n';
assert_equal true ArrayNode.(n = n');
assert_equal
false @@
ArrayNode.(n = Result.get_ok @@ ArrayNode.of_path (s ^ "/more"));
Expand Down

0 comments on commit 3eb0420

Please sign in to comment.