summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2016-12-22 06:42:44 +0700
committerDaniil Baturin <daniil@baturin.org>2016-12-22 06:42:44 +0700
commit53c65bd44ace64c39bb3019cf6884e929ebc6f4d (patch)
tree33e1813e2038e8be60e85084178d428999d90301
parent245128cf5b877ecf9821d677e789d7ba9e7fe7cc (diff)
parent3e66b20e08e4c3271a13797dade33426cad3fde0 (diff)
downloadvyconf-53c65bd44ace64c39bb3019cf6884e929ebc6f4d.tar.gz
vyconf-53c65bd44ace64c39bb3019cf6884e929ebc6f4d.zip
Merge branch 'philsummers-master'
-rw-r--r--src/config_tree.ml22
-rw-r--r--src/config_tree.mli10
-rw-r--r--test/config_tree_test.ml25
3 files changed, 57 insertions, 0 deletions
diff --git a/src/config_tree.ml b/src/config_tree.ml
index b97f150..f99c737 100644
--- a/src/config_tree.ml
+++ b/src/config_tree.ml
@@ -8,6 +8,8 @@ exception Useless_set
type config_node_data = {
values: string list;
comment: string option;
+ inactive: bool;
+ ephemeral: bool;
}
type t = config_node_data Vytree.t
@@ -15,6 +17,8 @@ type t = config_node_data Vytree.t
let default_data = {
values = [];
comment = None;
+ inactive = false;
+ ephemeral = false;
}
let make name = Vytree.make default_data name
@@ -84,3 +88,21 @@ let set_comment node path comment =
let get_comment node path =
let data = Vytree.get_data node path in
data.comment
+
+let set_inactive node path inactive =
+ let data = Vytree.get_data node path in
+ Vytree.update node path {data with inactive=inactive}
+
+let is_inactive node path =
+ let data = Vytree.get_data node path in
+ data.inactive
+
+let set_ephemeral node path ephemeral =
+ let data = Vytree.get_data node path in
+ Vytree.update node path {data with ephemeral=ephemeral}
+
+let is_ephemeral node path =
+ let data = Vytree.get_data node path in
+ data.ephemeral
+
+
diff --git a/src/config_tree.mli b/src/config_tree.mli
index ac9c5a9..2c463cb 100644
--- a/src/config_tree.mli
+++ b/src/config_tree.mli
@@ -6,6 +6,8 @@ exception Node_has_no_value
type config_node_data = {
values : string list;
comment : string option;
+ inactive : bool;
+ ephemeral : bool;
}
type t = config_node_data Vytree.t
@@ -25,3 +27,11 @@ val get_value : t -> string list -> string
val set_comment : t -> string list -> string option -> t
val get_comment : t -> string list -> string option
+
+val set_inactive : t -> string list -> bool -> t
+
+val is_inactive : t -> string list -> bool
+
+val set_ephemeral : t -> string list -> bool -> t
+
+val is_ephemeral : t -> string list -> bool
diff --git a/test/config_tree_test.ml b/test/config_tree_test.ml
index a486249..7057b94 100644
--- a/test/config_tree_test.ml
+++ b/test/config_tree_test.ml
@@ -69,6 +69,28 @@ let test_set_comment test_ctxt =
let node = CT.set_comment node path (Some "comment") in
assert_equal (CT.get_comment node path) (Some "comment")
+(* Creating a node without a value should default inactive and ephemeral to false *)
+let test_valueless_node_inactive_ephemeral test_ctxt =
+ let path = ["foo"; "bar"] in
+ let node = CT.make "root" in
+ let node = CT.set node path None CT.AddValue in
+ assert_equal ((not (CT.is_inactive node path)) && (not (CT.is_ephemeral node path))) true
+
+(* Setting a node inactive should work *)
+let test_set_inactive 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_inactive node path (true) in
+ assert_equal (CT.is_inactive node path) true
+
+(* Setting a node ephemeral should work *)
+let test_set_ephemeral 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_ephemeral node path (true) in
+ assert_equal (CT.is_ephemeral node path) true
let suite =
"VyConf config tree tests" >::: [
@@ -80,6 +102,9 @@ let suite =
"test_delete_last_value" >:: test_delete_last_value;
"test_delete_subtree" >:: test_delete_subtree;
"test_set_comment" >:: test_set_comment;
+ "test_valueless_node_inactive_ephemeral" >:: test_valueless_node_inactive_ephemeral;
+ "test_set_inactive" >:: test_set_inactive;
+ "test_set_ephemeral" >:: test_set_ephemeral;
]
let () =