yin parser FIX detection of extension instance
Due to xmlns definitions it's necesary to load all attributes of elements before classifying the element.
diff --git a/tests/src/test_parser_yin.c b/tests/src/test_parser_yin.c
index 9c56aa4..7a979e4 100644
--- a/tests/src/test_parser_yin.c
+++ b/tests/src/test_parser_yin.c
@@ -172,7 +172,7 @@
 
     st = reset_state(state);
     ret = yin_parse_module(st->ctx,
-                           "<module>\
+                           "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\
                             </module>",
                            st->mod);
     assert_int_equal(ret, LY_EVALID);
@@ -190,78 +190,89 @@
 static void
 test_yin_match_keyword(void **state)
 {
-    (void)state; /* unused */
+    struct state *st = *state;
 
-    assert_int_equal(yin_match_keyword("anydatax", strlen("anydatax")), YANG_NONE);
-    assert_int_equal(yin_match_keyword("asdasd", strlen("asdasd")), YANG_NONE);
-    assert_int_equal(yin_match_keyword("", 0), YANG_NONE);
-    assert_int_equal(yin_match_keyword("anydata", strlen("anydata")), YANG_ANYDATA);
-    assert_int_equal(yin_match_keyword("anyxml", strlen("anyxml")), YANG_ANYXML);
-    assert_int_equal(yin_match_keyword("argument", strlen("argument")), YANG_ARGUMENT);
-    assert_int_equal(yin_match_keyword("augment", strlen("augment")), YANG_AUGMENT);
-    assert_int_equal(yin_match_keyword("base", strlen("base")), YANG_BASE);
-    assert_int_equal(yin_match_keyword("belongs-to", strlen("belongs-to")), YANG_BELONGS_TO);
-    assert_int_equal(yin_match_keyword("bit", strlen("bit")), YANG_BIT);
-    assert_int_equal(yin_match_keyword("case", strlen("case")), YANG_CASE);
-    assert_int_equal(yin_match_keyword("choice", strlen("choice")), YANG_CHOICE);
-    assert_int_equal(yin_match_keyword("config", strlen("config")), YANG_CONFIG);
-    assert_int_equal(yin_match_keyword("contact", strlen("contact")), YANG_CONTACT);
-    assert_int_equal(yin_match_keyword("container", strlen("container")), YANG_CONTAINER);
-    assert_int_equal(yin_match_keyword("default", strlen("default")), YANG_DEFAULT);
-    assert_int_equal(yin_match_keyword("description", strlen("description")), YANG_DESCRIPTION);
-    assert_int_equal(yin_match_keyword("deviate", strlen("deviate")), YANG_DEVIATE);
-    assert_int_equal(yin_match_keyword("deviation", strlen("deviation")), YANG_DEVIATION);
-    assert_int_equal(yin_match_keyword("enum", strlen("enum")), YANG_ENUM);
-    assert_int_equal(yin_match_keyword("error-app-tag", strlen("error-app-tag")), YANG_ERROR_APP_TAG);
-    assert_int_equal(yin_match_keyword("error-message", strlen("error-message")), YANG_ERROR_MESSAGE);
-    assert_int_equal(yin_match_keyword("extension", strlen("extension")), YANG_EXTENSION);
-    assert_int_equal(yin_match_keyword("feature", strlen("feature")), YANG_FEATURE);
-    assert_int_equal(yin_match_keyword("fraction-digits", strlen("fraction-digits")), YANG_FRACTION_DIGITS);
-    assert_int_equal(yin_match_keyword("grouping", strlen("grouping")), YANG_GROUPING);
-    assert_int_equal(yin_match_keyword("identity", strlen("identity")), YANG_IDENTITY);
-    assert_int_equal(yin_match_keyword("if-feature", strlen("if-feature")), YANG_IF_FEATURE);
-    assert_int_equal(yin_match_keyword("import", strlen("import")), YANG_IMPORT);
-    assert_int_equal(yin_match_keyword("include", strlen("include")), YANG_INCLUDE);
-    assert_int_equal(yin_match_keyword("input", strlen("input")), YANG_INPUT);
-    assert_int_equal(yin_match_keyword("key", strlen("key")), YANG_KEY);
-    assert_int_equal(yin_match_keyword("leaf", strlen("leaf")), YANG_LEAF);
-    assert_int_equal(yin_match_keyword("leaf-list", strlen("leaf-list")), YANG_LEAF_LIST);
-    assert_int_equal(yin_match_keyword("length", strlen("length")), YANG_LENGTH);
-    assert_int_equal(yin_match_keyword("list", strlen("list")), YANG_LIST);
-    assert_int_equal(yin_match_keyword("mandatory", strlen("mandatory")), YANG_MANDATORY);
-    assert_int_equal(yin_match_keyword("max-elements", strlen("max-elements")), YANG_MAX_ELEMENTS);
-    assert_int_equal(yin_match_keyword("min-elements", strlen("min-elements")), YANG_MIN_ELEMENTS);
-    assert_int_equal(yin_match_keyword("modifier", strlen("modifier")), YANG_MODIFIER);
-    assert_int_equal(yin_match_keyword("module", strlen("module")), YANG_MODULE);
-    assert_int_equal(yin_match_keyword("must", strlen("must")), YANG_MUST);
-    assert_int_equal(yin_match_keyword("namespace", strlen("namespace")), YANG_NAMESPACE);
-    assert_int_equal(yin_match_keyword("notification", strlen("notification")), YANG_NOTIFICATION);
-    assert_int_equal(yin_match_keyword("ordered-by", strlen("ordered-by")), YANG_ORDERED_BY);
-    assert_int_equal(yin_match_keyword("organization", strlen("organization")), YANG_ORGANIZATION);
-    assert_int_equal(yin_match_keyword("output", strlen("output")), YANG_OUTPUT);
-    assert_int_equal(yin_match_keyword("path", strlen("path")), YANG_PATH);
-    assert_int_equal(yin_match_keyword("pattern", strlen("pattern")), YANG_PATTERN);
-    assert_int_equal(yin_match_keyword("position", strlen("position")), YANG_POSITION);
-    assert_int_equal(yin_match_keyword("prefix", strlen("prefix")), YANG_PREFIX);
-    assert_int_equal(yin_match_keyword("presence", strlen("presence")), YANG_PRESENCE);
-    assert_int_equal(yin_match_keyword("range", strlen("range")), YANG_RANGE);
-    assert_int_equal(yin_match_keyword("reference", strlen("reference")), YANG_REFERENCE);
-    assert_int_equal(yin_match_keyword("refine", strlen("refine")), YANG_REFINE);
-    assert_int_equal(yin_match_keyword("require-instance", strlen("require-instance")), YANG_REQUIRE_INSTANCE);
-    assert_int_equal(yin_match_keyword("revision", strlen("revision")), YANG_REVISION);
-    assert_int_equal(yin_match_keyword("revision-date", strlen("revision-date")), YANG_REVISION_DATE);
-    assert_int_equal(yin_match_keyword("rpc", strlen("rpc")), YANG_RPC);
-    assert_int_equal(yin_match_keyword("status", strlen("status")), YANG_STATUS);
-    assert_int_equal(yin_match_keyword("submodule", strlen("submodule")), YANG_SUBMODULE);
-    assert_int_equal(yin_match_keyword("type", strlen("type")), YANG_TYPE);
-    assert_int_equal(yin_match_keyword("typedef", strlen("typedef")), YANG_TYPEDEF);
-    assert_int_equal(yin_match_keyword("unique", strlen("unique")), YANG_UNIQUE);
-    assert_int_equal(yin_match_keyword("units", strlen("units")), YANG_UNITS);
-    assert_int_equal(yin_match_keyword("uses", strlen("uses")), YANG_USES);
-    assert_int_equal(yin_match_keyword("value", strlen("value")), YANG_VALUE);
-    assert_int_equal(yin_match_keyword("when", strlen("when")), YANG_WHEN);
-    assert_int_equal(yin_match_keyword("yang-version", strlen("yang-version")), YANG_YANG_VERSION);
-    assert_int_equal(yin_match_keyword("yin-element", strlen("yin-element")), YANG_YIN_ELEMENT);
+    const char *prefix, *name;
+    struct yin_arg_record *args = NULL;
+    size_t prefix_len, name_len;
+    /* create mock yin namespace in xml context */
+    const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
+    lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
+    yin_load_attributes(st->xml_ctx, &data, &args);
+    LY_ARRAY_FREE(args);
+
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len), YANG_NONE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len), YANG_NONE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "", 0, prefix, prefix_len), YANG_NONE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "anydata", strlen("anydata"), prefix, prefix_len), YANG_ANYDATA);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len), YANG_ANYXML);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "argument", strlen("argument"), prefix, prefix_len), YANG_ARGUMENT);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "augment", strlen("augment"), prefix, prefix_len), YANG_AUGMENT);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "base", strlen("base"), prefix, prefix_len), YANG_BASE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len), YANG_BELONGS_TO);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "bit", strlen("bit"), prefix, prefix_len), YANG_BIT);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "case", strlen("case"), prefix, prefix_len), YANG_CASE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "choice", strlen("choice"), prefix, prefix_len), YANG_CHOICE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "config", strlen("config"), prefix, prefix_len), YANG_CONFIG);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "contact", strlen("contact"), prefix, prefix_len), YANG_CONTACT);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "container", strlen("container"), prefix, prefix_len), YANG_CONTAINER);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "default", strlen("default"), prefix, prefix_len), YANG_DEFAULT);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "description", strlen("description"), prefix, prefix_len), YANG_DESCRIPTION);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "deviate", strlen("deviate"), prefix, prefix_len), YANG_DEVIATE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "deviation", strlen("deviation"), prefix, prefix_len), YANG_DEVIATION);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "enum", strlen("enum"), prefix, prefix_len), YANG_ENUM);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len), YANG_ERROR_APP_TAG);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "error-message", strlen("error-message"), prefix, prefix_len), YANG_ERROR_MESSAGE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "extension", strlen("extension"), prefix, prefix_len), YANG_EXTENSION);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "feature", strlen("feature"), prefix, prefix_len), YANG_FEATURE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "fraction-digits", strlen("fraction-digits"), prefix,  prefix_len), YANG_FRACTION_DIGITS);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "grouping", strlen("grouping"), prefix, prefix_len), YANG_GROUPING);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "identity", strlen("identity"), prefix, prefix_len), YANG_IDENTITY);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len), YANG_IF_FEATURE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "import", strlen("import"), prefix, prefix_len), YANG_IMPORT);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "include", strlen("include"), prefix, prefix_len), YANG_INCLUDE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "input", strlen("input"), prefix, prefix_len), YANG_INPUT);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "key", strlen("key"), prefix, prefix_len), YANG_KEY);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "leaf", strlen("leaf"), prefix, prefix_len), YANG_LEAF);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len), YANG_LEAF_LIST);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "length", strlen("length"), prefix, prefix_len), YANG_LENGTH);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "list", strlen("list"), prefix, prefix_len), YANG_LIST);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len), YANG_MANDATORY);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len), YANG_MAX_ELEMENTS);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len), YANG_MIN_ELEMENTS);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "modifier", strlen("modifier"), prefix, prefix_len), YANG_MODIFIER);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "module", strlen("module"), prefix, prefix_len), YANG_MODULE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "must", strlen("must"), prefix, prefix_len), YANG_MUST);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "namespace", strlen("namespace"), prefix, prefix_len), YANG_NAMESPACE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "notification", strlen("notification"), prefix, prefix_len), YANG_NOTIFICATION);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len), YANG_ORDERED_BY);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "organization", strlen("organization"), prefix, prefix_len), YANG_ORGANIZATION);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "output", strlen("output"), prefix, prefix_len), YANG_OUTPUT);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "path", strlen("path"), prefix, prefix_len), YANG_PATH);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "pattern", strlen("pattern"), prefix, prefix_len), YANG_PATTERN);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "position", strlen("position"), prefix, prefix_len), YANG_POSITION);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "prefix", strlen("prefix"), prefix, prefix_len), YANG_PREFIX);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "presence", strlen("presence"), prefix, prefix_len), YANG_PRESENCE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "range", strlen("range"), prefix, prefix_len), YANG_RANGE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "reference", strlen("reference"), prefix, prefix_len), YANG_REFERENCE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "refine", strlen("refine"), prefix, prefix_len), YANG_REFINE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len), YANG_REQUIRE_INSTANCE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "revision", strlen("revision"), prefix, prefix_len), YANG_REVISION);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len), YANG_REVISION_DATE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "rpc", strlen("rpc"), prefix, prefix_len), YANG_RPC);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "status", strlen("status"), prefix, prefix_len), YANG_STATUS);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "submodule", strlen("submodule"), prefix, prefix_len), YANG_SUBMODULE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "type", strlen("type"), prefix, prefix_len), YANG_TYPE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "typedef", strlen("typedef"), prefix, prefix_len), YANG_TYPEDEF);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "unique", strlen("unique"), prefix, prefix_len), YANG_UNIQUE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "units", strlen("units"), prefix, prefix_len), YANG_UNITS);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "uses", strlen("uses"), prefix, prefix_len), YANG_USES);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "value", strlen("value"), prefix, prefix_len), YANG_VALUE);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "when", strlen("when"), prefix, prefix_len), YANG_WHEN);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len), YANG_YANG_VERSION);
+    assert_int_equal(yin_match_keyword(st->xml_ctx, "yin-element", strlen("yin-element"), prefix, prefix_len), YANG_YIN_ELEMENT);
+
+    st->finished_correctly = true;
 }
 
 static void
