Skip to content

Commit 3eb0420

Browse files
committed
Manually implement show and pp for Node types.
1 parent b094229 commit 3eb0420

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/node.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ module GroupNode = struct
1212
type t =
1313
| Root
1414
| Cons of t * string
15-
[@@deriving show]
1615

1716
let create parent name =
1817
if rep_ok name then
@@ -87,14 +86,16 @@ module GroupNode = struct
8786
| _, Root -> false
8887
| v, Cons (parent, _) -> parent = v
8988

90-
let show n = to_path n
89+
let show = to_path
90+
91+
let pp fmt t =
92+
Format.fprintf fmt "%s" @@ show t
9193
end
9294

9395
module ArrayNode = struct
9496
type t =
9597
{parent : GroupNode.t
9698
;name : string}
97-
[@@deriving show]
9899

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

147148
let show = to_path
149+
150+
let pp fmt t =
151+
Format.fprintf fmt "%s" @@ show t
148152
end

test/test_node.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ let array_node = [
129129
let s = "/some/dir/moredirs/path/pname" in
130130
let n = ArrayNode.of_path s |> Result.get_ok in
131131
assert_equal "pname" @@ ArrayNode.name n;
132-
assert_equal ~printer:Fun.id s @@ ArrayNode.to_path n;
132+
assert_equal ~printer:Fun.id s @@ ArrayNode.show n;
133133

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

140140
(* equality tests *)
141+
let n' = (ArrayNode.of_path s |> Result.get_ok) in
141142
assert_equal
142-
true @@ ArrayNode.(n = (ArrayNode.of_path s |> Result.get_ok));
143+
~printer:ArrayNode.show n n';
144+
assert_equal true ArrayNode.(n = n');
143145
assert_equal
144146
false @@
145147
ArrayNode.(n = Result.get_ok @@ ArrayNode.of_path (s ^ "/more"));

0 commit comments

Comments
 (0)