summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2017-01-09 11:52:13 +0700
committerDaniil Baturin <daniil@baturin.org>2017-01-09 11:52:13 +0700
commit8377563a0d0d20f1e7f67b7cfcec4c27a02b7a3f (patch)
tree235b7f8a081b9430e9304a250fbae39b1bb4edb8 /test
parentb3afc59cfef4637dee41a595485559ff1e04193c (diff)
downloadvyconf-8377563a0d0d20f1e7f67b7cfcec4c27a02b7a3f.tar.gz
vyconf-8377563a0d0d20f1e7f67b7cfcec4c27a02b7a3f.zip
T245: add Vytree.merge_children function for de-duplicating children
that share the same name by merging subsequent nodes into the first one. Bad thing: the comments of the outer nodes will be lost, but then again one should attach them to the inner node anyway, in non-pathological cases.
Diffstat (limited to 'test')
-rw-r--r--test/vytree_test.ml25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/vytree_test.ml b/test/vytree_test.ml
index 5fb51ff..3cf3ae6 100644
--- a/test/vytree_test.ml
+++ b/test/vytree_test.ml
@@ -132,6 +132,29 @@ let test_get_data test_ctxt =
let node = insert node ["foo"; "bar"] 42 in
assert_equal (get_data node ["foo"; "bar"]) 42
+(* merge_children should have no effect if there are
+ no children with duplicate names *)
+let test_merge_children_no_duplicates test_ctxt =
+ let node = make_full () "root"
+ [make_full () "foo" [make () "bar"];
+ make () "bar";
+ make_full () "baz" [make () "quuz"]] in
+ let node' = merge_children node in
+ assert_equal (list_children node') ["foo"; "bar"; "baz"]
+
+
+(* If node has children with duplicate names, then
+ 1. Only the first should be left
+ 2. Children of all other nodes should be appended to its own *)
+let test_merge_children_has_duplicates test_ctxt =
+ let node = make_full () "root"
+ [make_full () "foo" [make () "bar"];
+ make () "quux";
+ make_full () "foo" [make () "baz"]] in
+ let node' = merge_children node in
+ assert_equal (list_children node') ["foo"; "quux"];
+ assert_equal (get node' ["foo"] |> list_children) ["bar"; "baz"]
+
let suite =
"VyConf tree tests" >::: [
"test_make_node" >:: test_make_node;
@@ -152,6 +175,8 @@ let suite =
"test_exists_existent" >:: test_exists_existent;
"test_exists_nonexistent" >:: test_exists_nonexistent;
"test_get_data" >:: test_get_data;
+ "test_merge_children_has_duplicates" >:: test_merge_children_has_duplicates;
+ "test_merge_children_no_duplicates" >:: test_merge_children_no_duplicates;
]
let () =