summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/config_tree.ml11
-rw-r--r--src/config_tree.mli6
-rw-r--r--test/config_tree_test.ml9
3 files changed, 23 insertions, 3 deletions
diff --git a/src/config_tree.ml b/src/config_tree.ml
index cdcbd1c..b97f150 100644
--- a/src/config_tree.ml
+++ b/src/config_tree.ml
@@ -7,14 +7,14 @@ exception Useless_set
type config_node_data = {
values: string list;
- comment: string;
+ comment: string option;
}
type t = config_node_data Vytree.t
let default_data = {
values = [];
- comment = "";
+ comment = None;
}
let make name = Vytree.make default_data name
@@ -77,3 +77,10 @@ let delete node path value =
| None ->
Vytree.delete node path
+let set_comment node path comment =
+ let data = Vytree.get_data node path in
+ Vytree.update node path {data with comment=comment}
+
+let get_comment node path =
+ let data = Vytree.get_data node path in
+ data.comment
diff --git a/src/config_tree.mli b/src/config_tree.mli
index 27042f8..ac9c5a9 100644
--- a/src/config_tree.mli
+++ b/src/config_tree.mli
@@ -5,7 +5,7 @@ exception Node_has_no_value
type config_node_data = {
values : string list;
- comment : string;
+ comment : string option;
}
type t = config_node_data Vytree.t
@@ -21,3 +21,7 @@ val delete : t -> string list -> string option -> t
val get_values : t -> string list -> string list
val get_value : t -> string list -> string
+
+val set_comment : t -> string list -> string option -> t
+
+val get_comment : t -> string list -> string option
diff --git a/test/config_tree_test.ml b/test/config_tree_test.ml
index dc9d239..a486249 100644
--- a/test/config_tree_test.ml
+++ b/test/config_tree_test.ml
@@ -61,6 +61,14 @@ let test_delete_subtree test_ctxt =
let node = CT.delete node ["foo"] None in
assert_equal (VT.list_children node) []
+(* Setting a node comment for an existent node should work *)
+let test_set_comment test_ctxt =
+ let path = ["foo"; "bar"] in
+ let node = CT.make "root" in
+ let node = CT.set node path None CT.AddValue in
+ let node = CT.set_comment node path (Some "comment") in
+ assert_equal (CT.get_comment node path) (Some "comment")
+
let suite =
"VyConf config tree tests" >::: [
@@ -71,6 +79,7 @@ let suite =
"test_delete_just_value" >:: test_delete_just_value;
"test_delete_last_value" >:: test_delete_last_value;
"test_delete_subtree" >:: test_delete_subtree;
+ "test_set_comment" >:: test_set_comment;
]
let () =