schema compile BUGFIX leafref non-prefixed node module
... should be the same as the context node, not
current module, which is only for schema paths.
Made current module in leafref redundant and some
other minor refactoring was added.
Fixes sysrepo/sysrepo#2481
diff --git a/tests/utests/data/test_tree_data.c b/tests/utests/data/test_tree_data.c
index dc699a5..9f5e483 100644
--- a/tests/utests/data/test_tree_data.c
+++ b/tests/utests/data/test_tree_data.c
@@ -388,10 +388,10 @@
"</c></l2>";
CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
- assert_int_equal(LY_SUCCESS, ly_path_parse(UTEST_LYCTX, NULL, path_str, strlen(path_str), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_FALSE,
+ assert_int_equal(LY_SUCCESS, ly_path_parse(UTEST_LYCTX, NULL, path_str, strlen(path_str), 0, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_SIMPLE, &exp));
- assert_int_equal(LY_SUCCESS, ly_path_compile(UTEST_LYCTX, NULL, NULL, NULL, exp, LY_PATH_LREF_FALSE, LY_PATH_OPER_INPUT,
- LY_PATH_TARGET_SINGLE, LY_VALUE_JSON, NULL, NULL, &path));
+ assert_int_equal(LY_SUCCESS, ly_path_compile(UTEST_LYCTX, NULL, NULL, NULL, exp, LY_PATH_OPER_INPUT,
+ LY_PATH_TARGET_SINGLE, LY_VALUE_JSON, NULL, &path));
term = lyd_target(path, tree);
const int unsigned flag = LYS_CONFIG_R | LYS_SET_ENUM | LYS_ORDBY_USER;
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index b635fb4..75b645e 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -1477,28 +1477,28 @@
/* lys_path_parse() */
path = "invalid_path";
- assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+ assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
path = "..";
- assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+ assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
path = "..[";
- assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+ assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
path = "../";
- assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+ assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
path = "/";
- assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+ assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
path = "../../pref:id/xxx[predicate]/invalid!!!";
- assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+ assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
CHECK_LOG_CTX("Invalid character 0x21 ('!'), perhaps \"invalid\" is supposed to be a function call.", NULL);
path = "/absolute/prefix:path";
- assert_int_equal(LY_SUCCESS, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+ assert_int_equal(LY_SUCCESS, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
assert_int_equal(4, expr->used);
assert_int_equal(LYXP_TOKEN_OPER_PATH, expr->tokens[0]);
@@ -2902,18 +2902,21 @@
assert_int_equal(LY_TYPE_IDENT, leaf->type->basetype);
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module y {namespace urn:y;prefix y;"
- "container cont {leaf l {type string;}}"
- "leaf bl2 {type string;}"
+ "leaf l1 {type string;}"
+ "leaf l2 {type string;}"
"}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module z {namespace urn:z;prefix z;"
"import y {prefix y;}"
- "deviation \"/y:cont/y:l\" {deviate replace {type leafref {path \"/al\";}}}"
- "leaf al {type string;}"
- "leaf al2 {type leafref {path \"/y:bl2\";}}"
+ "deviation \"/y:l1\" {deviate replace {type leafref {path \"/l2\";}}}"
+ "deviation \"/y:l2\" {deviate replace {type leafref {path \"/z:al2\";}}}"
+ "leaf al2 {type string;}"
"}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "y")));
- assert_non_null(leaf = (struct lysc_node_leaf *)lysc_node_child(mod->compiled->data));
- assert_string_equal("l", leaf->name);
+ assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
+ assert_string_equal("l1", leaf->name);
+ assert_int_equal(LY_TYPE_LEAFREF, leaf->type->basetype);
+ leaf = (struct lysc_node_leaf *)leaf->next;
+ assert_string_equal("l2", leaf->name);
assert_int_equal(LY_TYPE_LEAFREF, leaf->type->basetype);
/* complex dependencies */