yin parser CHANGE add support for when element
diff --git a/src/parser_yin.c b/src/parser_yin.c
index c58e85b..cd5c433 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -720,6 +720,7 @@
                 case YANG_VALUE:
                     break;
                 case YANG_WHEN:
+                    ret = yin_parse_when(ctx, subelem_attrs, data, (struct lysp_when **)subelem_info_rec->dest);
                     break;
                 case YANG_YANG_VERSION:
                     break;
@@ -839,6 +840,21 @@
 }
 
 LY_ERR
+yin_parse_when(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data, struct lysp_when **when_p)
+{
+    struct lysp_when *when;
+    when = calloc(1, sizeof *when);
+    LY_CHECK_ERR_RET(!when, LOGMEM(ctx->xml_ctx.ctx), LY_EMEM);
+    yin_parse_attribute(ctx, &attrs, YIN_ARG_CONDITION, &when->cond, Y_STR_ARG, YANG_WHEN);
+    *when_p = when;
+    struct yin_subelement subelems[3] = {{YANG_DESCRIPTION, &when->dsc, YIN_SUBELEM_UNIQUE},
+                                         {YANG_REFERENCE, &when->ref, YIN_SUBELEM_UNIQUE},
+                                         {YANG_CUSTOM, NULL, 0}};
+
+    return yin_parse_content(ctx, subelems, 3, data, YANG_WHEN, NULL, &when->exts);
+}
+
+LY_ERR
 yin_parse_yin_element_element(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data,
                               uint16_t *flags, struct lysp_ext_instance **exts)
 {
diff --git a/src/parser_yin.h b/src/parser_yin.h
index f7b4786..a827233 100644
--- a/src/parser_yin.h
+++ b/src/parser_yin.h
@@ -158,6 +158,16 @@
                         uint16_t *flags, struct lysp_ext_instance **exts);
 
 /**
+ * @brief Parse when element.
+ *
+ * @param[in,out] ctx Yin parser context for logging and to store current state.
+ * @param[in] attrs Attributes of when element.
+ * @param[in,out] data Data to read from, always moved to currently handled character.
+ * @param[out] when_p When pointer to parse to.
+ */
+LY_ERR yin_parse_when(struct yin_parser_ctx *ctx, struct yin_arg_record *attrs, const char **data, struct lysp_when **when_p);
+
+/**
  * @brief Parse revision date element.
  *
  * @param[in,out] ctx Yin parser context for logging and to store current state.
diff --git a/tests/src/test_parser_yin.c b/tests/src/test_parser_yin.c
index ce5bbc8..80be04d 100644
--- a/tests/src/test_parser_yin.c
+++ b/tests/src/test_parser_yin.c
@@ -30,6 +30,7 @@
 /* prototypes of static functions */
 void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
 void lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext);
+void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when);
 
 struct state {
     struct ly_ctx *ctx;
@@ -671,32 +672,43 @@
                             "</extension>"
                             "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
                             "<if-feature value=\"foo\"></if-feature>"
+                            "<when condition=\"condition...\">"
+                                "<reference><text>when_ref</text></reference>"
+                                "<description><text>when_desc</text></description>"
+                            "</when>"
                         "</prefix>";
     struct lysp_ext_instance *exts = NULL;
     const char **if_features = NULL;
     struct yin_arg_record *attrs = NULL;
     const char *value;
     struct lysp_ext *ext_def = NULL;
+    struct lysp_when *when_p = NULL;
 
     lyxml_get_element(&st->yin_ctx->xml_ctx, &data, &prefix.value, &prefix.len, &name.value, &name.len);
     yin_load_attributes(st->yin_ctx, &data, &attrs);
 
-    struct yin_subelement subelems[4] = {{YANG_EXTENSION, &ext_def, 0},
+    struct yin_subelement subelems[5] = {{YANG_EXTENSION, &ext_def, 0},
                                          {YANG_IF_FEATURE, &if_features, 0},
+                                         {YANG_WHEN, &when_p, 0},
                                          {YANG_CUSTOM, NULL, 0},
                                          {YIN_TEXT, &value, 0}};
-    ret = yin_parse_content(st->yin_ctx, subelems, 4, &data, YANG_PREFIX, NULL, &exts);
+    ret = yin_parse_content(st->yin_ctx, subelems, 5, &data, YANG_PREFIX, NULL, &exts);
     assert_int_equal(ret, LY_SUCCESS);
     assert_string_equal(exts->name, "custom");
     assert_string_equal(exts->argument, "totally amazing extension");
     assert_string_equal(value, "wsefsdf");
+    assert_string_equal(when_p->cond, "condition...");
+    assert_string_equal(when_p->dsc, "when_desc");
+    assert_string_equal(when_p->ref, "when_ref");
     lysp_ext_instance_free(st->ctx, exts);
+    lysp_when_free(st->ctx, when_p);
     lysp_ext_free(st->ctx, ext_def);
     FREE_STRING(st->ctx, *if_features);
     LY_ARRAY_FREE(if_features);
     LY_ARRAY_FREE(exts);
     LY_ARRAY_FREE(ext_def);
     LY_ARRAY_FREE(attrs);
+    free(when_p);
     attrs = NULL;
     lydict_remove(st->ctx, value);
     st = reset_state(state);