@@ -319,25 +330,35 @@
     const char *res = NULL, *prefix = NULL, *name = NULL;
     size_t prefix_len = 0, name_len = 0;
     LY_ERR ret = LY_SUCCESS;
+    struct yin_arg_record *args = NULL;
 
     const char *data = "<elem>content</elem>";
     lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
-    yin_parse_text_element(st->xml_ctx, &data, &res);
+    yin_load_attributes(st->xml_ctx, &data, &args);
+    yin_parse_text_element(st->xml_ctx, &args, &data, &res);
     assert_string_equal(res, "content");
     lydict_remove(st->ctx, "content");
     st = reset_state(state);
+    LY_ARRAY_FREE(args);
+    args = NULL;
 
     data = "<elem xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">another-content</elem>";
     lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
-    yin_parse_text_element(st->xml_ctx, &data, &res);
+    yin_load_attributes(st->xml_ctx, &data, &args);
+    yin_parse_text_element(st->xml_ctx, &args, &data, &res);
     assert_string_equal(res, "another-content");
     lydict_remove(st->ctx, "another-content");
     st = reset_state(state);
+    LY_ARRAY_FREE(args);
+    args = NULL;
 
     data = "<elem invalid=\"invalid\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">text</elem>";
     lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
-    ret = yin_parse_text_element(st->xml_ctx, &data, &res);
+    yin_load_attributes(st->xml_ctx, &data, &args);
+    ret = yin_parse_text_element(st->xml_ctx, &args, &data, &res);
     assert_int_equal(ret, LY_EVALID);
