summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/curly_parser_test.ml23
-rw-r--r--test/vytree_test.ml4
2 files changed, 25 insertions, 2 deletions
diff --git a/test/curly_parser_test.ml b/test/curly_parser_test.ml
index 7e53065..8e3d3fd 100644
--- a/test/curly_parser_test.ml
+++ b/test/curly_parser_test.ml
@@ -27,6 +27,10 @@ let config_with_comment = "foo { /* comment */ bar { } }"
let config_with_leaf_node_comment = "foo { /* comment */ bar baz; }"
let config_with_tag_node_comment = "foo { /* comment */ bar baz { } }"
+let config_with_duplicate_node = "foo { bar { baz {} } bar { baz {} } }"
+let config_with_duplicate_tag_node = "foo { bar baz0 { } bar baz0 { } }"
+let config_with_duplicate_leaf_node = "foo { bar baz; bar quux; }"
+
let parse s = Curly_parser.config Curly_lexer.token (Lexing.from_string s)
(* Empty config is considered valid, creates just the root node *)
@@ -99,6 +103,22 @@ let test_parse_with_tag test_ctxt =
assert_equal (CT.get_value config ["foo"; "bar"; "baz"; "quux"]) "xyzzy";
assert_equal (CT.get_value config ["foo"; "bar"; "qwerty"; "quux"]) "foobar"
+(* Normal nodes with duplicate children are detected *)
+let test_parse_node_duplicate_child test_ctxt =
+ try ignore @@ parse config_with_duplicate_node; assert_failure "Duplicated node child didn't cause errors"
+ with (Failure _) -> ()
+
+(* Tag nodes with duplicate children are detected *)
+let test_parse_tag_node_duplicate_child test_ctxt =
+ try ignore @@ parse config_with_duplicate_tag_node; assert_failure "Duplicated tag node child didn't cause errors"
+ with (Failure _) -> ()
+
+(* If there are duplicate leaf nodes, values of the next ones are merged into the first one,
+ the rest of the data is lost *)
+let test_parse_duplicate_leaf_node test_ctxt =
+ let config = parse config_with_duplicate_leaf_node in
+ assert_equal (CT.get_values config ["foo"; "bar"]) ["baz"; "quux"]
+
let suite =
"VyConf curly config parser tests" >::: [
@@ -116,6 +136,9 @@ let suite =
"test_parse_with_comment" >:: test_parse_with_comment;
"test_parse_with_leaf_node_comment" >:: test_parse_with_leaf_node_comment;
"test_parse_with_tag_node_comment" >:: test_parse_with_tag_node_comment;
+ "test_parse_node_duplicate_child" >:: test_parse_node_duplicate_child;
+ "test_parse_tag_node_duplicate_child" >:: test_parse_tag_node_duplicate_child;
+ "test_parse_duplicate_leaf_node" >:: test_parse_duplicate_leaf_node;
]
let () =
diff --git a/test/vytree_test.ml b/test/vytree_test.ml
index 3cf3ae6..4da2335 100644
--- a/test/vytree_test.ml
+++ b/test/vytree_test.ml
@@ -139,7 +139,7 @@ let test_merge_children_no_duplicates test_ctxt =
[make_full () "foo" [make () "bar"];
make () "bar";
make_full () "baz" [make () "quuz"]] in
- let node' = merge_children node in
+ let node' = merge_children (fun x y -> x) node in
assert_equal (list_children node') ["foo"; "bar"; "baz"]
@@ -151,7 +151,7 @@ let test_merge_children_has_duplicates test_ctxt =
[make_full () "foo" [make () "bar"];
make () "quux";
make_full () "foo" [make () "baz"]] in
- let node' = merge_children node in
+ let node' = merge_children (fun x y -> x) node in
assert_equal (list_children node') ["foo"; "quux"];
assert_equal (get node' ["foo"] |> list_children) ["bar"; "baz"]