schema compile CHANGE support min/max-elements refine in uses
diff --git a/src/tree_schema_compile.c b/src/tree_schema_compile.c
index df6e78e..9e4f686 100644
--- a/src/tree_schema_compile.c
+++ b/src/tree_schema_compile.c
@@ -3573,6 +3573,33 @@
goto error;
}
}
+
+ /* min/max-elements */
+ if (rfn->flags & (LYS_SET_MAX | LYS_SET_MIN)) {
+ switch (node->nodetype) {
+ case LYS_LEAFLIST:
+ if (rfn->flags & LYS_SET_MAX) {
+ ((struct lysc_node_leaflist*)node)->max = rfn->max ? rfn->max : (uint32_t)-1;
+ }
+ if (rfn->flags & LYS_SET_MIN) {
+ ((struct lysc_node_leaflist*)node)->min = rfn->min;
+ }
+ break;
+ case LYS_LIST:
+ if (rfn->flags & LYS_SET_MAX) {
+ ((struct lysc_node_list*)node)->max = rfn->max ? rfn->max : (uint32_t)-1;
+ }
+ if (rfn->flags & LYS_SET_MIN) {
+ ((struct lysc_node_list*)node)->min = rfn->min;
+ }
+ break;
+ default:
+ LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_SEMANTICS,
+ "Invalid refine of %s statement in \"%s\" - %s cannot hold this statement.",
+ (rfn->flags & LYS_SET_MAX) ? "max-elements" : "min-elements", rfn->nodeid, lys_nodetype2str(node->nodetype));
+ goto error;
+ }
+ }
}
/* fix connection of the children nodes from fake context node back into the parent */
if (context_node_fake.child) {
diff --git a/tests/src/test_tree_schema_compile.c b/tests/src/test_tree_schema_compile.c
index f12b4c3..4c6920c 100644
--- a/tests/src/test_tree_schema_compile.c
+++ b/tests/src/test_tree_schema_compile.c
@@ -2325,7 +2325,7 @@
assert_non_null(mod = lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;import grp {prefix g;}"
"uses g:grp {refine c/l {default hello; config false;}"
- "refine c/ll {default hello;default world;}"
+ "refine c/ll {default hello;default world; min-elements 2; max-elements 5;}"
"refine c/ch {default b;config true;}"
"refine c/x {mandatory false; must ../ll;}"
"refine c/a {mandatory true; must 1;}"
@@ -2345,6 +2345,8 @@
assert_int_equal(2, LY_ARRAY_SIZE(((struct lysc_node_leaflist*)child)->dflts));
assert_string_equal("hello", ((struct lysc_node_leaflist*)child)->dflts[0]);
assert_string_equal("world", ((struct lysc_node_leaflist*)child)->dflts[1]);
+ assert_int_equal(2, ((struct lysc_node_leaflist*)child)->min);
+ assert_int_equal(5, ((struct lysc_node_leaflist*)child)->max);
assert_non_null(child = child->next);
assert_int_equal(LYS_CHOICE, child->nodetype);
assert_string_equal("ch", child->name);
@@ -2440,6 +2442,11 @@
assert_int_equal(LY_EVALID, lys_compile(mod, 0));
logbuf_assert("Invalid refine of must statement in \"c/ch\" - choice cannot hold any must statement.");
+ assert_non_null(mod = lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;import grp {prefix g;}"
+ "uses g:grp {refine c/x {min-elements 1;}}}", LYS_IN_YANG));
+ assert_int_equal(LY_EVALID, lys_compile(mod, 0));
+ logbuf_assert("Invalid refine of min-elements statement in \"c/x\" - leaf cannot hold this statement.");
+
*state = NULL;
ly_ctx_destroy(ctx, NULL);
}