+    LY_ARRAY_FREE(args);
+    args = NULL;
 
     st->finished_correctly = true;
 }
@@ -350,6 +371,7 @@
     size_t prefix_len = 0, name_len = 0;
     LY_ERR ret = LY_SUCCESS;
     struct lysp_import *imports = NULL;
+    struct yin_arg_record *args = NULL;
 
     const char *data = "<import xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" module=\"a\">\
                             <prefix value=\"a_mod\"/>\
@@ -364,7 +386,8 @@
                         </import>";
     /* first import */
     lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
-    ret = yin_parse_import(st->xml_ctx, "b-mod", &data, &imports);
+    yin_load_attributes(st->xml_ctx, &data, &args);
+    ret = yin_parse_import(st->xml_ctx, &args, "b-mod", &data, &imports);
     assert_int_equal(ret, LY_SUCCESS);
     assert_string_equal(imports->name, "a");
     assert_string_equal(imports->prefix, "a_mod");
@@ -376,31 +399,38 @@
     lydict_remove(st->ctx, imports->dsc);
     lydict_remove(st->ctx, imports->ref);
     LY_ARRAY_FREE(imports);
+    LY_ARRAY_FREE(args);
     imports = NULL;
+    args = NULL;
 
     /* second invalid import */
     lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
-    ret = yin_parse_import(st->xml_ctx, "a_mod", &data, &imports);
+    yin_load_attributes(st->xml_ctx, &data, &args);
+    ret = yin_parse_import(st->xml_ctx,  &args, "a_mod", &data, &imports);
     assert_int_equal(ret, LY_EVALID);
     logbuf_assert("Prefix \"a_mod\" already used as module prefix. Line number 1.");
     /* cleanup is supposed to be done by caller function */
     lydict_remove(st->ctx, imports->name);
     lydict_remove(st->ctx, imports->prefix);
     LY_ARRAY_FREE(imports);
