yin parser CHANGE add support for feature element
diff --git a/src/parser_yin.c b/src/parser_yin.c
index 5e4d6a4..ed4e103 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -1385,6 +1385,16 @@
return yin_parse_content(ctx, subelems, 3, data, YANG_REVISION, NULL, &rev->exts);
}
+/**
+ * @brief Parse include element.
+ *
+ * @param[in,out] ctx YIN parser context for logging and to store current state.
+ * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of current element.
+ * @param[in,out] data Data to read from, always moved to currently handled character.
+ * @param[in,out] inc_meta Meta informatinou about module/submodule name and includes to add to.
+ *
+ * @return LY_ERR values.
+ */
static LY_ERR
yin_parse_include(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data,
struct include_meta *inc_meta)
@@ -1416,6 +1426,39 @@
}
/**
+ * @brief Parse feature element.
+ *
+ * @param[in,out] ctx YIN parser context for logging and to store current state.
+ * @param[in] attrs [Sized array](@ref sizedarrays) of attributes of current element.
+ * @param[in,out] data Data to read from, always moved to currently handled character.
+ * @param[in,out] features Features to add to.
+ *
+ * @return LY_ERR values.
+ */
+static LY_ERR
+yin_parse_feature(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data,
+ struct lysp_feature **features)
+{
+ struct lysp_feature *feat;
+
+ /* allocate new feature */
+ LY_ARRAY_NEW_RET(ctx->xml_ctx.ctx, *features, feat, LY_EMEM);
+
+ /* parse argument */
+ LY_CHECK_RET(yin_parse_attribute(ctx, attrs, YIN_ARG_NAME, &feat->name, Y_IDENTIF_ARG, YANG_FEATURE));
+
+ /* parse content */
+ struct yin_subelement subelems[5] = {
+ {YANG_DESCRIPTION, &feat->dsc, YIN_SUBELEM_UNIQUE},
+ {YANG_IF_FEATURE, &feat->iffeatures, 0},
+ {YANG_REFERENCE, &feat->ref, YIN_SUBELEM_UNIQUE},
+ {YANG_STATUS, &feat->flags, YIN_SUBELEM_UNIQUE},
+ {YANG_CUSTOM, NULL, 0},
+ };
+ return yin_parse_content(ctx, subelems, 5, data, YANG_FEATURE, NULL, &feat->exts);
+}
+
+/**
* @brief Map keyword type to substatement info.
*
* @param[in] kw Keyword type.
@@ -1656,6 +1699,7 @@
ret = yin_parse_extension(ctx, attrs, data, (struct lysp_ext **)subelem->dest);
break;
case YANG_FEATURE:
+ ret = yin_parse_feature(ctx, attrs, data, (struct lysp_feature **)subelem->dest);
break;
case YANG_FRACTION_DIGITS:
ret = yin_parse_fracdigits(ctx, attrs, data, (struct lysp_type *)subelem->dest);
diff --git a/tests/src/test_parser_yin.c b/tests/src/test_parser_yin.c
index 04125c2..ce30903 100644
--- a/tests/src/test_parser_yin.c
+++ b/tests/src/test_parser_yin.c
@@ -37,6 +37,7 @@
void lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref);
void lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev);
void lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include);
+void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat);
struct state {
struct ly_ctx *ctx;
@@ -2433,6 +2434,42 @@
st->finished_correctly = true;
}
+static void
+test_feature_elem(void **state)
+{
+ struct state *st = *state;
+ const char *data;
+ struct lysp_feature *features = NULL;
+
+ /* max subelems */
+ data = ELEMENT_WRAPPER_START
+ "<feature name=\"feature-name\">"
+ "<if-feature name=\"iff\"/>"
+ "<status value=\"deprecated\"/>"
+ "<description><text>desc</text></description>"
+ "<reference><text>ref</text></reference>"
+ "</feature>"
+ ELEMENT_WRAPPER_END;
+ assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS);
+ assert_string_equal(features->name, "feature-name");
+ assert_string_equal(features->dsc, "desc");
+ assert_null(features->exts);
+ assert_true(features->flags & LYS_STATUS_DEPRC);
+ assert_string_equal(*features->iffeatures, "iff");
+ assert_string_equal(features->ref, "ref");
+ FREE_ARRAY(st->ctx, features, lysp_feature_free);
+ features = NULL;
+
+ /* min subelems */
+ data = ELEMENT_WRAPPER_START "<feature name=\"feature-name\"/>" ELEMENT_WRAPPER_END;
+ assert_int_equal(test_element_helper(st, &data, &features, NULL, NULL, true), LY_SUCCESS);
+ assert_string_equal(features->name, "feature-name");
+ FREE_ARRAY(st->ctx, features, lysp_feature_free);
+ features = NULL;
+
+ st->finished_correctly = true;
+}
+
int
main(void)
{
@@ -2491,6 +2528,7 @@
cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_element_test),
cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_element_test),
cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_element_test),
+ cmocka_unit_test_setup_teardown(test_feature_elem, setup_element_test, teardown_element_test),
};