aboutsummaryrefslogtreecommitdiff
path: root/tests/test_generate.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_generate.c')
-rw-r--r--tests/test_generate.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/test_generate.c b/tests/test_generate.c
index 2b1bf8d73a3f..5c130e67499a 100644
--- a/tests/test_generate.c
+++ b/tests/test_generate.c
@@ -30,6 +30,7 @@ int
main (int argc, char **argv)
{
ucl_object_t *obj, *cur, *ar, *ref;
+ const ucl_object_t *found;
FILE *out;
unsigned char *emitted;
const char *fname_out = NULL;
@@ -114,6 +115,23 @@ main (int argc, char **argv)
cur = ucl_object_frombool (true);
ucl_object_insert_key (obj, cur, "k=3", 0, false);
+ /* Try to find using path */
+ /* Should exist */
+ found = ucl_lookup_path (obj, "key4.1");
+ assert (found != NULL && ucl_object_toint (found) == 10);
+ /* . should be ignored */
+ found = ucl_lookup_path (obj, ".key4.1");
+ assert (found != NULL && ucl_object_toint (found) == 10);
+ /* moar dots... */
+ found = ucl_lookup_path (obj, ".key4........1...");
+ assert (found != NULL && ucl_object_toint (found) == 10);
+ /* No such index */
+ found = ucl_lookup_path (obj, ".key4.3");
+ assert (found == NULL);
+ /* No such key */
+ found = ucl_lookup_path (obj, "key9..key1");
+ assert (found == NULL);
+
emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
fprintf (out, "%s\n", emitted);