-
+    LY_ARRAY_FREE(args);
     imports = NULL;
+    args = NULL;
+
     st = reset_state(state);
     /* import with unknown child element */
     data = "<import xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" module=\"a\">\
                 <what value=\"a_mod\"/>\
             </import>";
     lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
-    ret = yin_parse_import(st->xml_ctx, "invalid_mod", &data, &imports);
+    yin_load_attributes(st->xml_ctx, &data, &args);
+    ret = yin_parse_import(st->xml_ctx, &args, "invalid_mod", &data, &imports);
     assert_int_equal(ret, LY_EVALID);
     logbuf_assert("Unexpected child element \"what\" of import element.");
     /* cleanup is supposed to be done by caller function */
     lydict_remove(st->ctx, imports->name);
     LY_ARRAY_FREE(imports);
+    LY_ARRAY_FREE(args);
 
     st->finished_correctly = true;
 }
@@ -414,47 +444,61 @@
     LY_ERR ret = LY_SUCCESS;
     uint16_t flags = 0;
     struct lysp_ext_instance *exts;
+    struct yin_arg_record *args = NULL;
 
     /* try all valid values */
     const char *data = "<status value=\"current\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"/>";
     lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
-    ret = yin_parse_status(st->xml_ctx, &data, &flags, &exts);
+    yin_load_attributes(st->xml_ctx, &data, &args);
+    ret = yin_parse_status(st->xml_ctx, &args, &data, &flags, &exts);
     assert_int_equal(ret, LY_SUCCESS);
     assert_true(flags & LYS_STATUS_CURR);
