tests CHANGE more leaf parsing/compilation checks according to RFC
diff --git a/src/common.h b/src/common.h
index f90ae36..55201c5 100644
--- a/src/common.h
+++ b/src/common.h
@@ -135,6 +135,7 @@
#define LY_VCODE_INSTMT LYVE_SYNTAX_YANG, "Invalid keyword \"%s\"."
#define LY_VCODE_INCHILDSTMT LYVE_SYNTAX_YANG, "Invalid keyword \"%s\" as a child of \"%s\"."
#define LY_VCODE_INCHILDSTMT2 LYVE_SYNTAX_YANG, "Invalid keyword \"%s\" as a child of \"%s\" - the statement is allowed only in YANG 1.1 modules."
+#define LY_VCODE_INCHILDSTMSCOMB LYVE_SYNTAX_YANG, "Invalid combination of keywords \"%s\" and \"%s\" as children of \"%s\"."
#define LY_VCODE_DUPSTMT LYVE_SYNTAX_YANG, "Duplicate keyword \"%s\"."
#define LY_VCODE_DUPIDENT LYVE_SYNTAX_YANG, "Duplicate identifier \"%s\" of %s statement."
#define LY_VCODE_INVAL LYVE_SYNTAX_YANG, "Invalid value \"%.*s\" of \"%s\"."
diff --git a/src/parser_yang.c b/src/parser_yang.c
index f418f24..cbac833 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -2375,6 +2375,10 @@
LOGVAL_YANG(ctx, LY_VCODE_MISSTMT, "type", "leaf");
return LY_EVALID;
}
+ if ((leaf->flags & LYS_MAND_TRUE) && (leaf->dflt)) {
+ LOGVAL_YANG(ctx, LY_VCODE_INCHILDSTMSCOMB, "mandatory", "default", "leaf");
+ return LY_EVALID;
+ }
return ret;
}
diff --git a/src/tree_schema_compile.c b/src/tree_schema_compile.c
index 62aeb99..5fc25e1 100644
--- a/src/tree_schema_compile.c
+++ b/src/tree_schema_compile.c
@@ -2661,7 +2661,7 @@
DUP_STRING(ctx->ctx, leaf_p->dflt, leaf->dflt);
ret = lys_compile_type(ctx, node_p, node_p->flags, ctx->mod->parsed, node_p->name, &leaf_p->type, options, &leaf->type,
- leaf->units ? NULL : &leaf->units, leaf->dflt ? NULL : &leaf->dflt);
+ leaf->units ? NULL : &leaf->units, leaf->dflt || (leaf->flags & LYS_MAND_TRUE) ? NULL : &leaf->dflt);
LY_CHECK_GOTO(ret, done);
if (leaf->type->basetype == LY_TYPE_LEAFREF) {
/* store to validate the path in the current context at the end of schema compiling when all the nodes are present */
@@ -2679,6 +2679,8 @@
return LY_EVALID;
}
+ /* TODO validate default value according to the type, possibly postpone the check when the leafref target is known */
+
done:
return ret;
}