+    LY_ARRAY_FREE(args);
+    args = NULL;
 
     st = reset_state(state);
     flags = 0;
     data = "<status value=\"deprecated\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"/>";
     lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
-    ret = yin_parse_status(st->xml_ctx, &data, &flags, &exts);
+    yin_load_attributes(st->xml_ctx, &data, &args);
+    ret = yin_parse_status(st->xml_ctx, &args, &data, &flags, &exts);
     assert_int_equal(ret, LY_SUCCESS);
     assert_true(flags & LYS_STATUS_DEPRC);
-    st->finished_correctly = true;
+    LY_ARRAY_FREE(args);
+    args = NULL;
 
     st = reset_state(state);
     flags = 0;
     data = "<status value=\"obsolete\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"/>";
     lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
-    ret = yin_parse_status(st->xml_ctx, &data, &flags, &exts);
+    yin_load_attributes(st->xml_ctx, &data, &args);
+    ret = yin_parse_status(st->xml_ctx, &args, &data, &flags, &exts);
     assert_int_equal(ret, LY_SUCCESS);
     assert_true(flags & LYS_STATUS_OBSLT);
-    st->finished_correctly = true;
+    LY_ARRAY_FREE(args);
+    args = NULL;
 
     /* duplicit definition (no reset_state() call) */
     data = "<status value=\"deprecated\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"/>";
     lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
-    ret = yin_parse_status(st->xml_ctx, &data, &flags, &exts);
+    yin_load_attributes(st->xml_ctx, &data, &args);
+    ret = yin_parse_status(st->xml_ctx, &args, &data, &flags, &exts);
     assert_int_equal(ret, LY_EVALID);
     logbuf_assert("Duplicate element \"status\". Line number 1.");
+    LY_ARRAY_FREE(args);
+    args = NULL;
 
     /* invalid status value */
     st = reset_state(state);
     flags = 0;
     data = "<status value=\"dunno\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"/>";
     lyxml_get_element(st->xml_ctx, &data, &prefix, &prefix_len, &name, &name_len);
-    ret = yin_parse_status(st->xml_ctx, &data, &flags, &exts);
+    yin_load_attributes(st->xml_ctx, &data, &args);
+    ret = yin_parse_status(st->xml_ctx, &args, &data, &flags, &exts);
     assert_int_equal(ret, LY_EVALID);
     logbuf_assert("Invalid value \"dunno\" of \"status\". Line number 1.");
+    LY_ARRAY_FREE(args);
+
     st->finished_correctly = true;
 }
 
@@ -468,7 +512,7 @@
         cmocka_unit_test_setup_teardown(test_yin_parse_text_element, setup_f, teardown_f),
         cmocka_unit_test_setup_teardown(test_yin_parse_import, setup_f, teardown_f),
         cmocka_unit_test_setup_teardown(test_yin_parse_status, setup_f, teardown_f),
-        cmocka_unit_test(test_yin_match_keyword),
+        cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f),
         cmocka_unit_test(test_yin_match_argument_name),
     };