libyang REFACTOR parsed/printed bytes in in/out structs
diff --git a/tests/utests/CMakeLists.txt b/tests/utests/CMakeLists.txt
index 0d6c165..624cfdc 100644
--- a/tests/utests/CMakeLists.txt
+++ b/tests/utests/CMakeLists.txt
@@ -7,8 +7,8 @@
 ly_add_utest(NAME xpath SOURCES test_xpath.c)
 ly_add_utest(NAME yanglib SOURCES test_yanglib.c)
 ly_add_utest(NAME schema SOURCES schema/test_schema.c schema/test_schema_common.c schema/test_schema_stmts.c)
-ly_add_utest(NAME parses_yang SOURCES schema/test_parser_yang.c)
-ly_add_utest(NAME parses_yin SOURCES schema/test_parser_yin.c)
+ly_add_utest(NAME parser_yang SOURCES schema/test_parser_yang.c)
+ly_add_utest(NAME parser_yin SOURCES schema/test_parser_yin.c)
 ly_add_utest(NAME tree_schema_compile SOURCES schema/test_tree_schema_compile.c)
 ly_add_utest(NAME printer_yang SOURCES schema/test_printer_yang.c)
 ly_add_utest(NAME printer_yin SOURCES schema/test_printer_yin.c)
diff --git a/tests/utests/data/test_parser_xml.c b/tests/utests/data/test_parser_xml.c
index 20681b1..79c85f5 100644
--- a/tests/utests/data/test_parser_xml.c
+++ b/tests/utests/data/test_parser_xml.c
@@ -21,6 +21,7 @@
 #include <string.h>
 
 #include "context.h"
+#include "parser.h"
 #include "parser_data.h"
 #include "printer.h"
 #include "printer_data.h"
@@ -126,7 +127,7 @@
     struct lyd_node *tree;
     struct lyd_node_term *leaf;
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_int_equal(LYS_LEAF, tree->schema->nodetype);
     assert_string_equal("foo", tree->schema->name);
@@ -143,7 +144,7 @@
 
     /* make foo2 explicit */
     data = "<foo2 xmlns=\"urn:tests:a\">default-val</foo2>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_int_equal(LYS_LEAF, tree->schema->nodetype);
     assert_string_equal("foo2", tree->schema->name);
@@ -155,7 +156,7 @@
 
     /* parse foo2 but make it implicit */
     data = "<foo2 xmlns=\"urn:tests:a\" xmlns:wd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" wd:default=\"true\">default-val</foo2>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_int_equal(LYS_LEAF, tree->schema->nodetype);
     assert_string_equal("foo2", tree->schema->name);
@@ -187,7 +188,7 @@
         "</element1>"
         "<element1a/>"
     "</any>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_int_equal(LYS_ANYDATA, tree->schema->nodetype);
     assert_string_equal("any", tree->schema->name);
@@ -220,7 +221,7 @@
     struct lyd_node_term *leaf;
 
     /* check hashes */
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_int_equal(LYS_LIST, tree->schema->nodetype);
     assert_string_equal("l1", tree->schema->name);
@@ -232,25 +233,25 @@
 
     /* missing keys */
     data = "<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b></l1>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     logbuf_assert("List instance is missing its key \"a\". /a:l1[b='b'][c='1']");
 
     data = "<l1 xmlns=\"urn:tests:a\"><a>a</a></l1>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     logbuf_assert("List instance is missing its key \"b\". /a:l1[a='a']");
 
     data = "<l1 xmlns=\"urn:tests:a\"><b>b</b><a>a</a></l1>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     logbuf_assert("List instance is missing its key \"c\". /a:l1[a='a'][b='b']");
 
     /* key duplicate */
     data = "<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b><a>a</a><c>1</c></l1>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     logbuf_assert("Duplicate instance of \"c\". /a:l1[a='a'][b='b'][c='1'][c='1']/c");
 
     /* keys order */
     data = "<l1 xmlns=\"urn:tests:a\"><d>d</d><a>a</a><c>1</c><b>b</b></l1>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_int_equal(LYS_LIST, tree->schema->nodetype);
     assert_string_equal("l1", tree->schema->name);
@@ -267,7 +268,7 @@
     lyd_free_all(tree);
 
     data = "<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b><a>a</a></l1>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_int_equal(LYS_LIST, tree->schema->nodetype);
     assert_string_equal("l1", tree->schema->name);
@@ -282,7 +283,7 @@
     logbuf_clean();
     lyd_free_all(tree);
 
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_PARSE_STRICT, 0, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_STRICT, 0, &tree));
     logbuf_assert("Invalid position of the key \"b\" in a list. Line number 1.");
 
     *state = NULL;
@@ -297,7 +298,7 @@
     struct lyd_node *tree;
     struct lyd_node_inner *cont;
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_int_equal(LYS_CONTAINER, tree->schema->nodetype);
     assert_string_equal("c", tree->schema->name);
@@ -306,7 +307,7 @@
     lyd_free_all(tree);
 
     data = "<cp xmlns=\"urn:tests:a\"/>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_int_equal(LYS_CONTAINER, tree->schema->nodetype);
     assert_string_equal("cp", tree->schema->name);
@@ -331,12 +332,12 @@
 
     /* invalid value, no flags */
     data = "<foo3 xmlns=\"urn:tests:a\"/>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     logbuf_assert("Invalid empty uint32 value. /a:foo3");
     assert_null(tree);
 
     /* opaq flag */
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_null(tree->schema);
     assert_string_equal(((struct lyd_node_opaq *)tree)->name, "foo3");
@@ -349,12 +350,12 @@
 
     /* missing key, no flags */
     data = "<l1 xmlns=\"urn:tests:a\"><a>val_a</a><b>val_b</b><d>val_d</d></l1>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     logbuf_assert("List instance is missing its key \"c\". /a:l1[a='val_a'][b='val_b']");
     assert_null(tree);
 
     /* opaq flag */
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_OPAQ , LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_OPAQ , LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_null(tree->schema);
     assert_string_equal(((struct lyd_node_opaq *)tree)->name, "l1");
@@ -367,12 +368,12 @@
 
     /* invalid key, no flags */
     data = "<l1 xmlns=\"urn:tests:a\"><a>val_a</a><b>val_b</b><c>val_c</c></l1>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     logbuf_assert("Invalid int16 value \"val_c\". /a:l1/c");
     assert_null(tree);
 
     /* opaq flag */
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_null(tree->schema);
     assert_string_equal(((struct lyd_node_opaq *)tree)->name, "l1");
@@ -384,7 +385,8 @@
     lyd_free_all(tree);
 
     /* opaq flag and fail */
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, "<a xmlns=\"ns\"><b>x</b><c xml:id=\"D\">1</c></a>", LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, "<a xmlns=\"ns\"><b>x</b><c xml:id=\"D\">1</c></a>", LYD_XML,
+                                                   LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
 
     ly_out_free(out, NULL, 1);
@@ -398,6 +400,7 @@
     *state = test_rpc;
 
     const char *data;
+    struct ly_in *in;
     char *str;
     struct lyd_node *tree, *op;
     const struct lyd_node *node;
@@ -423,7 +426,9 @@
                 "</config>"
             "</edit-config>"
         "</rpc>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &tree, &op));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &tree, &op));
+    ly_in_free(in, 0);
 
     assert_non_null(op);
     assert_string_equal(op->schema->name, "edit-config");
@@ -484,6 +489,7 @@
     *state = test_action;
 
     const char *data;
+    struct ly_in *in;
     char *str;
     struct lyd_node *tree, *op;
     const struct lyd_node *node;
@@ -501,7 +507,9 @@
                 "</c>"
             "</action>"
         "</rpc>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &tree, &op));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &tree, &op));
+    ly_in_free(in, 0);
 
     assert_non_null(op);
     assert_string_equal(op->schema->name, "act");
@@ -543,6 +551,7 @@
     *state = test_notification;
 
     const char *data;
+    struct ly_in *in;
     char *str;
     struct lyd_node *tree, *ntf;
     const struct lyd_node *node;
@@ -559,7 +568,9 @@
                 "</n1>"
             "</c>"
         "</notification>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_notif(ctx, data, &tree, &ntf));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+    assert_int_equal(LY_SUCCESS, lyd_parse_notif(ctx, in, LYD_XML, &tree, &ntf));
+    ly_in_free(in, 0);
 
     assert_non_null(ntf);
     assert_string_equal(ntf->schema->name, "n1");
@@ -584,7 +595,9 @@
 
     /* top-level notif without envelope */
     data = "<n2 xmlns=\"urn:tests:a\"/>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_notif(ctx, data, &tree, &ntf));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+    assert_int_equal(LY_SUCCESS, lyd_parse_notif(ctx, in, LYD_XML, &tree, &ntf));
+    ly_in_free(in, 0);
 
     assert_non_null(ntf);
     assert_string_equal(ntf->schema->name, "n2");
@@ -611,6 +624,7 @@
     *state = test_reply;
 
     const char *data;
+    struct ly_in *in;
     char *str;
     struct lyd_node *request, *tree, *op;
     const struct lyd_node *node;
@@ -624,12 +638,17 @@
                 "<al>value</al>"
             "</act>"
         "</c>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &request, NULL));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &request, NULL));
+    ly_in_free(in, 0);
+
     data =
         "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" msgid=\"25\">"
             "<al xmlns=\"urn:tests:a\">25</al>"
         "</rpc-reply>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_reply(request, data, &tree, &op));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+    assert_int_equal(LY_SUCCESS, lyd_parse_reply(request, in, LYD_XML, &tree, &op));
+    ly_in_free(in, 0);
     lyd_free_all(request);
 
     assert_non_null(op);
diff --git a/tests/utests/data/test_printer_xml.c b/tests/utests/data/test_printer_xml.c
index e972808..7f44fb4 100644
--- a/tests/utests/data/test_printer_xml.c
+++ b/tests/utests/data/test_printer_xml.c
@@ -178,7 +178,6 @@
     const char *data;
     const char *result;
     char *printed;
-    ssize_t len;
     struct ly_out *out;
 
     s->func = test_leaf;
@@ -187,8 +186,8 @@
     data = "<int8 xmlns=\"urn:tests:types\">\n 15 \t\n  </int8>";
     result = "<int8 xmlns=\"urn:tests:types\">15</int8>";
     assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_true((len = lyd_print(out, tree, LYD_XML, 0)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, 0));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     assert_string_equal(printed, result);
     lyd_free_all(tree);
 
@@ -203,7 +202,6 @@
     struct lyd_node *tree;
     const char *data;
     char *printed;
-    ssize_t len;
     struct ly_out *out;
 
     s->func = test_anydata;
@@ -211,8 +209,8 @@
 
     data = "<any xmlns=\"urn:tests:types\"><somexml xmlns:x=\"url:x\" xmlns=\"example.com\"><x:x/></somexml></any>";
     assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_true((len = lyd_print(out, tree, LYD_XML, 0)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, 0));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     /* canonized */
     data = "<any xmlns=\"urn:tests:types\"><somexml xmlns=\"example.com\"><x xmlns=\"url:x\"/></somexml></any>";
     assert_string_equal(printed, data);
@@ -221,8 +219,8 @@
 
     data = "<any xmlns=\"urn:tests:types\"/>";
     assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_true((len = lyd_print(out, tree, LYD_XML, 0)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, 0));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     assert_string_equal(printed, data);
     ly_out_reset(out);
     lyd_free_all(tree);
@@ -243,8 +241,8 @@
     assert_string_equal(((struct lyd_node_any *)tree)->value.tree->schema->name, "cont");
     /* but its children not */
     assert_null(((struct lyd_node_inner *)(((struct lyd_node_any *)tree)->value.tree))->child->schema);
-    assert_true((len = lyd_print(out, tree, LYD_XML, 0)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, 0));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     /* canonized */
     data =
         "<any xmlns=\"urn:tests:types\">"
@@ -271,7 +269,6 @@
     struct lyd_node *tree;
     const char *data;
     char *printed;
-    ssize_t len;
     struct ly_out *out;
 
     s->func = test_defaults;
@@ -282,27 +279,27 @@
     data = "<c xmlns=\"urn:defaults\">aa</c>";
     assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
 
-    assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     assert_string_equal(printed, data);
     ly_out_reset(out);
 
-    assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a>";
     assert_string_equal(printed, data);
     ly_out_reset(out);
 
-    assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     data = "<c xmlns=\"urn:defaults\">aa</c>"
         "<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
         " ncwd:default=\"true\" xmlns:d=\"urn:defaults\">/d:b</a>";
     assert_string_equal(printed, data);
     ly_out_reset(out);
 
-    assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     data = "<c xmlns=\"urn:defaults\">aa</c>"
         "<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
         " ncwd:default=\"true\" xmlns:d=\"urn:defaults\">/d:b</a>";
@@ -315,23 +312,23 @@
     data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\">/d:b</a>";
     assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
 
-    assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     assert_string_equal(printed, data);
     ly_out_reset(out);
 
-    assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     assert_string_equal(printed, data);
     ly_out_reset(out);
 
-    assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     assert_string_equal(printed, data);
     ly_out_reset(out);
 
-    assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     assert_string_equal(printed, data);
     ly_out_reset(out);
 
@@ -341,20 +338,20 @@
     data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b>";
     assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
 
-    assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     data = "<c xmlns=\"urn:defaults\">aa</c><b xmlns=\"urn:defaults\">val</b>";
     assert_string_equal(printed, data);
     ly_out_reset(out);
 
-    assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b>";
     assert_string_equal(printed, data);
     ly_out_reset(out);
 
-    assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     data = "<c xmlns=\"urn:defaults\">aa</c>"
         "<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
         " ncwd:default=\"true\" xmlns:d=\"urn:defaults\">/d:b</a>"
@@ -362,8 +359,8 @@
     assert_string_equal(printed, data);
     ly_out_reset(out);
 
-    assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG)) >= 0);
-    assert_int_equal(len, strlen(printed));
+    assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG));
+    assert_int_equal(strlen(printed), ly_out_printed(out));
     data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b>";
     assert_string_equal(printed, data);
     ly_out_reset(out);
diff --git a/tests/utests/data/test_validation.c b/tests/utests/data/test_validation.c
index f80ce9f..cd05191 100644
--- a/tests/utests/data/test_validation.c
+++ b/tests/utests/data/test_validation.c
@@ -21,6 +21,7 @@
 #include <string.h>
 
 #include "context.h"
+#include "parser.h"
 #include "parser_data.h"
 #include "printer.h"
 #include "printer_data.h"
@@ -477,19 +478,19 @@
     struct lyd_node *tree;
 
     data = "<c xmlns=\"urn:tests:a\">hey</c>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("When condition \"/cont/b = 'val_b'\" not satisfied. /a:c");
 
     data = "<cont xmlns=\"urn:tests:a\"><b>val_b</b></cont><c xmlns=\"urn:tests:a\">hey</c>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_string_equal("c", tree->next->schema->name);
     assert_int_equal(LYD_WHEN_TRUE, tree->next->flags);
     lyd_free_all(tree);
 
     data = "<cont xmlns=\"urn:tests:a\"><a>val</a><b>val_b</b></cont><c xmlns=\"urn:tests:a\">val_c</c>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     assert_string_equal("a", lyd_node_children(tree, 0)->schema->name);
     assert_int_equal(LYD_WHEN_TRUE, lyd_node_children(tree, 0)->flags);
@@ -509,22 +510,22 @@
     struct lyd_node *tree;
 
     data = "<d xmlns=\"urn:tests:b\"/>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Mandatory node \"choic\" instance does not exist. /b:choic");
 
     data = "<l xmlns=\"urn:tests:b\">string</l><d xmlns=\"urn:tests:b\"/>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Mandatory node \"c\" instance does not exist. /b:c");
 
     data = "<a xmlns=\"urn:tests:b\">string</a>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Mandatory node \"c\" instance does not exist. /b:c");
 
     data = "<a xmlns=\"urn:tests:b\">string</a><c xmlns=\"urn:tests:b\">string2</c>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     lyd_free_siblings(tree);
 
@@ -540,14 +541,14 @@
     struct lyd_node *tree;
 
     data = "<d xmlns=\"urn:tests:c\"/>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Too few \"l\" instances. /c:choic/b/l");
 
     data =
     "<l xmlns=\"urn:tests:c\">val1</l>"
     "<l xmlns=\"urn:tests:c\">val2</l>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Too few \"l\" instances. /c:choic/b/l");
 
@@ -555,7 +556,7 @@
     "<l xmlns=\"urn:tests:c\">val1</l>"
     "<l xmlns=\"urn:tests:c\">val2</l>"
     "<l xmlns=\"urn:tests:c\">val3</l>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     lyd_free_siblings(tree);
 
@@ -568,7 +569,7 @@
     "<lt xmlns=\"urn:tests:c\"><k>val3</k></lt>"
     "<lt xmlns=\"urn:tests:c\"><k>val4</k></lt>"
     "<lt xmlns=\"urn:tests:c\"><k>val5</k></lt>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Too many \"lt\" instances. /c:lt");
 
@@ -591,7 +592,7 @@
     "<lt xmlns=\"urn:tests:d\">"
         "<k>val2</k>"
     "</lt>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     lyd_free_siblings(tree);
 
@@ -604,7 +605,7 @@
         "<k>val2</k>"
         "<l1>not-same</l1>"
     "</lt>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     lyd_free_siblings(tree);
 
@@ -617,7 +618,7 @@
         "<k>val2</k>"
         "<l1>same</l1>"
     "</lt>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Unique data leaf(s) \"l1\" not satisfied in \"/d:lt[k='val1']\" and \"/d:lt[k='val2']\". /d:lt[k='val2']");
 
@@ -655,7 +656,7 @@
         "<k>val8</k>"
         "<l1>8</l1>"
     "</lt>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     lyd_free_siblings(tree);
 
@@ -689,7 +690,7 @@
     "<lt xmlns=\"urn:tests:d\">"
         "<k>val8</k>"
     "</lt>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     lyd_free_siblings(tree);
 
@@ -723,7 +724,7 @@
         "<k>val8</k>"
         "<l1>8</l1>"
     "</lt>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Unique data leaf(s) \"l1\" not satisfied in \"/d:lt[k='val7']\" and \"/d:lt[k='val2']\". /d:lt[k='val2']");
 
@@ -795,7 +796,7 @@
             "<l3>3</l3>"
         "</lt3>"
     "</lt2>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     lyd_free_siblings(tree);
 
@@ -856,7 +857,7 @@
             "<l3>3</l3>"
         "</lt3>"
     "</lt2>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Unique data leaf(s) \"l3\" not satisfied in \"/d:lt2[k='val2']/lt3[kk='val3']\" and"
                   " \"/d:lt2[k='val2']/lt3[kk='val1']\". /d:lt2[k='val2']/lt3[kk='val1']");
@@ -897,7 +898,7 @@
         "</cont>"
         "<l4>5</l4>"
     "</lt2>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Unique data leaf(s) \"cont/l2 l4\" not satisfied in \"/d:lt2[k='val4']\" and \"/d:lt2[k='val2']\". /d:lt2[k='val2']");
 
@@ -945,7 +946,7 @@
         "<l5>3</l5>"
         "<l6>3</l6>"
     "</lt2>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Unique data leaf(s) \"l5 l6\" not satisfied in \"/d:lt2[k='val5']\" and \"/d:lt2[k='val3']\". /d:lt2[k='val3']");
 
@@ -961,51 +962,51 @@
     struct lyd_node *tree;
 
     data = "<d xmlns=\"urn:tests:e\">25</d><d xmlns=\"urn:tests:e\">50</d>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Duplicate instance of \"d\". /e:d");
 
     data = "<lt xmlns=\"urn:tests:e\"><k>A</k></lt><lt xmlns=\"urn:tests:e\"><k>B</k></lt><lt xmlns=\"urn:tests:e\"><k>A</k></lt>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Duplicate instance of \"lt\". /e:lt[k='A']");
 
     data = "<ll xmlns=\"urn:tests:e\">A</ll><ll xmlns=\"urn:tests:e\">B</ll><ll xmlns=\"urn:tests:e\">B</ll>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Duplicate instance of \"ll\". /e:ll[.='B']");
 
     data = "<cont xmlns=\"urn:tests:e\"></cont><cont xmlns=\"urn:tests:e\"/>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Duplicate instance of \"cont\". /e:cont");
 
     /* same tests again but using hashes */
     data = "<cont xmlns=\"urn:tests:e\"><d>25</d><d>50</d><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll></cont>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Duplicate instance of \"d\". /e:cont/d");
 
     data = "<cont xmlns=\"urn:tests:e\"><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll>"
         "<lt><k>a</k></lt><lt><k>b</k></lt><lt><k>c</k></lt><lt><k>d</k></lt><lt><k>c</k></lt></cont>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Duplicate instance of \"lt\". /e:cont/lt[k='c']");
 
     data = "<cont xmlns=\"urn:tests:e\"><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll>"
         "<ll>a</ll><ll>b</ll><ll>c</ll><ll>d</ll><ll>d</ll></cont>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Duplicate instance of \"ll\". /e:cont/ll[.='d']");
 
     /* cases */
     data = "<l xmlns=\"urn:tests:e\">a</l><l xmlns=\"urn:tests:e\">b</l><l xmlns=\"urn:tests:e\">c</l><l xmlns=\"urn:tests:e\">b</l>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Duplicate instance of \"l\". /e:l[.='b']");
 
     data = "<l xmlns=\"urn:tests:e\">a</l><l xmlns=\"urn:tests:e\">b</l><l xmlns=\"urn:tests:e\">c</l><a xmlns=\"urn:tests:e\">aa</a>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Data for both cases \"a\" and \"b\" exist. /e:choic");
 
@@ -1185,7 +1186,7 @@
     "<cont xmlns=\"urn:tests:g\">"
         "<d>51</d>"
     "</cont>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Data are disabled by \"cont\" schema node if-feature. /g:cont");
 
@@ -1204,7 +1205,7 @@
             "<e>val</e>"
         "</cont2>"
     "</cont>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Data are disabled by \"cont2\" schema node if-feature. /g:cont/cont2");
 
@@ -1212,14 +1213,14 @@
     "<cont xmlns=\"urn:tests:g\">"
         "<a>val</a>"
     "</cont>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Data are disabled by \"choic\" schema node if-feature. /g:cont/a");
 
     /* enable f3 */
     assert_int_equal(lys_feature_enable(mod, "f3"), LY_SUCCESS);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     lyd_free_siblings(tree);
 
@@ -1228,14 +1229,14 @@
     "<cont xmlns=\"urn:tests:g\">"
         "<l>val</l>"
     "</cont>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Data are disabled by \"b\" schema node if-feature. /g:cont/l");
 
     /* enable f2 */
     assert_int_equal(lys_feature_enable(mod, "f2"), LY_SUCCESS);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     lyd_free_siblings(tree);
 
@@ -1252,7 +1253,7 @@
             "<e>val</e>"
         "</cont2>"
     "</cont>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY, 0, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY, 0, &tree));
     assert_non_null(tree);
 
     assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALIDATE_PRESENT));
@@ -1286,15 +1287,15 @@
             "<l>val</l>"
         "</cont2>"
     "</cont>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY | LYD_PARSE_NO_STATE, 0, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_NO_STATE, 0, &tree));
     assert_null(tree);
     logbuf_assert("Invalid state data node \"cont2\" found. Line number 1.");
 
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT | LYD_VALIDATE_NO_STATE, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT | LYD_VALIDATE_NO_STATE, &tree));
     assert_null(tree);
     logbuf_assert("Invalid state data node \"cont2\" found. /h:cont/cont2");
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY, 0, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY, 0, &tree));
     assert_non_null(tree);
 
     assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALIDATE_PRESENT | LYD_VALIDATE_NO_STATE));
@@ -1318,7 +1319,7 @@
         "<l>wrong</l>"
         "<l2>val</l2>"
     "</cont>";
-    assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_null(tree);
     logbuf_assert("Must condition \"../l = 'right'\" not satisfied. /i:cont/l2");
 
@@ -1327,7 +1328,7 @@
         "<l>right</l>"
         "<l2>val</l2>"
     "</cont>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
     lyd_free_tree(tree);
 
@@ -1340,6 +1341,7 @@
     *state = test_action;
 
     const char *data;
+    struct ly_in *in;
     struct lyd_node *tree, *op_tree;
     const struct lys_module *mod;
 
@@ -1352,20 +1354,22 @@
             "</act>"
         "</l1>"
     "</cont>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &op_tree, NULL));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &op_tree, NULL));
     assert_non_null(op_tree);
 
     /* missing leafref */
     assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, NULL, LYD_VALIDATE_OP_RPC));
     logbuf_assert("Invalid leafref value \"target\" - no target instance \"/lf3\" with the same value."
         " /j:cont/l1[k='val1']/act/lf2");
+    ly_in_free(in, 0);
 
     data =
     "<cont xmlns=\"urn:tests:j\">"
         "<lf1>not true</lf1>"
     "</cont>"
     "<lf3 xmlns=\"urn:tests:j\">target</lf3>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
     assert_non_null(tree);
 
     /* disabled if-feature */
@@ -1386,7 +1390,7 @@
         "<lf1>true</lf1>"
     "</cont>"
     "<lf3 xmlns=\"urn:tests:j\">target</lf3>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
     assert_non_null(tree);
 
     /* success */
@@ -1405,6 +1409,7 @@
     *state = test_reply;
 
     const char *data;
+    struct ly_in *in;
     struct lyd_node *tree, *op_tree, *request;
     const struct lys_module *mod;
 
@@ -1417,12 +1422,17 @@
             "</act>"
         "</l1>"
     "</cont>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &request, NULL));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &request, NULL));
     assert_non_null(request);
+    ly_in_free(in, 0);
+
     data = "<lf2 xmlns=\"urn:tests:j\">target</lf2>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_reply(request, data, &op_tree, NULL));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+    assert_int_equal(LY_SUCCESS, lyd_parse_reply(request, in, LYD_XML, &op_tree, NULL));
     lyd_free_all(request);
     assert_non_null(op_tree);
+    ly_in_free(in, 0);
 
     /* missing leafref */
     assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, NULL, LYD_VALIDATE_OP_REPLY));
@@ -1434,7 +1444,7 @@
         "<lf1>not true</lf1>"
     "</cont>"
     "<lf4 xmlns=\"urn:tests:j\">target</lf4>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
     assert_non_null(tree);
 
     /* disabled if-feature */
@@ -1455,7 +1465,7 @@
         "<lf1>true2</lf1>"
     "</cont>"
     "<lf4 xmlns=\"urn:tests:j\">target</lf4>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
     assert_non_null(tree);
 
     /* success */
diff --git a/tests/utests/schema/test_parser_yang.c b/tests/utests/schema/test_parser_yang.c
index 3d19f24..ea24966 100644
--- a/tests/utests/schema/test_parser_yang.c
+++ b/tests/utests/schema/test_parser_yang.c
@@ -36,34 +36,34 @@
 void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
 void lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when);
 
-LY_ERR buf_add_char(struct ly_ctx *ctx, const char **input, size_t len, char **buf, size_t *buf_len, size_t *buf_used);
-LY_ERR buf_store_char(struct lys_yang_parser_ctx *ctx, const char **input, enum yang_arg arg, char **word_p,
+LY_ERR buf_add_char(struct ly_ctx *ctx, struct ly_in *in, size_t len, char **buf, size_t *buf_len, size_t *buf_used);
+LY_ERR buf_store_char(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum yang_arg arg, char **word_p,
                       size_t *word_len, char **word_b, size_t *buf_len, int need_buf, int *prefix);
-LY_ERR get_keyword(struct lys_yang_parser_ctx *ctx, const char **data, enum ly_stmt *kw, char **word_p, size_t *word_len);
-LY_ERR get_argument(struct lys_yang_parser_ctx *ctx, const char **data, enum yang_arg arg,
+LY_ERR get_keyword(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt *kw, char **word_p, size_t *word_len);
+LY_ERR get_argument(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum yang_arg arg,
                     uint16_t *flags, char **word_p, char **word_b, size_t *word_len);
-LY_ERR skip_comment(struct lys_yang_parser_ctx *ctx, const char **data, int comment);
+LY_ERR skip_comment(struct lys_yang_parser_ctx *ctx, struct ly_in *in, int comment);
 
-LY_ERR parse_action(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_action **actions);
-LY_ERR parse_any(struct lys_yang_parser_ctx *ctx, const char **data, enum ly_stmt kw, struct lysp_node *parent, struct lysp_node **siblings);
-LY_ERR parse_augment(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_augment **augments);
-LY_ERR parse_case(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
-LY_ERR parse_container(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
-LY_ERR parse_deviate(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_deviate **deviates);
-LY_ERR parse_deviation(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_deviation **deviations);
-LY_ERR parse_grouping(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_grp **groupings);
-LY_ERR parse_choice(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
-LY_ERR parse_leaf(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
-LY_ERR parse_leaflist(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
-LY_ERR parse_list(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
-LY_ERR parse_maxelements(struct lys_yang_parser_ctx *ctx, const char **data, uint32_t *max, uint16_t *flags, struct lysp_ext_instance **exts);
-LY_ERR parse_minelements(struct lys_yang_parser_ctx *ctx, const char **data, uint32_t *min, uint16_t *flags, struct lysp_ext_instance **exts);
-LY_ERR parse_module(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_module *mod);
-LY_ERR parse_notif(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_notif **notifs);
-LY_ERR parse_submodule(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_submodule *submod);
-LY_ERR parse_uses(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
-LY_ERR parse_when(struct lys_yang_parser_ctx *ctx, const char **data, struct lysp_when **when_p);
-LY_ERR parse_type_enum_value_pos(struct lys_yang_parser_ctx *ctx, const char **data, enum ly_stmt val_kw, int64_t *value, uint16_t *flags, struct lysp_ext_instance **exts);
+LY_ERR parse_action(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_action **actions);
+LY_ERR parse_any(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt kw, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_augment(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_augment **augments);
+LY_ERR parse_case(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_container(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_deviate(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_deviate **deviates);
+LY_ERR parse_deviation(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_deviation **deviations);
+LY_ERR parse_grouping(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_grp **groupings);
+LY_ERR parse_choice(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_leaf(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_leaflist(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_list(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_maxelements(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint32_t *max, uint16_t *flags, struct lysp_ext_instance **exts);
+LY_ERR parse_minelements(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint32_t *min, uint16_t *flags, struct lysp_ext_instance **exts);
+LY_ERR parse_module(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_module *mod);
+LY_ERR parse_notif(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_notif **notifs);
+LY_ERR parse_submodule(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_submodule *submod);
+LY_ERR parse_uses(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_when(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_when **when_p);
+LY_ERR parse_type_enum_value_pos(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt val_kw, int64_t *value, uint16_t *flags, struct lysp_ext_instance **exts);
 
 #define BUFSIZE 1024
 char logbuf[BUFSIZE] = {0};
@@ -125,8 +125,8 @@
 #endif
 
 #define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
-    str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
+    in.current = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, FUNC(&ctx, &in, RESULT)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
     CLEANUP
 
@@ -135,7 +135,7 @@
 {
     (void) state; /* unused */
 
-    const char *str;
+    struct ly_in in = {0};
     char *buf, *p;
     size_t len, size;
     struct lys_yang_parser_ctx ctx;
@@ -146,44 +146,44 @@
     int prefix = 0;
 
     /* storing into buffer */
-    str = "abcd";
+    in.current = "abcd";
     buf = NULL;
     size = len = 0;
-    assert_int_equal(LY_SUCCESS, buf_add_char(NULL, &str, 2, &buf, &size, &len));
+    assert_int_equal(LY_SUCCESS, buf_add_char(NULL, &in, 2, &buf, &size, &len));
     assert_int_not_equal(0, size);
     assert_int_equal(2, len);
-    assert_string_equal("cd", str);
+    assert_string_equal("cd", in.current);
     assert_false(strncmp("ab", buf, 2));
     free(buf);
     buf = NULL;
 
     /* invalid first characters */
     len = 0;
-    str = "2invalid";
-    assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
-    str = ".invalid";
-    assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
-    str = "-invalid";
-    assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    in.current = "2invalid";
+    assert_int_equal(LY_EVALID, buf_store_char(&ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    in.current = ".invalid";
+    assert_int_equal(LY_EVALID, buf_store_char(&ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    in.current = "-invalid";
+    assert_int_equal(LY_EVALID, buf_store_char(&ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     /* invalid following characters */
     len = 3; /* number of characters read before the str content */
-    str = "!";
-    assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
-    str = ":";
-    assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    in.current = "!";
+    assert_int_equal(LY_EVALID, buf_store_char(&ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    in.current = ":";
+    assert_int_equal(LY_EVALID, buf_store_char(&ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     /* valid colon for prefixed identifiers */
     len = size = 0;
     p = NULL;
     prefix = 0;
-    str = "x:id";
-    assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &str, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 0, &prefix));
+    in.current = "x:id";
+    assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &in, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 0, &prefix));
     assert_int_equal(1, len);
     assert_null(buf);
-    assert_string_equal(":id", str);
+    assert_string_equal(":id", in.current);
     assert_int_equal('x', p[len - 1]);
-    assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &str, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &in, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     assert_int_equal(2, len);
-    assert_string_equal("id", str);
+    assert_string_equal("id", in.current);
     assert_int_equal(':', p[len - 1]);
     free(buf);
     prefix = 0;
@@ -212,8 +212,8 @@
 {
     (void) state; /* unused */
 
+    struct ly_in in = {0};
     struct lys_yang_parser_ctx ctx;
-    const char *str, *p;
     char *word, *buf;
     size_t len;
 
@@ -222,27 +222,27 @@
     ctx.pos_type = LY_VLOG_LINE;
     ctx.line = 1;
 
-    str = " // this is a text of / one * line */ comment\nargument;";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = " // this is a text of / one * line */ comment\nargument;";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_string_equal("argument;", word);
     assert_null(buf);
     assert_int_equal(8, len);
 
-    str = "/* this is a \n * text // of / block * comment */\"arg\" + \"ume\" \n + \n \"nt\";";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "/* this is a \n * text // of / block * comment */\"arg\" + \"ume\" \n + \n \"nt\";";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_string_equal("argument", word);
     assert_ptr_equal(buf, word);
     assert_int_equal(8, len);
     free(word);
 
-    str = p = " this is one line comment on last line";
-    assert_int_equal(LY_SUCCESS, skip_comment(&ctx, &str, 1));
-    assert_true(str[0] == '\0');
+    in.current = " this is one line comment on last line";
+    assert_int_equal(LY_SUCCESS, skip_comment(&ctx, &in, 1));
+    assert_true(in.current[0] == '\0');
 
-    str = p = " this is a not terminated comment x";
-    assert_int_equal(LY_EVALID, skip_comment(&ctx, &str, 2));
+    in.current = " this is a not terminated comment x";
+    assert_int_equal(LY_EVALID, skip_comment(&ctx, &in, 2));
     logbuf_assert("Unexpected end-of-input, non-terminated comment. Line number 5.");
-    assert_true(str[0] == '\0');
+    assert_true(in.current[0] == '\0');
 }
 
 static void
@@ -251,7 +251,7 @@
     (void) state; /* unused */
 
     struct lys_yang_parser_ctx ctx;
-    const char *str;
+    struct ly_in in = {0};
     char *word, *buf;
     size_t len;
 
@@ -261,78 +261,78 @@
     ctx.line = 1;
 
     /* missing argument */
-    str = ";";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_MAYBE_STR_ARG, NULL, &word, &buf, &len));
+    in.current = ";";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_MAYBE_STR_ARG, NULL, &word, &buf, &len));
     assert_null(word);
 
-    str = "{";
-    assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "{";
+    assert_int_equal(LY_EVALID, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     logbuf_assert("Invalid character sequence \"{\", expected an argument. Line number 1.");
 
     /* invalid escape sequence */
-    str = "\"\\s\"";
-    assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "\"\\s\"";
+    assert_int_equal(LY_EVALID, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     logbuf_assert("Double-quoted string unknown special character \'\\s\'. Line number 1.");
-    str = "\'\\s\'"; /* valid, since it is not an escape sequence in single quoted string */
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "\'\\s\'"; /* valid, since it is not an escape sequence in single quoted string */
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_int_equal(2, len);
     assert_string_equal("\\s\'", word);
-    assert_int_equal('\0', str[0]); /* input has been eaten */
+    assert_int_equal('\0', in.current[0]); /* input has been eaten */
 
     /* invalid character after the argument */
-    str = "hello\"";
-    assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "hello\"";
+    assert_int_equal(LY_EVALID, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     logbuf_assert("Invalid character sequence \"\"\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
-    str = "hello}";
-    assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "hello}";
+    assert_int_equal(LY_EVALID, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     logbuf_assert("Invalid character sequence \"}\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
 
     /* invalid identifier-ref-arg-str */
-    str = "pre:pre:value";
-    assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
+    in.current = "pre:pre:value";
+    assert_int_equal(LY_EVALID, get_argument(&ctx, &in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
 
-    str = "\"\";"; /* empty identifier is not allowed */
-    assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_IDENTIF_ARG, NULL, &word, &buf, &len));
+    in.current = "\"\";"; /* empty identifier is not allowed */
+    assert_int_equal(LY_EVALID, get_argument(&ctx, &in, Y_IDENTIF_ARG, NULL, &word, &buf, &len));
     logbuf_assert("Statement argument is required. Line number 1.");
     logbuf_clean();
-    str = "\"\";"; /* empty reference identifier is not allowed */
-    assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
+    in.current = "\"\";"; /* empty reference identifier is not allowed */
+    assert_int_equal(LY_EVALID, get_argument(&ctx, &in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
     logbuf_assert("Statement argument is required. Line number 1.");
 
-    str = "hello/x\t"; /* slash is not an invalid character */
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "hello/x\t"; /* slash is not an invalid character */
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_int_equal(7, len);
     assert_string_equal("hello/x\t", word);
 
     assert_null(buf);
 
     /* different quoting */
-    str = "hello ";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "hello ";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_null(buf);
     assert_int_equal(5, len);
     assert_string_equal("hello ", word);
 
-    str = "hello/*comment*/\n";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "hello/*comment*/\n";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_null(buf);
     assert_int_equal(5, len);
     assert_false(strncmp("hello", word, len));
 
 
-    str = "\"hello\\n\\t\\\"\\\\\";";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "\"hello\\n\\t\\\"\\\\\";";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_non_null(buf);
     assert_int_equal(9, len);
     assert_string_equal("hello\n\t\"\\", word);
     free(buf);
 
     ctx.indent = 14;
-    str = "\"hello \t\n\t\t world!\"";
+    in.current = "\"hello \t\n\t\t world!\"";
     /* - space and tabs before newline are stripped out
      * - space and tabs after newline (indentation) are stripped out
      */
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_non_null(buf);
     assert_ptr_equal(word, buf);
     assert_int_equal(14, len);
@@ -340,8 +340,8 @@
     free(buf);
     /* In contrast to previous, the backslash-escaped tabs are expanded after trimming, so they are preserved */
     ctx.indent = 14;
-    str = "\"hello \\t\n\t\\t world!\"";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "\"hello \\t\n\t\\t world!\"";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_non_null(buf);
     assert_ptr_equal(word, buf);
     assert_int_equal(16, len);
@@ -349,8 +349,8 @@
     free(buf);
     /* Do not handle whitespaces after backslash-escaped newline as indentation */
     ctx.indent = 14;
-    str = "\"hello\\n\t\t world!\"";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "\"hello\\n\t\t world!\"";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_non_null(buf);
     assert_ptr_equal(word, buf);
     assert_int_equal(15, len);
@@ -358,47 +358,47 @@
     free(buf);
 
     ctx.indent = 14;
-    str = "\"hello\n \tworld!\"";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "\"hello\n \tworld!\"";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_non_null(buf);
     assert_ptr_equal(word, buf);
     assert_int_equal(12, len);
     assert_string_equal("hello\nworld!", word);
     free(buf);
 
-    str = "\'hello\'";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "\'hello\'";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_null(buf);
     assert_int_equal(5, len);
     assert_false(strncmp("hello", word, 5));
 
-    str = "\"hel\"  +\t\n\"lo\"";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "\"hel\"  +\t\n\"lo\"";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_ptr_equal(word, buf);
     assert_int_equal(5, len);
     assert_string_equal("hello", word);
     free(buf);
-    str = "\"hel\"  +\t\nlo"; /* unquoted the second part */
-    assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "\"hel\"  +\t\nlo"; /* unquoted the second part */
+    assert_int_equal(LY_EVALID, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     logbuf_assert("Both string parts divided by '+' must be quoted. Line number 6.");
 
-    str = "\'he\'\t\n+ \"llo\"";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = "\'he\'\t\n+ \"llo\"";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_ptr_equal(word, buf);
     assert_int_equal(5, len);
     assert_string_equal("hello", word);
     free(buf);
 
-    str = " \t\n\"he\"+\'llo\'";
-    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = " \t\n\"he\"+\'llo\'";
+    assert_int_equal(LY_SUCCESS, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     assert_ptr_equal(word, buf);
     assert_int_equal(5, len);
     assert_string_equal("hello", word);
     free(buf);
 
     /* missing argument */
-    str = ";";
-    assert_int_equal(LY_EVALID, get_argument(&ctx, &str, Y_STR_ARG, NULL, &word, &buf, &len));
+    in.current = ";";
+    assert_int_equal(LY_EVALID, get_argument(&ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
     logbuf_assert("Invalid character sequence \";\", expected an argument. Line number 8.");
 }
 
@@ -408,7 +408,8 @@
     (void) state; /* unused */
 
     struct lys_yang_parser_ctx ctx;
-    const char *str, *p;
+    struct ly_in in = {0};
+    const char *p;
     enum ly_stmt kw;
     char *word;
     size_t len;
@@ -418,328 +419,328 @@
     ctx.pos_type = LY_VLOG_LINE;
     ctx.line = 1;
 
-    str = "\n// comment\n\tinput\t{";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "\n// comment\n\tinput\t{";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_INPUT, kw);
     assert_int_equal(5, len);
     assert_string_equal("input\t{", word);
-    assert_string_equal("\t{", str);
+    assert_string_equal("\t{", in.current);
 
-    str = "\t /* comment */\t output\n\t{";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "\t /* comment */\t output\n\t{";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_OUTPUT, kw);
     assert_int_equal(6, len);
     assert_string_equal("output\n\t{", word);
-    assert_string_equal("\n\t{", str);
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    assert_string_equal("\n\t{", in.current);
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_SYNTAX_LEFT_BRACE, kw);
     assert_int_equal(1, len);
     assert_string_equal("{", word);
-    assert_string_equal("", str);
+    assert_string_equal("", in.current);
 
-    str = "/input { "; /* invalid slash */
-    assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "/input { "; /* invalid slash */
+    assert_int_equal(LY_EVALID, get_keyword(&ctx, &in, &kw, &word, &len));
     logbuf_assert("Invalid identifier first character '/'. Line number 4.");
 
-    str = "not-a-statement-nor-extension { "; /* invalid identifier */
-    assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "not-a-statement-nor-extension { "; /* invalid identifier */
+    assert_int_equal(LY_EVALID, get_keyword(&ctx, &in, &kw, &word, &len));
     logbuf_assert("Invalid character sequence \"not-a-statement-nor-extension\", expected a keyword. Line number 4.");
 
-    str = "path;"; /* missing sep after the keyword */
-    assert_int_equal(LY_EVALID, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "path;"; /* missing sep after the keyword */
+    assert_int_equal(LY_EVALID, get_keyword(&ctx, &in, &kw, &word, &len));
     logbuf_assert("Invalid character sequence \"path;\", expected a keyword followed by a separator. Line number 4.");
 
-    str = "action ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "action ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_ACTION, kw);
     assert_int_equal(6, len);
-    str = "anydata ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "anydata ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_ANYDATA, kw);
     assert_int_equal(7, len);
-    str = "anyxml ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "anyxml ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_ANYXML, kw);
     assert_int_equal(6, len);
-    str = "argument ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "argument ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_ARGUMENT, kw);
     assert_int_equal(8, len);
-    str = "augment ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "augment ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_AUGMENT, kw);
     assert_int_equal(7, len);
-    str = "base ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "base ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_BASE, kw);
     assert_int_equal(4, len);
-    str = "belongs-to ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "belongs-to ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_BELONGS_TO, kw);
     assert_int_equal(10, len);
-    str = "bit ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "bit ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_BIT, kw);
     assert_int_equal(3, len);
-    str = "case ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "case ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_CASE, kw);
     assert_int_equal(4, len);
-    str = "choice ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "choice ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_CHOICE, kw);
     assert_int_equal(6, len);
-    str = "config ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "config ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_CONFIG, kw);
     assert_int_equal(6, len);
-    str = "contact ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "contact ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_CONTACT, kw);
     assert_int_equal(7, len);
-    str = "container ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "container ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_CONTAINER, kw);
     assert_int_equal(9, len);
-    str = "default ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "default ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_DEFAULT, kw);
     assert_int_equal(7, len);
-    str = "description ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "description ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_DESCRIPTION, kw);
     assert_int_equal(11, len);
-    str = "deviate ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "deviate ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_DEVIATE, kw);
     assert_int_equal(7, len);
-    str = "deviation ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "deviation ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_DEVIATION, kw);
     assert_int_equal(9, len);
-    str = "enum ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "enum ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_ENUM, kw);
     assert_int_equal(4, len);
-    str = "error-app-tag ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "error-app-tag ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_ERROR_APP_TAG, kw);
     assert_int_equal(13, len);
-    str = "error-message ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "error-message ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_ERROR_MESSAGE, kw);
     assert_int_equal(13, len);
-    str = "extension ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "extension ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_EXTENSION, kw);
     assert_int_equal(9, len);
-    str = "feature ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "feature ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_FEATURE, kw);
     assert_int_equal(7, len);
-    str = "fraction-digits ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "fraction-digits ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_FRACTION_DIGITS, kw);
     assert_int_equal(15, len);
-    str = "grouping ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "grouping ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_GROUPING, kw);
     assert_int_equal(8, len);
-    str = "identity ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "identity ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_IDENTITY, kw);
     assert_int_equal(8, len);
-    str = "if-feature ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "if-feature ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_IF_FEATURE, kw);
     assert_int_equal(10, len);
-    str = "import ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "import ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_IMPORT, kw);
     assert_int_equal(6, len);
-    str = "include ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "include ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_INCLUDE, kw);
     assert_int_equal(7, len);
-    str = "input{";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "input{";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_INPUT, kw);
     assert_int_equal(5, len);
-    str = "key ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "key ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_KEY, kw);
     assert_int_equal(3, len);
-    str = "leaf ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "leaf ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_LEAF, kw);
     assert_int_equal(4, len);
-    str = "leaf-list ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "leaf-list ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_LEAF_LIST, kw);
     assert_int_equal(9, len);
-    str = "length ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "length ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_LENGTH, kw);
     assert_int_equal(6, len);
-    str = "list ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "list ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_LIST, kw);
     assert_int_equal(4, len);
-    str = "mandatory ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "mandatory ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_MANDATORY, kw);
     assert_int_equal(9, len);
-    str = "max-elements ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "max-elements ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_MAX_ELEMENTS, kw);
     assert_int_equal(12, len);
-    str = "min-elements ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "min-elements ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_MIN_ELEMENTS, kw);
     assert_int_equal(12, len);
-    str = "modifier ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "modifier ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_MODIFIER, kw);
     assert_int_equal(8, len);
-    str = "module ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "module ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_MODULE, kw);
     assert_int_equal(6, len);
-    str = "must ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "must ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_MUST, kw);
     assert_int_equal(4, len);
-    str = "namespace ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "namespace ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_NAMESPACE, kw);
     assert_int_equal(9, len);
-    str = "notification ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "notification ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_NOTIFICATION, kw);
     assert_int_equal(12, len);
-    str = "ordered-by ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "ordered-by ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_ORDERED_BY, kw);
     assert_int_equal(10, len);
-    str = "organization ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "organization ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_ORGANIZATION, kw);
     assert_int_equal(12, len);
-    str = "output ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "output ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_OUTPUT, kw);
     assert_int_equal(6, len);
-    str = "path ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "path ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_PATH, kw);
     assert_int_equal(4, len);
-    str = "pattern ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "pattern ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_PATTERN, kw);
     assert_int_equal(7, len);
-    str = "position ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "position ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_POSITION, kw);
     assert_int_equal(8, len);
-    str = "prefix ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "prefix ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_PREFIX, kw);
     assert_int_equal(6, len);
-    str = "presence ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "presence ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_PRESENCE, kw);
     assert_int_equal(8, len);
-    str = "range ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "range ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_RANGE, kw);
     assert_int_equal(5, len);
-    str = "reference ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "reference ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_REFERENCE, kw);
     assert_int_equal(9, len);
-    str = "refine ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "refine ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_REFINE, kw);
     assert_int_equal(6, len);
-    str = "require-instance ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "require-instance ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_REQUIRE_INSTANCE, kw);
     assert_int_equal(16, len);
-    str = "revision ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "revision ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_REVISION, kw);
     assert_int_equal(8, len);
-    str = "revision-date ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "revision-date ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_REVISION_DATE, kw);
     assert_int_equal(13, len);
-    str = "rpc ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "rpc ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_RPC, kw);
     assert_int_equal(3, len);
-    str = "status ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "status ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_STATUS, kw);
     assert_int_equal(6, len);
-    str = "submodule ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "submodule ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_SUBMODULE, kw);
     assert_int_equal(9, len);
-    str = "type ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "type ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_TYPE, kw);
     assert_int_equal(4, len);
-    str = "typedef ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "typedef ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_TYPEDEF, kw);
     assert_int_equal(7, len);
-    str = "unique ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "unique ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_UNIQUE, kw);
     assert_int_equal(6, len);
-    str = "units ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "units ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_UNITS, kw);
     assert_int_equal(5, len);
-    str = "uses ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "uses ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_USES, kw);
     assert_int_equal(4, len);
-    str = "value ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "value ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_VALUE, kw);
     assert_int_equal(5, len);
-    str = "when ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "when ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_WHEN, kw);
     assert_int_equal(4, len);
-    str = "yang-version ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "yang-version ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_YANG_VERSION, kw);
     assert_int_equal(12, len);
-    str = "yin-element ";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = "yin-element ";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_YIN_ELEMENT, kw);
     assert_int_equal(11, len);
-    str = ";config false;";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = ";config false;";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_SYNTAX_SEMICOLON, kw);
     assert_int_equal(1, len);
-    assert_string_equal("config false;", str);
-    str = "{ config false;";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    assert_string_equal("config false;", in.current);
+    in.current = "{ config false;";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_SYNTAX_LEFT_BRACE, kw);
     assert_int_equal(1, len);
-    assert_string_equal(" config false;", str);
-    str = "}";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    assert_string_equal(" config false;", in.current);
+    in.current = "}";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_SYNTAX_RIGHT_BRACE, kw);
     assert_int_equal(1, len);
-    assert_string_equal("", str);
+    assert_string_equal("", in.current);
 
     /* geenric extension */
-    str = p = "nacm:default-deny-write;";
-    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &str, &kw, &word, &len));
+    in.current = p = "nacm:default-deny-write;";
+    assert_int_equal(LY_SUCCESS, get_keyword(&ctx, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_EXTENSION_INSTANCE, kw);
     assert_int_equal(23, len);
     assert_ptr_equal(p, word);
@@ -754,7 +755,7 @@
     uint16_t flags = 0;
     uint32_t value = 0;
     struct lysp_ext_instance *ext = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -763,30 +764,30 @@
     ctx.line = 1;
     ctx.mod_version = 2; /* simulate YANG 1.1 */
 
-    str = " 1invalid; ...";
-    assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " 1invalid; ...";
+    assert_int_equal(LY_EVALID, parse_minelements(&ctx, &in, &value, &flags, &ext));
     logbuf_assert("Invalid value \"1invalid\" of \"min-elements\". Line number 1.");
 
     flags = value = 0;
-    str = " -1; ...";
-    assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " -1; ...";
+    assert_int_equal(LY_EVALID, parse_minelements(&ctx, &in, &value, &flags, &ext));
     logbuf_assert("Invalid value \"-1\" of \"min-elements\". Line number 1.");
 
     /* implementation limit */
     flags = value = 0;
-    str = " 4294967296; ...";
-    assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " 4294967296; ...";
+    assert_int_equal(LY_EVALID, parse_minelements(&ctx, &in, &value, &flags, &ext));
     logbuf_assert("Value \"4294967296\" is out of \"min-elements\" bounds. Line number 1.");
 
     flags = value = 0;
-    str = " 1; ...";
-    assert_int_equal(LY_SUCCESS, parse_minelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " 1; ...";
+    assert_int_equal(LY_SUCCESS, parse_minelements(&ctx, &in, &value, &flags, &ext));
     assert_int_equal(LYS_SET_MIN, flags);
     assert_int_equal(1, value);
 
     flags = value = 0;
-    str = " 1 {m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_minelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " 1 {m:ext;} ...";
+    assert_int_equal(LY_SUCCESS, parse_minelements(&ctx, &in, &value, &flags, &ext));
     assert_int_equal(LYS_SET_MIN, flags);
     assert_int_equal(1, value);
     assert_non_null(ext);
@@ -794,40 +795,40 @@
     ext = NULL;
 
     flags = value = 0;
-    str = " 1 {config true;} ...";
-    assert_int_equal(LY_EVALID, parse_minelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " 1 {config true;} ...";
+    assert_int_equal(LY_EVALID, parse_minelements(&ctx, &in, &value, &flags, &ext));
     logbuf_assert("Invalid keyword \"config\" as a child of \"min-elements\". Line number 1.");
 
-    str = " 1invalid; ...";
-    assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " 1invalid; ...";
+    assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &in, &value, &flags, &ext));
     logbuf_assert("Invalid value \"1invalid\" of \"max-elements\". Line number 1.");
 
     flags = value = 0;
-    str = " -1; ...";
-    assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " -1; ...";
+    assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &in, &value, &flags, &ext));
     logbuf_assert("Invalid value \"-1\" of \"max-elements\". Line number 1.");
 
     /* implementation limit */
     flags = value = 0;
-    str = " 4294967296; ...";
-    assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " 4294967296; ...";
+    assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &in, &value, &flags, &ext));
     logbuf_assert("Value \"4294967296\" is out of \"max-elements\" bounds. Line number 1.");
 
     flags = value = 0;
-    str = " 1; ...";
-    assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " 1; ...";
+    assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &in, &value, &flags, &ext));
     assert_int_equal(LYS_SET_MAX, flags);
     assert_int_equal(1, value);
 
     flags = value = 0;
-    str = " unbounded; ...";
-    assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " unbounded; ...";
+    assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &in, &value, &flags, &ext));
     assert_int_equal(LYS_SET_MAX, flags);
     assert_int_equal(0, value);
 
     flags = value = 0;
-    str = " 1 {m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " 1 {m:ext;} ...";
+    assert_int_equal(LY_SUCCESS, parse_maxelements(&ctx, &in, &value, &flags, &ext));
     assert_int_equal(LYS_SET_MAX, flags);
     assert_int_equal(1, value);
     assert_non_null(ext);
@@ -835,8 +836,8 @@
     ext = NULL;
 
     flags = value = 0;
-    str = " 1 {config true;} ...";
-    assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &str, &value, &flags, &ext));
+    in.current = " 1 {config true;} ...";
+    assert_int_equal(LY_EVALID, parse_maxelements(&ctx, &in, &value, &flags, &ext));
     logbuf_assert("Invalid keyword \"config\" as a child of \"max-elements\". Line number 1.");
 
     *state = NULL;
@@ -897,7 +898,7 @@
     struct lysp_module *mod = NULL;
     struct lysp_submodule *submod = NULL;
     struct lys_module *m;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -909,35 +910,35 @@
     mod = mod_renew(&ctx);
 
     /* missing mandatory substatements */
-    str = " name {}";
-    assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
+    in.current = " name {}";
+    assert_int_equal(LY_EVALID, parse_module(&ctx, &in, mod));
     assert_string_equal("name", mod->mod->name);
     logbuf_assert("Missing mandatory keyword \"namespace\" as a child of \"module\". Line number 1.");
     mod = mod_renew(&ctx);
 
-    str = " name {namespace urn:x;}";
-    assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
+    in.current = " name {namespace urn:x;}";
+    assert_int_equal(LY_EVALID, parse_module(&ctx, &in, mod));
     assert_string_equal("urn:x", mod->mod->ns);
     logbuf_assert("Missing mandatory keyword \"prefix\" as a child of \"module\". Line number 1.");
     mod = mod_renew(&ctx);
 
-    str = " name {namespace urn:x;prefix \"x\";}";
-    assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod));
+    in.current = " name {namespace urn:x;prefix \"x\";}";
+    assert_int_equal(LY_SUCCESS, parse_module(&ctx, &in, mod));
     assert_string_equal("x", mod->mod->prefix);
     mod = mod_renew(&ctx);
 
 #define SCHEMA_BEGINNING " name {yang-version 1.1;namespace urn:x;prefix \"x\";"
 #define SCHEMA_BEGINNING2 " name {namespace urn:x;prefix \"x\";"
 #define TEST_NODE(NODETYPE, INPUT, NAME) \
-        str = SCHEMA_BEGINNING INPUT; \
-        assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod)); \
+        in.current = SCHEMA_BEGINNING INPUT; \
+        assert_int_equal(LY_SUCCESS, parse_module(&ctx, &in, mod)); \
         assert_non_null(mod->data); \
         assert_int_equal(NODETYPE, mod->data->nodetype); \
         assert_string_equal(NAME, mod->data->name); \
         mod = mod_renew(&ctx);
 #define TEST_GENERIC(INPUT, TARGET, TEST) \
-        str = SCHEMA_BEGINNING INPUT; \
-        assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod)); \
+        in.current = SCHEMA_BEGINNING INPUT; \
+        assert_int_equal(LY_SUCCESS, parse_module(&ctx, &in, mod)); \
         assert_non_null(TARGET); \
         TEST; \
         mod = mod_renew(&ctx);
@@ -954,8 +955,8 @@
     TEST_DUP("reference", "a", "b", "1");
 
     /* not allowed in module (submodule-specific) */
-    str = SCHEMA_BEGINNING "belongs-to master {prefix m;}}";
-    assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
+    in.current = SCHEMA_BEGINNING "belongs-to master {prefix m;}}";
+    assert_int_equal(LY_EVALID, parse_module(&ctx, &in, mod));
     logbuf_assert("Invalid keyword \"belongs-to\" as a child of \"module\". Line number 1.");
     mod = mod_renew(&ctx);
 
@@ -997,32 +998,32 @@
                  assert_string_equal("zzz", mod->imports[0].name));
 
     /* import - prefix collision */
-    str = SCHEMA_BEGINNING "import zzz {prefix x;}}";
-    assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
+    in.current = SCHEMA_BEGINNING "import zzz {prefix x;}}";
+    assert_int_equal(LY_EVALID, parse_module(&ctx, &in, mod));
     logbuf_assert("Prefix \"x\" already used as module prefix. Line number 2.");
     mod = mod_renew(&ctx);
-    str = SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix y;}}";
-    assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
+    in.current = SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix y;}}";
+    assert_int_equal(LY_EVALID, parse_module(&ctx, &in, mod));
     logbuf_assert("Prefix \"y\" already used to import \"zzz\" module. Line number 2.");
     mod = mod_renew(&ctx);
-    str = "module" SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix z;}}";
-    assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG));
+    in.current = "module" SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix z;}}";
+    assert_null(lys_parse_mem(ctx.ctx, in.current, LYS_IN_YANG));
     assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
     logbuf_assert("Single revision of the module \"zzz\" referred twice.");
 
     /* include */
     store = 1;
     ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "module xxx { namespace urn:xxx; prefix x;}");
-    str = "module" SCHEMA_BEGINNING "include xxx;}";
-    assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG));
+    in.current = "module" SCHEMA_BEGINNING "include xxx;}";
+    assert_null(lys_parse_mem(ctx.ctx, in.current, LYS_IN_YANG));
     assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
     logbuf_assert("Input data contains module in situation when a submodule is expected.");
     store = -1;
 
     store = 1;
     ly_ctx_set_module_imp_clb(ctx.ctx, test_imp_clb, "submodule xxx {belongs-to wrong-name {prefix w;}}");
-    str = "module" SCHEMA_BEGINNING "include xxx;}";
-    assert_null(lys_parse_mem(ctx.ctx, str, LYS_IN_YANG));
+    in.current = "module" SCHEMA_BEGINNING "include xxx;}";
+    assert_null(lys_parse_mem(ctx.ctx, in.current, LYS_IN_YANG));
     assert_int_equal(LY_EVALID, ly_errcode(ctx.ctx));
     logbuf_assert("Included \"xxx\" submodule from \"name\" belongs-to a different module \"wrong-name\".");
     store = -1;
@@ -1058,48 +1059,47 @@
     /* uses */
     TEST_NODE(LYS_USES, "uses test;}", "test");
     /* yang-version */
-    str = SCHEMA_BEGINNING2 "\n\tyang-version 10;}";
-    assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
+    in.current = SCHEMA_BEGINNING2 "\n\tyang-version 10;}";
+    assert_int_equal(LY_EVALID, parse_module(&ctx, &in, mod));
     logbuf_assert("Invalid value \"10\" of \"yang-version\". Line number 3.");
     mod = mod_renew(&ctx);
-    str = SCHEMA_BEGINNING2 "yang-version 1.0;yang-version 1.1;}";
-    assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
+    in.current = SCHEMA_BEGINNING2 "yang-version 1.0;yang-version 1.1;}";
+    assert_int_equal(LY_EVALID, parse_module(&ctx, &in, mod));
     logbuf_assert("Duplicate keyword \"yang-version\". Line number 3.");
     mod = mod_renew(&ctx);
-    str = SCHEMA_BEGINNING2 "yang-version 1.0;}";
-    assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod));
+    in.current = SCHEMA_BEGINNING2 "yang-version 1.0;}";
+    assert_int_equal(LY_SUCCESS, parse_module(&ctx, &in, mod));
     assert_int_equal(1, mod->mod->version);
     mod = mod_renew(&ctx);
-    str = SCHEMA_BEGINNING2 "yang-version \"1.1\";}";
-    assert_int_equal(LY_SUCCESS, parse_module(&ctx, &str, mod));
+    in.current = SCHEMA_BEGINNING2 "yang-version \"1.1\";}";
+    assert_int_equal(LY_SUCCESS, parse_module(&ctx, &in, mod));
     assert_int_equal(2, mod->mod->version);
     mod = mod_renew(&ctx);
 
     struct lys_yang_parser_ctx *ctx_p = NULL;
-    str = "module " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
+    in.current = "module " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
     m = mod->mod;
     free(mod);
     m->parsed = NULL;
-    assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, str, m));
+    assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m));
     logbuf_assert("Trailing garbage \"module q {names...\" after module, expected end-of-input. Line number 1.");
     yang_parser_ctx_free(ctx_p);
     mod = mod_renew(&ctx);
 
-    str = "prefix " SCHEMA_BEGINNING "}";
+    in.current = "prefix " SCHEMA_BEGINNING "}";
     m = mod->mod;
     free(mod);
     m->parsed = NULL;
-    assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, str, m));
+    assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m));
     yang_parser_ctx_free(ctx_p);
     logbuf_assert("Invalid keyword \"prefix\", expected \"module\" or \"submodule\". Line number 1.");
     mod = mod_renew(&ctx);
 
-    str = "module " SCHEMA_BEGINNING "}";
-    str = "module " SCHEMA_BEGINNING "leaf enum {type enumeration {enum seven { position 7;}}}}";
+    in.current = "module " SCHEMA_BEGINNING "leaf enum {type enumeration {enum seven { position 7;}}}}";
     m = mod->mod;
     free(mod);
     m->parsed = NULL;
-    assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, str, m));
+    assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m));
     yang_parser_ctx_free(ctx_p);
     logbuf_assert("Invalid keyword \"position\" as a child of \"enum\". Line number 1.");
     mod = mod_renew(&ctx);
@@ -1111,8 +1111,8 @@
     mod = mod_renew(&ctx);
 
     /* invalid substatement */
-    str = SCHEMA_BEGINNING "must false;}";
-    assert_int_equal(LY_EVALID, parse_module(&ctx, &str, mod));
+    in.current = SCHEMA_BEGINNING "must false;}";
+    assert_int_equal(LY_EVALID, parse_module(&ctx, &in, mod));
     logbuf_assert("Invalid keyword \"must\" as a child of \"module\". Line number 3.");
     mod = mod_renew(&ctx);
 
@@ -1120,16 +1120,16 @@
     submod = submod_renew(&ctx, submod);
 
     /* missing mandatory substatements */
-    str = " subname {}";
+    in.current = " subname {}";
     lydict_remove(ctx.ctx, submod->name);
-    assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod));
+    assert_int_equal(LY_EVALID, parse_submodule(&ctx, &in, submod));
     assert_string_equal("subname", submod->name);
     logbuf_assert("Missing mandatory keyword \"belongs-to\" as a child of \"submodule\". Line number 3.");
     submod = submod_renew(&ctx, submod);
 
-    str = " subname {belongs-to name {prefix x;}}";
+    in.current = " subname {belongs-to name {prefix x;}}";
     lydict_remove(ctx.ctx, submod->name);
-    assert_int_equal(LY_SUCCESS, parse_submodule(&ctx, &str, submod));
+    assert_int_equal(LY_SUCCESS, parse_submodule(&ctx, &in, submod));
     assert_string_equal("name", submod->belongsto);
     submod = submod_renew(&ctx, submod);
 
@@ -1137,30 +1137,30 @@
 #define SCHEMA_BEGINNING " subname {belongs-to name {prefix x;}"
 
     /* duplicated namespace, prefix */
-    str = " subname {belongs-to name {prefix x;}belongs-to module1;belongs-to module2;} ...";
-    assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod)); \
+    in.current = " subname {belongs-to name {prefix x;}belongs-to module1;belongs-to module2;} ...";
+    assert_int_equal(LY_EVALID, parse_submodule(&ctx, &in, submod)); \
     logbuf_assert("Duplicate keyword \"belongs-to\". Line number 3."); \
     submod = submod_renew(&ctx, submod);
 
     /* not allowed in submodule (module-specific) */
-    str = SCHEMA_BEGINNING "namespace \"urn:z\";}";
-    assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod));
+    in.current = SCHEMA_BEGINNING "namespace \"urn:z\";}";
+    assert_int_equal(LY_EVALID, parse_submodule(&ctx, &in, submod));
     logbuf_assert("Invalid keyword \"namespace\" as a child of \"submodule\". Line number 3.");
     submod = submod_renew(&ctx, submod);
-    str = SCHEMA_BEGINNING "prefix m;}}";
-    assert_int_equal(LY_EVALID, parse_submodule(&ctx, &str, submod));
+    in.current = SCHEMA_BEGINNING "prefix m;}}";
+    assert_int_equal(LY_EVALID, parse_submodule(&ctx, &in, submod));
     logbuf_assert("Invalid keyword \"prefix\" as a child of \"submodule\". Line number 3.");
     submod = submod_renew(&ctx, submod);
 
-    str = "submodule " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
+    in.current = "submodule " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
     lysp_submodule_free(ctx.ctx, submod);
     submod = NULL;
-    assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, ctx.ctx, (struct lys_parser_ctx *)&ctx, str, &submod));
+    assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, ctx.ctx, (struct lys_parser_ctx *)&ctx, &in, &submod));
     yang_parser_ctx_free(ctx_p);
     logbuf_assert("Trailing garbage \"module q {names...\" after submodule, expected end-of-input. Line number 1.");
 
-    str = "prefix " SCHEMA_BEGINNING "}";
-    assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, ctx.ctx, (struct lys_parser_ctx *)&ctx, str, &submod));
+    in.current = "prefix " SCHEMA_BEGINNING "}";
+    assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, ctx.ctx, (struct lys_parser_ctx *)&ctx, &in, &submod));
     yang_parser_ctx_free(ctx_p);
     logbuf_assert("Invalid keyword \"prefix\", expected \"module\" or \"submodule\". Line number 1.");
     submod = submod_renew(&ctx, submod);
@@ -1177,25 +1177,6 @@
     *state = NULL;
 }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 static void
 test_deviation(void **state)
 {
@@ -1203,7 +1184,7 @@
 
     struct lys_yang_parser_ctx ctx;
     struct lysp_deviation *d = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -1221,23 +1202,23 @@
     TEST_DUP("reference", "a", "b");
 
     /* full content */
-    str = " test {deviate not-supported;description text;reference \'another text\';prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviation(&ctx, &str, &d));
+    in.current = " test {deviate not-supported;description text;reference \'another text\';prefix:ext;} ...";
+    assert_int_equal(LY_SUCCESS, parse_deviation(&ctx, &in, &d));
     assert_non_null(d);
-    assert_string_equal(" ...", str);
+    assert_string_equal(" ...", in.current);
     FREE_ARRAY(ctx.ctx, d, lysp_deviation_free);
     d = NULL;
 
     /* missing mandatory substatement */
-    str = " test {description text;}";
-    assert_int_equal(LY_EVALID, parse_deviation(&ctx, &str, &d));
+    in.current = " test {description text;}";
+    assert_int_equal(LY_EVALID, parse_deviation(&ctx, &in, &d));
     logbuf_assert("Missing mandatory keyword \"deviate\" as a child of \"deviation\". Line number 1.");
     FREE_ARRAY(ctx.ctx, d, lysp_deviation_free);
     d = NULL;
 
     /* invalid substatement */
-    str = " test {deviate not-supported; status obsolete;}";
-    assert_int_equal(LY_EVALID, parse_deviation(&ctx, &str, &d));
+    in.current = " test {deviate not-supported; status obsolete;}";
+    assert_int_equal(LY_EVALID, parse_deviation(&ctx, &in, &d));
     logbuf_assert("Invalid keyword \"status\" as a child of \"deviation\". Line number 1.");
     FREE_ARRAY(ctx.ctx, d, lysp_deviation_free);
     d = NULL;
@@ -1254,7 +1235,7 @@
 
     struct lys_yang_parser_ctx ctx;
     struct lysp_deviate *d = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -1277,31 +1258,31 @@
     TEST_DUP("add", "units", "kilometers", "miles");
 
     /* full contents */
-    str = " not-supported {prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
+    in.current = " not-supported {prefix:ext;} ...";
+    assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &in, &d));
     assert_non_null(d);
-    assert_string_equal(" ...", str);
+    assert_string_equal(" ...", in.current);
     lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
-    str = " add {units meters; must 1; must 2; unique x; unique y; default a; default b; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
+    in.current = " add {units meters; must 1; must 2; unique x; unique y; default a; default b; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...";
+    assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &in, &d));
     assert_non_null(d);
-    assert_string_equal(" ...", str);
+    assert_string_equal(" ...", in.current);
     lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
-    str = " delete {units meters; must 1; must 2; unique x; unique y; default a; default b; prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
+    in.current = " delete {units meters; must 1; must 2; unique x; unique y; default a; default b; prefix:ext;} ...";
+    assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &in, &d));
     assert_non_null(d);
-    assert_string_equal(" ...", str);
+    assert_string_equal(" ...", in.current);
     lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
-    str = " replace {type string; units meters; default a; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &str, &d));
+    in.current = " replace {type string; units meters; default a; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...";
+    assert_int_equal(LY_SUCCESS, parse_deviate(&ctx, &in, &d));
     assert_non_null(d);
-    assert_string_equal(" ...", str);
+    assert_string_equal(" ...", in.current);
     lysp_deviate_free(ctx.ctx, d); free(d); d = NULL;
 
     /* invalid substatements */
 #define TEST_NOT_SUP(DEV, STMT, VALUE) \
-    str = " "DEV" {"STMT" "VALUE";}..."; \
-    assert_int_equal(LY_EVALID, parse_deviate(&ctx, &str, &d)); \
+    in.current = " "DEV" {"STMT" "VALUE";}..."; \
+    assert_int_equal(LY_EVALID, parse_deviate(&ctx, &in, &d)); \
     logbuf_assert("Deviate \""DEV"\" does not support keyword \""STMT"\". Line number 1."); \
     lysp_deviate_free(ctx.ctx, d); free(d); d = NULL
 
@@ -1323,8 +1304,8 @@
     TEST_NOT_SUP("replace", "must", "1");
     TEST_NOT_SUP("replace", "unique", "a");
 
-    str = " nonsence; ...";
-    assert_int_equal(LY_EVALID, parse_deviate(&ctx, &str, &d));
+    in.current = " nonsence; ...";
+    assert_int_equal(LY_EVALID, parse_deviate(&ctx, &in, &d));
     logbuf_assert("Invalid value \"nonsence\" of \"deviate\". Line number 1.");
     assert_null(d);
 
@@ -1341,7 +1322,7 @@
 
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_node_container *c = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -1352,8 +1333,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "cont {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c)); \
+    in.current = "cont {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_container(&ctx, &in, NULL, (struct lysp_node**)&c)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
 
@@ -1366,9 +1347,9 @@
 #undef TEST_DUP
 
     /* full content */
-    str = "cont {action x;anydata any;anyxml anyxml; choice ch;config false;container c;description test;grouping g;if-feature f; leaf l {type string;}"
+    in.current = "cont {action x;anydata any;anyxml anyxml; choice ch;config false;container c;description test;grouping g;if-feature f; leaf l {type string;}"
           "leaf-list ll {type string;} list li;must 'expr';notification not; presence true; reference test;status current;typedef t {type int8;}uses g;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
+    assert_int_equal(LY_SUCCESS, parse_container(&ctx, &in, NULL, (struct lysp_node**)&c));
     assert_non_null(c);
     assert_int_equal(LYS_CONTAINER, c->nodetype);
     assert_string_equal("cont", c->name);
@@ -1391,18 +1372,18 @@
     lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
 
     /* invalid */
-    str = " cont {augment /root;} ...";
-    assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
+    in.current = " cont {augment /root;} ...";
+    assert_int_equal(LY_EVALID, parse_container(&ctx, &in, NULL, (struct lysp_node**)&c));
     logbuf_assert("Invalid keyword \"augment\" as a child of \"container\". Line number 1.");
     lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
-    str = " cont {nonsence true;} ...";
-    assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
+    in.current = " cont {nonsence true;} ...";
+    assert_int_equal(LY_EVALID, parse_container(&ctx, &in, NULL, (struct lysp_node**)&c));
     logbuf_assert("Invalid character sequence \"nonsence\", expected a keyword. Line number 1.");
     lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
 
     ctx.mod_version = 1; /* simulate YANG 1.0 */
-    str = " cont {action x;} ...";
-    assert_int_equal(LY_EVALID, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
+    in.current = " cont {action x;} ...";
+    assert_int_equal(LY_EVALID, parse_container(&ctx, &in, NULL, (struct lysp_node**)&c));
     logbuf_assert("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
     lysp_node_free(ctx.ctx, (struct lysp_node*)c); c = NULL;
 
@@ -1416,7 +1397,7 @@
 
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_node_leaf *l = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -1427,8 +1408,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l)); \
+    in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_leaf(&ctx, &in, NULL, (struct lysp_node**)&l)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
 
@@ -1444,9 +1425,9 @@
 #undef TEST_DUP
 
     /* full content - without mandatory which is mutual exclusive with default */
-    str = "l {config false;default \"xxx\";description test;if-feature f;"
+    in.current = "l {config false;default \"xxx\";description test;if-feature f;"
           "must 'expr';reference test;status current;type string; units yyy;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
+    assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &in, NULL, (struct lysp_node**)&l));
     assert_non_null(l);
     assert_int_equal(LYS_LEAF, l->nodetype);
     assert_string_equal("l", l->name);
@@ -1465,8 +1446,8 @@
     lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
 
     /* full content - now with mandatory */
-    str = "l {mandatory true; type string;} ...";
-    assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
+    in.current = "l {mandatory true; type string;} ...";
+    assert_int_equal(LY_SUCCESS, parse_leaf(&ctx, &in, NULL, (struct lysp_node**)&l));
     assert_non_null(l);
     assert_int_equal(LYS_LEAF, l->nodetype);
     assert_string_equal("l", l->name);
@@ -1475,13 +1456,13 @@
     lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
 
     /* invalid */
-    str = " l {mandatory true; default xx; type string;} ...";
-    assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
+    in.current = " l {mandatory true; default xx; type string;} ...";
+    assert_int_equal(LY_EVALID, parse_leaf(&ctx, &in, NULL, (struct lysp_node**)&l));
     logbuf_assert("Invalid combination of keywords \"mandatory\" and \"default\" as substatements of \"leaf\". Line number 1.");
     lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
 
-    str = " l {description \"missing type\";} ...";
-    assert_int_equal(LY_EVALID, parse_leaf(&ctx, &str, NULL, (struct lysp_node**)&l));
+    in.current = " l {description \"missing type\";} ...";
+    assert_int_equal(LY_EVALID, parse_leaf(&ctx, &in, NULL, (struct lysp_node**)&l));
     logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf\". Line number 1.");
     lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
 
@@ -1496,7 +1477,7 @@
 
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_node_leaflist *ll = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -1507,8 +1488,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "ll {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll)); \
+    in.current = "ll {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &in, NULL, (struct lysp_node**)&ll)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
 
@@ -1525,10 +1506,10 @@
 #undef TEST_DUP
 
     /* full content - without min-elements which is mutual exclusive with default */
-    str = "ll {config false;default \"xxx\"; default \"yyy\";description test;if-feature f;"
+    in.current = "ll {config false;default \"xxx\"; default \"yyy\";description test;if-feature f;"
           "max-elements 10;must 'expr';ordered-by user;reference test;"
           "status current;type string; units zzz;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
+    assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &in, NULL, (struct lysp_node**)&ll));
     assert_non_null(ll);
     assert_int_equal(LYS_LEAFLIST, ll->nodetype);
     assert_string_equal("ll", ll->name);
@@ -1552,8 +1533,8 @@
     lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
 
     /* full content - now with min-elements */
-    str = "ll {min-elements 10; type string;} ...";
-    assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
+    in.current = "ll {min-elements 10; type string;} ...";
+    assert_int_equal(LY_SUCCESS, parse_leaflist(&ctx, &in, NULL, (struct lysp_node**)&ll));
     assert_non_null(ll);
     assert_int_equal(LYS_LEAFLIST, ll->nodetype);
     assert_string_equal("ll", ll->name);
@@ -1564,24 +1545,24 @@
     lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
 
     /* invalid */
-    str = " ll {min-elements 1; default xx; type string;} ...";
-    assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
+    in.current = " ll {min-elements 1; default xx; type string;} ...";
+    assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &in, NULL, (struct lysp_node**)&ll));
     logbuf_assert("Invalid combination of keywords \"min-elements\" and \"default\" as substatements of \"leaf-list\". Line number 1.");
     lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
 
-    str = " ll {description \"missing type\";} ...";
-    assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
+    in.current = " ll {description \"missing type\";} ...";
+    assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &in, NULL, (struct lysp_node**)&ll));
     logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf-list\". Line number 1.");
     lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
 
-    str = " ll {type string; min-elements 10; max-elements 1;} ..."; /* invalid combination of min/max */
-    assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
+    in.current = " ll {type string; min-elements 10; max-elements 1;} ..."; /* invalid combination of min/max */
+    assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &in, NULL, (struct lysp_node**)&ll));
     logbuf_assert("Invalid combination of min-elements and max-elements: min value 10 is bigger than the max value 1. Line number 1.");
     lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
 
     ctx.mod_version = 1; /* simulate YANG 1.0 - default statement is not allowed */
-    str = " ll {default xx; type string;} ...";
-    assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &str, NULL, (struct lysp_node**)&ll));
+    in.current = " ll {default xx; type string;} ...";
+    assert_int_equal(LY_EVALID, parse_leaflist(&ctx, &in, NULL, (struct lysp_node**)&ll));
     logbuf_assert("Invalid keyword \"default\" as a child of \"leaf-list\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
     lysp_node_free(ctx.ctx, (struct lysp_node*)ll); ll = NULL;
 
@@ -1596,7 +1577,7 @@
 
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_node_list *l = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -1607,8 +1588,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l)); \
+    in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_list(&ctx, &in, NULL, (struct lysp_node**)&l)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
 
@@ -1624,10 +1605,10 @@
 #undef TEST_DUP
 
     /* full content */
-    str = "l {action x;anydata any;anyxml anyxml; choice ch;config false;container c;description test;grouping g;if-feature f; key l; leaf l {type string;}"
+    in.current = "l {action x;anydata any;anyxml anyxml; choice ch;config false;container c;description test;grouping g;if-feature f; key l; leaf l {type string;}"
           "leaf-list ll {type string;} list li;max-elements 10; min-elements 1;must 'expr';notification not; ordered-by system; reference test;"
           "status current;typedef t {type int8;}unique xxx;unique yyy;uses g;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l));
+    assert_int_equal(LY_SUCCESS, parse_list(&ctx, &in, NULL, (struct lysp_node**)&l));
     assert_non_null(l);
     assert_int_equal(LYS_LIST, l->nodetype);
     assert_string_equal("l", l->name);
@@ -1652,8 +1633,8 @@
 
     /* invalid content */
     ctx.mod_version = 1; /* simulate YANG 1.0 */
-    str = "l {action x;} ...";
-    assert_int_equal(LY_EVALID, parse_list(&ctx, &str, NULL, (struct lysp_node**)&l));
+    in.current = "l {action x;} ...";
+    assert_int_equal(LY_EVALID, parse_list(&ctx, &in, NULL, (struct lysp_node**)&l));
     logbuf_assert("Invalid keyword \"action\" as a child of \"list\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
     lysp_node_free(ctx.ctx, (struct lysp_node*)l); l = NULL;
 
@@ -1668,7 +1649,7 @@
 
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_node_choice *ch = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -1679,8 +1660,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "ch {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch)); \
+    in.current = "ch {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_choice(&ctx, &in, NULL, (struct lysp_node**)&ch)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
 
@@ -1694,9 +1675,9 @@
 #undef TEST_DUP
 
     /* full content - without default due to a collision with mandatory */
-    str = "ch {anydata any;anyxml anyxml; case c;choice ch;config false;container c;description test;if-feature f;leaf l {type string;}"
+    in.current = "ch {anydata any;anyxml anyxml; case c;choice ch;config false;container c;description test;if-feature f;leaf l {type string;}"
           "leaf-list ll {type string;} list li;mandatory true;reference test;status current;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch));
+    assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &in, NULL, (struct lysp_node**)&ch));
     assert_non_null(ch);
     assert_int_equal(LYS_CHOICE, ch->nodetype);
     assert_string_equal("ch", ch->name);
@@ -1711,8 +1692,8 @@
     lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
 
     /* full content - the default missing from the previous node */
-    str = "ch {default c;case c;} ...";
-    assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch));
+    in.current = "ch {default c;case c;} ...";
+    assert_int_equal(LY_SUCCESS, parse_choice(&ctx, &in, NULL, (struct lysp_node**)&ch));
     assert_non_null(ch);
     assert_int_equal(LYS_CHOICE, ch->nodetype);
     assert_string_equal("ch", ch->name);
@@ -1721,8 +1702,8 @@
     lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
 
     /* invalid content */
-    str = "ch {mandatory true; default c1; case c1 {leaf x{type string;}}} ...";
-    assert_int_equal(LY_EVALID, parse_choice(&ctx, &str, NULL, (struct lysp_node**)&ch));
+    in.current = "ch {mandatory true; default c1; case c1 {leaf x{type string;}}} ...";
+    assert_int_equal(LY_EVALID, parse_choice(&ctx, &in, NULL, (struct lysp_node**)&ch));
     logbuf_assert("Invalid combination of keywords \"mandatory\" and \"default\" as substatements of \"choice\". Line number 1.");
     lysp_node_free(ctx.ctx, (struct lysp_node*)ch); ch = NULL;
 
@@ -1737,7 +1718,7 @@
 
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_node_case *cs = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -1748,8 +1729,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "cs {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs)); \
+    in.current = "cs {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_case(&ctx, &in, NULL, (struct lysp_node**)&cs)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL;
 
@@ -1760,9 +1741,9 @@
 #undef TEST_DUP
 
     /* full content */
-    str = "cs {anydata any;anyxml anyxml; choice ch;container c;description test;if-feature f;leaf l {type string;}"
+    in.current = "cs {anydata any;anyxml anyxml; choice ch;container c;description test;if-feature f;leaf l {type string;}"
           "leaf-list ll {type string;} list li;reference test;status current;uses grp;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs));
+    assert_int_equal(LY_SUCCESS, parse_case(&ctx, &in, NULL, (struct lysp_node**)&cs));
     assert_non_null(cs);
     assert_int_equal(LYS_CASE, cs->nodetype);
     assert_string_equal("cs", cs->name);
@@ -1777,8 +1758,8 @@
     lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL;
 
     /* invalid content */
-    str = "cs {config true} ...";
-    assert_int_equal(LY_EVALID, parse_case(&ctx, &str, NULL, (struct lysp_node**)&cs));
+    in.current = "cs {config true} ...";
+    assert_int_equal(LY_EVALID, parse_case(&ctx, &in, NULL, (struct lysp_node**)&cs));
     logbuf_assert("Invalid keyword \"config\" as a child of \"case\". Line number 1.");
     lysp_node_free(ctx.ctx, (struct lysp_node*)cs); cs = NULL;
 
@@ -1793,7 +1774,7 @@
 
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_node_anydata *any = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -1808,8 +1789,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_any(&ctx, &str, kw, NULL, (struct lysp_node**)&any)); \
+    in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_any(&ctx, &in, kw, NULL, (struct lysp_node**)&any)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     lysp_node_free(ctx.ctx, (struct lysp_node*)any); any = NULL;
 
@@ -1822,8 +1803,8 @@
 #undef TEST_DUP
 
     /* full content */
-    str = "any {config true;description test;if-feature f;mandatory true;must 'expr';reference test;status current;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_any(&ctx, &str, kw, NULL, (struct lysp_node**)&any));
+    in.current = "any {config true;description test;if-feature f;mandatory true;must 'expr';reference test;status current;when true;m:ext;} ...";
+    assert_int_equal(LY_SUCCESS, parse_any(&ctx, &in, kw, NULL, (struct lysp_node**)&any));
     assert_non_null(any);
     assert_int_equal(kw == LY_STMT_ANYDATA ? LYS_ANYDATA : LYS_ANYXML, any->nodetype);
     assert_string_equal("any", any->name);
@@ -1861,7 +1842,7 @@
 
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_grp *grp = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -1872,8 +1853,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp)); \
+    in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_grouping(&ctx, &in, NULL, &grp)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL;
 
@@ -1883,9 +1864,9 @@
 #undef TEST_DUP
 
     /* full content */
-    str = "grp {action x;anydata any;anyxml anyxml; choice ch;container c;description test;grouping g;leaf l {type string;}"
+    in.current = "grp {action x;anydata any;anyxml anyxml; choice ch;container c;description test;grouping g;leaf l {type string;}"
           "leaf-list ll {type string;} list li;notification not;reference test;status current;typedef t {type int8;}uses g;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_grouping(&ctx, &str, NULL, &grp));
+    assert_int_equal(LY_SUCCESS, parse_grouping(&ctx, &in, NULL, &grp));
     assert_non_null(grp);
     assert_int_equal(LYS_GROUPING, grp->nodetype);
     assert_string_equal("grp", grp->name);
@@ -1898,13 +1879,13 @@
     FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL;
 
     /* invalid content */
-    str = "grp {config true} ...";
-    assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp));
+    in.current = "grp {config true} ...";
+    assert_int_equal(LY_EVALID, parse_grouping(&ctx, &in, NULL, &grp));
     logbuf_assert("Invalid keyword \"config\" as a child of \"grouping\". Line number 1.");
     FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL;
 
-    str = "grp {must 'expr'} ...";
-    assert_int_equal(LY_EVALID, parse_grouping(&ctx, &str, NULL, &grp));
+    in.current = "grp {must 'expr'} ...";
+    assert_int_equal(LY_EVALID, parse_grouping(&ctx, &in, NULL, &grp));
     logbuf_assert("Invalid keyword \"must\" as a child of \"grouping\". Line number 1.");
     FREE_ARRAY(ctx.ctx, grp, lysp_grp_free); grp = NULL;
 
@@ -1920,7 +1901,7 @@
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_action *rpcs = NULL;
     struct lysp_node_container *c = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -1931,8 +1912,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_action(&ctx, &str, NULL, &rpcs)); \
+    in.current = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_action(&ctx, &in, NULL, &rpcs)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     FREE_ARRAY(ctx.ctx, rpcs, lysp_action_free); rpcs = NULL;
 
@@ -1944,14 +1925,14 @@
 #undef TEST_DUP
 
     /* full content */
-    str = "top;";
-    assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
-    str = "func {description test;grouping grp;if-feature f;reference test;status current;typedef mytype {type int8;} m:ext;"
+    in.current = "top;";
+    assert_int_equal(LY_SUCCESS, parse_container(&ctx, &in, NULL, (struct lysp_node**)&c));
+    in.current = "func {description test;grouping grp;if-feature f;reference test;status current;typedef mytype {type int8;} m:ext;"
           "input {anydata a1; anyxml a2; choice ch; container c; grouping grp; leaf l {type int8;} leaf-list ll {type int8;}"
           " list li; must 1; typedef mytypei {type int8;} uses grp; m:ext;}"
           "output {anydata a1; anyxml a2; choice ch; container c; grouping grp; leaf l {type int8;} leaf-list ll {type int8;}"
           " list li; must 1; typedef mytypeo {type int8;} uses grp; m:ext;}} ...";
-    assert_int_equal(LY_SUCCESS, parse_action(&ctx, &str, (struct lysp_node*)c, &rpcs));
+    assert_int_equal(LY_SUCCESS, parse_action(&ctx, &in, (struct lysp_node*)c, &rpcs));
     assert_non_null(rpcs);
     assert_int_equal(LYS_ACTION, rpcs->nodetype);
     assert_string_equal("func", rpcs->name);
@@ -1981,8 +1962,8 @@
     FREE_ARRAY(ctx.ctx, rpcs, lysp_action_free); rpcs = NULL;
 
     /* invalid content */
-    str = "func {config true} ...";
-    assert_int_equal(LY_EVALID, parse_action(&ctx, &str, NULL, &rpcs));
+    in.current = "func {config true} ...";
+    assert_int_equal(LY_EVALID, parse_action(&ctx, &in, NULL, &rpcs));
     logbuf_assert("Invalid keyword \"config\" as a child of \"rpc\". Line number 1.");
     FREE_ARRAY(ctx.ctx, rpcs, lysp_action_free); rpcs = NULL;
 
@@ -1999,7 +1980,7 @@
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_notif *notifs = NULL;
     struct lysp_node_container *c = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -2010,8 +1991,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_notif(&ctx, &str, NULL, &notifs)); \
+    in.current = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_notif(&ctx, &in, NULL, &notifs)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     FREE_ARRAY(ctx.ctx, notifs, lysp_notif_free); notifs = NULL;
 
@@ -2021,11 +2002,11 @@
 #undef TEST_DUP
 
     /* full content */
-    str = "top;";
-    assert_int_equal(LY_SUCCESS, parse_container(&ctx, &str, NULL, (struct lysp_node**)&c));
-    str = "ntf {anydata a1; anyxml a2; choice ch; container c; description test; grouping grp; if-feature f; leaf l {type int8;}"
+    in.current = "top;";
+    assert_int_equal(LY_SUCCESS, parse_container(&ctx, &in, NULL, (struct lysp_node**)&c));
+    in.current = "ntf {anydata a1; anyxml a2; choice ch; container c; description test; grouping grp; if-feature f; leaf l {type int8;}"
           "leaf-list ll {type int8;} list li; must 1; reference test; status current; typedef mytype {type int8;} uses grp; m:ext;}";
-    assert_int_equal(LY_SUCCESS, parse_notif(&ctx, &str, (struct lysp_node*)c, &notifs));
+    assert_int_equal(LY_SUCCESS, parse_notif(&ctx, &in, (struct lysp_node*)c, &notifs));
     assert_non_null(notifs);
     assert_int_equal(LYS_NOTIF, notifs->nodetype);
     assert_string_equal("ntf", notifs->name);
@@ -2043,8 +2024,8 @@
     FREE_ARRAY(ctx.ctx, notifs, lysp_notif_free); notifs = NULL;
 
     /* invalid content */
-    str = "ntf {config true} ...";
-    assert_int_equal(LY_EVALID, parse_notif(&ctx, &str, NULL, &notifs));
+    in.current = "ntf {config true} ...";
+    assert_int_equal(LY_EVALID, parse_notif(&ctx, &in, NULL, &notifs));
     logbuf_assert("Invalid keyword \"config\" as a child of \"notification\". Line number 1.");
     FREE_ARRAY(ctx.ctx, notifs, lysp_notif_free); notifs = NULL;
 
@@ -2060,7 +2041,7 @@
 
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_node_uses *u = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -2071,8 +2052,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_uses(&ctx, &str, NULL, (struct lysp_node**)&u)); \
+    in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_uses(&ctx, &in, NULL, (struct lysp_node**)&u)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     lysp_node_free(ctx.ctx, (struct lysp_node*)u); u = NULL;
 
@@ -2083,8 +2064,8 @@
 #undef TEST_DUP
 
     /* full content */
-    str = "grpref {augment some/node;description test;if-feature f;reference test;refine some/other/node;status current;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_uses(&ctx, &str, NULL, (struct lysp_node**)&u));
+    in.current = "grpref {augment some/node;description test;if-feature f;reference test;refine some/other/node;status current;when true;m:ext;} ...";
+    assert_int_equal(LY_SUCCESS, parse_uses(&ctx, &in, NULL, (struct lysp_node**)&u));
     assert_non_null(u);
     assert_int_equal(LYS_USES, u->nodetype);
     assert_string_equal("grpref", u->name);
@@ -2112,7 +2093,7 @@
 
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_augment *a = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -2123,8 +2104,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_augment(&ctx, &str, NULL, &a)); \
+    in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_augment(&ctx, &in, NULL, &a)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     FREE_ARRAY(ctx.ctx, a, lysp_augment_free); a = NULL;
 
@@ -2135,9 +2116,9 @@
 #undef TEST_DUP
 
     /* full content */
-    str = "/target/nodeid {action x; anydata any;anyxml anyxml; case cs; choice ch;container c;description test;if-feature f;leaf l {type string;}"
+    in.current = "/target/nodeid {action x; anydata any;anyxml anyxml; case cs; choice ch;container c;description test;if-feature f;leaf l {type string;}"
           "leaf-list ll {type string;} list li;notification not;reference test;status current;uses g;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_augment(&ctx, &str, NULL, &a));
+    assert_int_equal(LY_SUCCESS, parse_augment(&ctx, &in, NULL, &a));
     assert_non_null(a);
     assert_int_equal(LYS_AUGMENT, a->nodetype);
     assert_string_equal("/target/nodeid", a->nodeid);
@@ -2161,7 +2142,7 @@
 
     struct lys_yang_parser_ctx ctx = {0};
     struct lysp_when *w = NULL;
-    const char *str;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -2172,8 +2153,8 @@
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
-    str = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_when(&ctx, &str, &w)); \
+    in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
+    assert_int_equal(LY_EVALID, parse_when(&ctx, &in, &w)); \
     logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
     FREE_MEMBER(ctx.ctx, w, lysp_when_free); w = NULL;
 
@@ -2182,8 +2163,8 @@
 #undef TEST_DUP
 
     /* full content */
-    str = "expression {description test;reference test;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_when(&ctx, &str, &w));
+    in.current = "expression {description test;reference test;m:ext;} ...";
+    assert_int_equal(LY_SUCCESS, parse_when(&ctx, &in, &w));
     assert_non_null(w);
     assert_string_equal("expression", w->cond);
     assert_string_equal("test", w->dsc);
@@ -2192,8 +2173,8 @@
     FREE_MEMBER(ctx.ctx, w, lysp_when_free); w = NULL;
 
     /* empty condition */
-    str = "\"\";";
-    assert_int_equal(LY_SUCCESS, parse_when(&ctx, &str, &w));
+    in.current = "\"\";";
+    assert_int_equal(LY_SUCCESS, parse_when(&ctx, &in, &w));
     logbuf_assert("Empty argument of when statement does not make sense.");
     assert_non_null(w);
     assert_string_equal("", w->cond);
@@ -2208,6 +2189,7 @@
 {
     *state = test_value;
     struct lys_yang_parser_ctx ctx;
+    struct ly_in in = {0};
 
     ctx.format = LYS_IN_YANG;
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx.ctx));
@@ -2218,13 +2200,13 @@
     int64_t val = 0;
     uint16_t flags = 0;
 
-    const char *data = "-0;";
-    assert_int_equal(parse_type_enum_value_pos(&ctx, &data, LY_STMT_VALUE, &val, &flags, NULL), LY_SUCCESS);
+    in.current = "-0;";
+    assert_int_equal(parse_type_enum_value_pos(&ctx, &in, LY_STMT_VALUE, &val, &flags, NULL), LY_SUCCESS);
     assert_int_equal(val, 0);
 
-    data = "-0;";
+    in.current = "-0;";
     flags = 0;
-    assert_int_equal(parse_type_enum_value_pos(&ctx, &data, LY_STMT_POSITION, &val, &flags, NULL), LY_EVALID);
+    assert_int_equal(parse_type_enum_value_pos(&ctx, &in, LY_STMT_POSITION, &val, &flags, NULL), LY_EVALID);
     logbuf_assert("Invalid value \"-0\" of \"position\". Line number 1.");
 
     *state = NULL;
diff --git a/tests/utests/schema/test_parser_yin.c b/tests/utests/schema/test_parser_yin.c
index 737d2d5..201de0d 100644
--- a/tests/utests/schema/test_parser_yin.c
+++ b/tests/utests/schema/test_parser_yin.c
@@ -60,6 +60,7 @@
     struct lys_module *mod;
     struct lysp_module *lysp_mod;
     struct lys_yin_parser_ctx *yin_ctx;
+    struct ly_in *in;
     bool finished_correctly;
 };
 
@@ -151,6 +152,8 @@
     st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
     st->yin_ctx->format = LYS_IN_YIN;
 
+    st->in = NULL;
+
     return EXIT_SUCCESS;
 }
 
@@ -174,6 +177,7 @@
     lysp_module_free(st->lysp_mod);
     lys_module_free(temp, NULL);
     free(st->yin_ctx);
+    ly_in_free(st->in, 0);
 
     return EXIT_SUCCESS;
 }
@@ -243,6 +247,7 @@
 
     lyxml_ctx_free(st->yin_ctx->xmlctx);
     free(st->yin_ctx);
+    ly_in_free(st->in, 0);
 
     teardown_logger(state);
 
@@ -258,7 +263,8 @@
     size_t prefix_len;
     /* create mock yin namespace in xml context */
     const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
     prefix = st->yin_ctx->xmlctx->prefix;
     prefix_len = st->yin_ctx->xmlctx->prefix_len;
 
@@ -365,7 +371,8 @@
     memset(&exts, 0, sizeof(exts));
 
     const char *data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
 
     ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
     assert_int_equal(ret, LY_SUCCESS);
@@ -379,7 +386,8 @@
     st = reset_state(state);
 
     data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
 
     ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
     assert_int_equal(ret, LY_SUCCESS);
@@ -399,7 +407,8 @@
     struct test_parser_yin_state *st = *state;
     struct lysp_ext_instance *exts = NULL;
     const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>";
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
 
     ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
     assert_int_equal(ret, LY_SUCCESS);
@@ -427,7 +436,8 @@
     st = reset_state(state);
 
     data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />";
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
 
     ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
     assert_int_equal(ret, LY_SUCCESS);
@@ -451,7 +461,8 @@
                 "</myext:ext-sub2>"
                 "<myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>"
            "</myext:ext>";
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
 
     ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
     assert_int_equal(ret, LY_SUCCESS);
@@ -529,7 +540,8 @@
                 "<yin:description><yin:text>contact-val</yin:text></yin:description>"
                 "<yin:error-message><yin:value>err-msg</yin:value></yin:error-message>"
            "</myext:extension-elem>";
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
 
     ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
     assert_int_equal(ret, LY_SUCCESS);
@@ -599,7 +611,8 @@
     struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
     uint8_t config = 0;
 
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
     lyxml_ctx_next(st->yin_ctx->xmlctx);
     lyxml_ctx_next(st->yin_ctx->xmlctx);
     lyxml_ctx_next(st->yin_ctx->xmlctx);
@@ -683,7 +696,8 @@
                 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
                 "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
            ELEMENT_WRAPPER_END;
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
     lyxml_ctx_next(st->yin_ctx->xmlctx);
 
     ret = yin_parse_content(st->yin_ctx, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
@@ -701,7 +715,8 @@
            ELEMENT_WRAPPER_END;
     struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
                                          {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
     lyxml_ctx_next(st->yin_ctx->xmlctx);
 
     ret = yin_parse_content(st->yin_ctx, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
@@ -713,7 +728,8 @@
     /* test mandatory subelem */
     data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
     struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
     lyxml_ctx_next(st->yin_ctx->xmlctx);
 
     ret = yin_parse_content(st->yin_ctx, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
@@ -730,7 +746,8 @@
     const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
 
     /* create some XML context */
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
     st->yin_ctx->xmlctx->status = LYXML_ELEM_CONTENT;
     st->yin_ctx->xmlctx->dynamic = 0;
 
@@ -835,7 +852,8 @@
                                             {LY_STMT_ARG_TEXT, dest, 0},
                                             {LY_STMT_ARG_VALUE, dest, 0}
                                         };
-    lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &st->in);
+    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
     prefix = st->yin_ctx->xmlctx->prefix;
     prefix_len = st->yin_ctx->xmlctx->prefix_len;
     name = st->yin_ctx->xmlctx->name;
@@ -844,9 +862,11 @@
 
     ret = yin_parse_content(st->yin_ctx, subelems, 71, yin_match_keyword(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts);
 
-    /* free parser */
+    /* free parser and input */
     lyxml_ctx_free(st->yin_ctx->xmlctx);
     st->yin_ctx->xmlctx = NULL;
+    ly_in_free(st->in, 0);
+    st->in = NULL;
     return ret;
 }
 
@@ -3887,7 +3907,8 @@
                 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
                 EXT_SUBELEM"\n"
            "</module>\n";
-    assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
 
     assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
     assert_string_equal(lysp_mod->mod->name, "mod");
@@ -3935,6 +3956,7 @@
     lys_module_free(lys_mod, NULL);
 
     /* min subelems */
+    ly_in_free(st->in, 0);
     lyxml_ctx_free(st->yin_ctx->xmlctx);
     lys_mod = calloc(1, sizeof *lys_mod);
     lysp_mod = calloc(1, sizeof *lysp_mod);
@@ -3945,13 +3967,15 @@
                 "<prefix value=\"pref\"/>"
                 "<yang-version value=\"1.1\"/>"
            "</module>";
-    assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
     assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
     assert_string_equal(lysp_mod->mod->name, "mod");
     lysp_module_free(lysp_mod);
     lys_module_free(lys_mod, NULL);
 
     /* incorrect subelem order */
+    ly_in_free(st->in, 0);
     lyxml_ctx_free(st->yin_ctx->xmlctx);
     lys_mod = calloc(1, sizeof *lys_mod);
     lysp_mod = calloc(1, sizeof *lysp_mod);
@@ -3963,7 +3987,8 @@
                 "<prefix value=\"pref\"/>"
                 "<yang-version value=\"1.1\"/>"
            "</module>";
-    assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
     assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_EVALID);
     logbuf_assert("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\". Line number 2.");
     lysp_module_free(lysp_mod);
@@ -4010,7 +4035,8 @@
                 "<typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
                 EXT_SUBELEM"\n"
            "</submodule>\n";
-    assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
     assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
 
     assert_string_equal(lysp_submod->name, "mod");
@@ -4057,13 +4083,15 @@
     lysp_submodule_free(st->ctx, lysp_submod);
 
     /* min subelemnts */
+    ly_in_free(st->in, 0);
     lyxml_ctx_free(st->yin_ctx->xmlctx);
     lysp_submod = calloc(1, sizeof *lysp_submod);
     data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
                 "<yang-version value=\"1.0\"/>"
                 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
            "</submodule>";
-    assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
     assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
     assert_string_equal(lysp_submod->prefix, "pref");
     assert_string_equal(lysp_submod->belongsto, "mod-name");
@@ -4071,6 +4099,7 @@
     lysp_submodule_free(st->ctx, lysp_submod);
 
     /* incorrect subelem order */
+    ly_in_free(st->in, 0);
     lyxml_ctx_free(st->yin_ctx->xmlctx);
     lysp_submod = calloc(1, sizeof *lysp_submod);
     data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">"
@@ -4078,7 +4107,8 @@
                 "<reference><text>ref</text></reference>\n"
                 "<belongs-to module=\"mod-name\"><prefix value=\"pref\"/></belongs-to>"
            "</submodule>";
-    assert_int_equal(lyxml_ctx_new(st->ctx, data, &st->yin_ctx->xmlctx), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
     assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_EVALID);
     logbuf_assert("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\". Line number 2.");
     lysp_submodule_free(st->ctx, lysp_submod);
@@ -4093,6 +4123,7 @@
     const char *data;
     struct lys_module *mod;
     struct lys_yin_parser_ctx *yin_ctx = NULL;
+    struct ly_in *in = NULL;
 
     mod = calloc(1, sizeof *mod);
     mod->ctx = st->ctx;
@@ -4117,11 +4148,13 @@
                 "<units name=\"meters\"/>\n"
            "</md:annotation>\n"
            "</module>\n";
-    assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
+    assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
     assert_null(mod->parsed->exts->child->next->child);
     assert_string_equal(mod->parsed->exts->child->next->arg, "test");
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
+    ly_in_free(in, 0);
     mod = NULL;
     yin_ctx = NULL;
 
@@ -4155,9 +4188,11 @@
                     "</leaf>\n"
                 "</list>\n"
             "</module>\n";
-    assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
+    assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
+    ly_in_free(in, 0);
     mod = NULL;
     yin_ctx = NULL;
 
@@ -4168,9 +4203,11 @@
                 "<namespace uri=\"urn:example:foo\"/>\n"
                 "<prefix value=\"foo\"/>\n"
             "</module>\n";
-    assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
+    assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_SUCCESS);
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
+    ly_in_free(in, 0);
     mod = NULL;
     yin_ctx = NULL;
 
@@ -4179,10 +4216,12 @@
     mod->ctx = st->ctx;
     data =  "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
             "</submodule>\n";
-    assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EINVAL);
+    assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
+    assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EINVAL);
     logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
+    ly_in_free(in, 0);
 
     mod = calloc(1, sizeof *mod);
     mod->ctx = st->ctx;
@@ -4192,10 +4231,12 @@
                 "<prefix value=\"foo\"/>\n"
             "</module>"
             "<module>";
-    assert_int_equal(yin_parse_module(&yin_ctx, data, mod), LY_EVALID);
+    assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
+    assert_int_equal(yin_parse_module(&yin_ctx, in, mod), LY_EVALID);
     logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 5.");
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
+    ly_in_free(in, 0);
     mod = NULL;
     yin_ctx = NULL;
 
@@ -4210,6 +4251,7 @@
     struct lys_yin_parser_ctx *yin_ctx = NULL;
     struct lysp_submodule *submod = NULL;
     struct lys_parser_ctx main_ctx = {};
+    struct ly_in *in;
 
     data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
             "<submodule name=\"asub\""
@@ -4235,9 +4277,11 @@
                     "<container name=\"bar-sub2\"/>"
                 "</augment>"
             "</submodule>";
-    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
+    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, in, &submod), LY_SUCCESS);
     lysp_submodule_free(st->ctx, submod);
     yin_parser_ctx_free(yin_ctx);
+    ly_in_free(in, 0);
     yin_ctx = NULL;
     submod = NULL;
 
@@ -4248,19 +4292,23 @@
                     "<prefix value=\"a_pref\"/>"
                 "</belongs-to>"
             "</submodule>";
-    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
+    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, in, &submod), LY_SUCCESS);
     lysp_submodule_free(st->ctx, submod);
     yin_parser_ctx_free(yin_ctx);
+    ly_in_free(in, 0);
     yin_ctx = NULL;
     submod = NULL;
 
     data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
             "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
             "</module>";
-    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EINVAL);
+    assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
+    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, in, &submod), LY_EINVAL);
     logbuf_assert("Input data contains module in situation when a submodule is expected.");
     lysp_submodule_free(st->ctx, submod);
     yin_parser_ctx_free(yin_ctx);
+    ly_in_free(in, 0);
     yin_ctx = NULL;
     submod = NULL;
 
@@ -4277,10 +4325,12 @@
                     "<prefix value=\"a_pref\"/>"
                 "</belongs-to>"
             "</submodule>";
-    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, data, &submod), LY_EVALID);
+    assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
+    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, &main_ctx, in, &submod), LY_EVALID);
     logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 2.");
     lysp_submodule_free(st->ctx, submod);
     yin_parser_ctx_free(yin_ctx);
+    ly_in_free(in, 0);
     yin_ctx = NULL;
     submod = NULL;
 
diff --git a/tests/utests/schema/test_printer_yang.c b/tests/utests/schema/test_printer_yang.c
index 24e8b31..6352695 100644
--- a/tests/utests/schema/test_printer_yang.c
+++ b/tests/utests/schema/test_printer_yang.c
@@ -133,16 +133,17 @@
             "}\n";
     char *printed;
     struct ly_out *out;
-    size_t size = 0;
 
     assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
     assert_non_null(mod = lys_parse_mem(ctx, orig, LYS_IN_YANG));
-    assert_int_equal(strlen(orig), size = lys_print(out, mod, LYS_OUT_YANG, 0, 0));
+    assert_int_equal(LY_SUCCESS, lys_print(out, mod, LYS_OUT_YANG, 0, 0));
+    assert_int_equal(strlen(orig), ly_out_printed(out));
     assert_string_equal(printed, orig);
     ly_out_reset(out);
-    assert_int_equal(strlen(compiled), lys_print(out, mod, LYS_OUT_YANG_COMPILED, 0, 0));
+    assert_int_equal(LY_SUCCESS, lys_print(out, mod, LYS_OUT_YANG_COMPILED, 0, 0));
+    assert_int_equal(strlen(compiled), ly_out_printed(out));
     assert_string_equal(printed, compiled);
     ly_out_reset(out);
 
@@ -188,10 +189,12 @@
             "  }\n"
             "}\n";
     assert_non_null(mod = lys_parse_mem(ctx, orig, LYS_IN_YANG));
-    assert_int_equal(strlen(orig), lys_print(out, mod, LYS_OUT_YANG, 0, 0));
+    assert_int_equal(LY_SUCCESS, lys_print(out, mod, LYS_OUT_YANG, 0, 0));
+    assert_int_equal(strlen(orig), ly_out_printed(out));
     assert_string_equal(printed, orig);
     ly_out_reset(out);
-    assert_int_equal(strlen(compiled), lys_print(out, mod, LYS_OUT_YANG_COMPILED, 0, 0));
+    assert_int_equal(LY_SUCCESS, lys_print(out, mod, LYS_OUT_YANG_COMPILED, 0, 0));
+    assert_int_equal(strlen(compiled), ly_out_printed(out));
     assert_string_equal(printed, compiled);
     ly_out_reset(out);
 
@@ -213,10 +216,12 @@
             "  }\n"
             "}\n";
     assert_non_null(mod = lys_parse_mem(ctx, orig, LYS_IN_YANG));
-    assert_int_equal(strlen(orig), lys_print(out, mod, LYS_OUT_YANG, 0, 0));
+    assert_int_equal(LY_SUCCESS, lys_print(out, mod, LYS_OUT_YANG, 0, 0));
+    assert_int_equal(strlen(orig), ly_out_printed(out));
     assert_string_equal(printed, orig);
     ly_out_reset(out);
-    assert_int_equal(strlen(compiled), lys_print(out, mod, LYS_OUT_YANG, 0, 0));
+    assert_int_equal(LY_SUCCESS, lys_print(out, mod, LYS_OUT_YANG, 0, 0));
+    assert_int_equal(strlen(compiled), ly_out_printed(out));
     assert_string_equal(printed, compiled);
     /* missing free(printed); which is done in the following lyp_free() */
 
diff --git a/tests/utests/schema/test_printer_yin.c b/tests/utests/schema/test_printer_yin.c
index 2d82f88..eda568f 100644
--- a/tests/utests/schema/test_printer_yin.c
+++ b/tests/utests/schema/test_printer_yin.c
@@ -587,7 +587,8 @@
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
     assert_non_null(mod = lys_parse_mem(ctx, orig, LYS_IN_YANG));
-    assert_int_equal(strlen(ori_res), lys_print(out, mod, LYS_OUT_YIN, 0, 0));
+    assert_int_equal(LY_SUCCESS, lys_print(out, mod, LYS_OUT_YIN, 0, 0));
+    assert_int_equal(strlen(ori_res), ly_out_printed(out));
     assert_string_equal(printed, ori_res);
 
     /*
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 6d9b4a3..40de6f4 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -102,6 +102,7 @@
     *state = test_module;
 
     const char *str;
+    struct ly_in *in;
     struct ly_ctx *ctx = NULL;
     struct lys_module *mod = NULL;
     struct lysc_feature *f;
@@ -115,7 +116,9 @@
     logbuf_assert("Invalid argument mod (lys_compile()).");
     assert_int_equal(LY_EINVAL, lys_compile(&mod, 0));
     logbuf_assert("Invalid argument *mod (lys_compile()).");
-    assert_non_null(mod = lys_parse_mem_module(ctx, str, LYS_IN_YANG, 0, NULL, NULL));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_non_null(mod = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 0, NULL, NULL));
+    ly_in_free(in, 0);
     assert_int_equal(0, mod->implemented);
     assert_int_equal(LY_SUCCESS, lys_compile(&mod, 0));
     assert_null(mod->compiled);
@@ -139,12 +142,16 @@
 
     /* submodules cannot be compiled directly */
     str = "submodule test {belongs-to xxx {prefix x;}}";
-    assert_null(lys_parse_mem_module(ctx, str, LYS_IN_YANG, 1, NULL, NULL));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+    ly_in_free(in, 0);
     logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
 
     /* data definition name collision in top level */
-    assert_non_null(mod = lys_parse_mem_module(ctx, "module aa {namespace urn:aa;prefix aa;"
-                                        "leaf a {type string;} container a{presence x;}}", LYS_IN_YANG, 1, NULL, NULL));
+    str = "module aa {namespace urn:aa;prefix aa; leaf a {type string;} container a{presence x;}}";
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_non_null(mod = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+    ly_in_free(in, 0);
     assert_int_equal(LY_EVALID, lys_compile(&mod, 0));
     logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /aa:a");
     assert_null(mod);
diff --git a/tests/utests/test_context.c b/tests/utests/test_context.c
index 5f14972..9a09dee 100644
--- a/tests/utests/test_context.c
+++ b/tests/utests/test_context.c
@@ -22,6 +22,7 @@
 
 #include "common.h"
 #include "context.h"
+#include "parser.h"
 #include "tests/config.h"
 #include "tree_schema_internal.h"
 
@@ -272,6 +273,7 @@
     *state = test_models;
 
     struct ly_ctx *ctx;
+    struct ly_in *in;
     const char *str;
     struct lys_module *mod1, *mod2;
 
@@ -282,7 +284,9 @@
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
     assert_int_equal(ctx->module_set_id, ly_ctx_get_module_set_id(ctx));
 
-    assert_null(lys_parse_mem_module(ctx, "module x {namespace urn:x;prefix x;}", 4, 1, NULL, NULL));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module x {namespace urn:x;prefix x;}", &in));
+    assert_null(lys_parse_mem_module(ctx, in, 4, 1, NULL, NULL));
+    ly_in_free(in, 0);
     logbuf_assert("Invalid schema input format.");
 
     /* import callback */
@@ -298,18 +302,26 @@
 
     /* name collision of module and submodule */
     ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule y {belongs-to a {prefix a;} revision 2018-10-30;}");
-    assert_null(lys_parse_mem_module(ctx, "module y {namespace urn:y;prefix y;include y;}", LYS_IN_YANG, 1, NULL, NULL));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module y {namespace urn:y;prefix y;include y;}", &in));
+    assert_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+    ly_in_free(in, 0);
     assert_int_equal(LY_EVALID, ly_errcode(ctx));
     logbuf_assert("Name collision between module and submodule of name \"y\". Line number 1.");
 
-    assert_non_null(lys_parse_mem_module(ctx, "module a {namespace urn:a;prefix a;include y;revision 2018-10-30; }", LYS_IN_YANG, 1, NULL, NULL));
-    assert_null(lys_parse_mem_module(ctx, "module y {namespace urn:y;prefix y;}", LYS_IN_YANG, 1, NULL, NULL));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module a {namespace urn:a;prefix a;include y;revision 2018-10-30; }", &in));
+    assert_non_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+    ly_in_free(in, 0);
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module y {namespace urn:y;prefix y;}", &in));
+    assert_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+    ly_in_free(in, 0);
     assert_int_equal(LY_EVALID, ly_errcode(ctx));
     logbuf_assert("Name collision between module and submodule of name \"y\". Line number 1.");
 
     store = 1;
     ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule y {belongs-to b {prefix b;}}");
-    assert_null(lys_parse_mem_module(ctx, "module b {namespace urn:b;prefix b;include y;}", LYS_IN_YANG, 1, NULL, NULL));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module b {namespace urn:b;prefix b;include y;}", &in));
+    assert_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+    ly_in_free(in, 0);
     assert_int_equal(LY_EVALID, ly_errcode(ctx));
     logbuf_assert("Name collision between submodules of name \"y\". Line number 1.");
     store = -1;
@@ -317,18 +329,24 @@
     /* selecting correct revision of the submodules */
     ly_ctx_reset_latests(ctx);
     ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule y {belongs-to a {prefix a;} revision 2018-10-31;}");
-    mod2 = lys_parse_mem_module(ctx, "module a {namespace urn:a;prefix a;include y; revision 2018-10-31;}", LYS_IN_YANG, 0, NULL, NULL);
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module a {namespace urn:a;prefix a;include y; revision 2018-10-31;}", &in));
+    mod2 = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 0, NULL, NULL);
+    ly_in_free(in, 0);
     assert_non_null(mod2);
     assert_string_equal("2018-10-31", mod2->parsed->includes[0].submodule->revs[0].date);
 
     /* reloading module in case only the compiled module resists in the context */
-    mod1 = lys_parse_mem_module(ctx, "module w {namespace urn:w;prefix w;revision 2018-10-24;}", LYS_IN_YANG, 1, NULL, NULL);
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module w {namespace urn:w;prefix w;revision 2018-10-24;}", &in));
+    mod1 = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL);
+    ly_in_free(in, 0);
     assert_non_null(mod1);
     assert_int_equal(LY_SUCCESS, lys_compile(&mod1, LYSC_OPT_FREE_SP));
     assert_non_null(mod1->compiled);
     assert_null(mod1->parsed);
 
-    mod2 = lys_parse_mem_module(ctx, "module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", LYS_IN_YANG, 1, NULL, NULL);
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", &in));
+    mod2 = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL);
+    ly_in_free(in, 0);
     assert_non_null(mod2);
     /* mod1->parsed is necessary to compile mod2 because of possible groupings, typedefs, ... */
     ly_ctx_set_module_imp_clb(ctx, NULL, NULL);
@@ -336,7 +354,9 @@
     logbuf_assert("Unable to reload \"w\" module to import it into \"z\", source data not found.");
     assert_null(mod2);
 
-    mod2 = lys_parse_mem_module(ctx, "module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", LYS_IN_YANG, 1, NULL, NULL);
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", &in));
+    mod2 = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL);
+    ly_in_free(in, 0);
     assert_non_null(mod2);
     ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module w {namespace urn:w;prefix w;revision 2018-10-24;}");
     assert_int_equal(LY_SUCCESS, lys_compile(&mod2, 0));
@@ -404,10 +424,14 @@
     const char *str0 = "module a {namespace urn:a;prefix a;}";
     const char *str1 = "module a {namespace urn:a;prefix a;revision 2018-10-23;}";
     const char *str2 = "module a {namespace urn:a;prefix a;revision 2018-10-23;revision 2018-10-24;}";
+    struct ly_in *in0, *in1, *in2;
 
     unsigned int index = 0;
     const char *names[] = {"ietf-yang-metadata", "yang", "ietf-inet-types", "ietf-yang-types", "ietf-datastores", "ietf-yang-library", "a", "a", "a"};
 
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str0, &in0));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str1, &in1));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str2, &in2));
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
     /* invalid arguments */
@@ -435,14 +459,16 @@
     assert_non_null(ly_ctx_get_module_ns(ctx, "urn:ietf:params:xml:ns:yang:ietf-datastores", "2018-02-14"));
 
     /* select module by revision */
-    mod = lys_parse_mem_module(ctx, str1, LYS_IN_YANG, 1, NULL, NULL);
+    mod = lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL);
     /* invalid attempts - implementing module of the same name and inserting the same module */
-    assert_null(lys_parse_mem_module(ctx, str2, LYS_IN_YANG, 1, NULL, NULL));
+    assert_null(lys_parse_mem_module(ctx, in2, LYS_IN_YANG, 1, NULL, NULL));
     logbuf_assert("Module \"a\" is already implemented in the context.");
-    assert_null(lys_parse_mem_module(ctx, str1, LYS_IN_YANG, 0, NULL, NULL));
+    ly_in_reset(in1);
+    assert_null(lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 0, NULL, NULL));
     logbuf_assert("Module \"a\" of revision \"2018-10-23\" is already present in the context.");
     /* insert the second module only as imported, not implemented */
-    mod2 = lys_parse_mem_module(ctx, str2, LYS_IN_YANG, 0, NULL, NULL);
+    ly_in_reset(in2);
+    mod2 = lys_parse_mem_module(ctx, in2, LYS_IN_YANG, 0, NULL, NULL);
     assert_non_null(mod);
     assert_non_null(mod2);
     assert_ptr_not_equal(mod, mod2);
@@ -451,13 +477,15 @@
     mod2 = ly_ctx_get_module_latest_ns(ctx, mod->ns);
     assert_ptr_equal(mod, mod2);
     /* work with module with no revision */
-    mod = lys_parse_mem_module(ctx, str0, LYS_IN_YANG, 0, NULL, NULL);
+    mod = lys_parse_mem_module(ctx, in0, LYS_IN_YANG, 0, NULL, NULL);
     assert_non_null(mod);
     assert_ptr_equal(mod, ly_ctx_get_module(ctx, "a", NULL));
     assert_ptr_not_equal(mod, ly_ctx_get_module_latest(ctx, "a"));
 
     str1 = "submodule b {belongs-to a {prefix a;}}";
-    assert_null(lys_parse_mem_module(ctx, str1, LYS_IN_YANG, 1, NULL, NULL));
+    ly_in_free(in1, 0);
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str1, &in1));
+    assert_null(lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL));
     logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
 
     while ((mod = ly_ctx_get_module_iter(ctx, &index))) {
@@ -467,6 +495,9 @@
 
     /* cleanup */
     *state = NULL;
+    ly_in_free(in0, 0);
+    ly_in_free(in1, 0);
+    ly_in_free(in2, 0);
     ly_ctx_destroy(ctx, NULL);
 }
 
diff --git a/tests/utests/test_xml.c b/tests/utests/test_xml.c
index e9e22e1..ca1c260 100644
--- a/tests/utests/test_xml.c
+++ b/tests/utests/test_xml.c
@@ -24,8 +24,10 @@
 #include <stdio.h>
 #include <string.h>
 
-#include "xml.h"
 #include "context.h"
+#include "parser.h"
+#include "parser_internal.h"
+#include "xml.h"
 
 LY_ERR lyxml_ns_add(struct lyxml_ctx *xmlctx, const char *prefix, size_t prefix_len, char *uri);
 LY_ERR lyxml_ns_rm(struct lyxml_ctx *xmlctx);
@@ -91,39 +93,50 @@
 test_element(void **state)
 {
     struct lyxml_ctx *xmlctx;
+    struct ly_in *in;
     const char *str;
 
     /* empty */
     str = "";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_END, xmlctx->status);
-    assert_true(xmlctx->input[0] == '\0');
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 
     /* end element */
     str = "</element>";
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
     logbuf_assert("Stray closing element tag (\"element\"). Line number 1.");
+    ly_in_free(in, 0);
 
     /* no element */
     //logbuf_clean();
     str = "no data present";
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
     logbuf_assert("Invalid character sequence \"no data present\", expected element tag start ('<'). Line number 1.");
+    ly_in_free(in, 0);
 
     /* not supported DOCTYPE */
     str = "<!DOCTYPE greeting SYSTEM \"hello.dtd\"><greeting/>";
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
     logbuf_assert("Document Type Declaration not supported. Line number 1.");
+    ly_in_free(in, 0);
 
     /* invalid XML */
     str = "<!NONSENSE/>";
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
     logbuf_assert("Unknown XML section \"<!NONSENSE/>\". Line number 1.");
+    ly_in_free(in, 0);
 
     /* unqualified element */
     str = "  <  element/>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_null(xmlctx->prefix);
     assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len));
@@ -139,10 +152,12 @@
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_END, xmlctx->status);
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 
     /* element with attribute */
     str = "  <  element attr=\'x\'/>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len));
     assert_null(xmlctx->prefix);
@@ -168,10 +183,12 @@
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_END, xmlctx->status);
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 
     /* headers and comments */
     str = "<?xml version=\"1.0\"?>  <!-- comment --> <![CDATA[<greeting>Hello, world!</greeting>]]> <?TEST xxx?> <element/>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len));
     assert_null(xmlctx->prefix);
@@ -186,10 +203,12 @@
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_END, xmlctx->status);
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 
     /* separate opening and closing tags, neamespaced parsed internally */
     str = "<element xmlns=\"urn\"></element>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len));
     assert_null(xmlctx->prefix);
@@ -207,10 +226,12 @@
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_END, xmlctx->status);
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 
     /* qualified element */
     str = "  <  yin:element/>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len));
     assert_true(!strncmp("yin", xmlctx->prefix, xmlctx->prefix_len));
@@ -224,10 +245,12 @@
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_END, xmlctx->status);
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 
     /* non-matching closing tag */
     str = "<yin:element xmlns=\"urn\"></element>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len));
     assert_true(!strncmp("yin", xmlctx->prefix, xmlctx->prefix_len));
@@ -239,18 +262,23 @@
 
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Opening (\"yin:element\") and closing (\"element\") elements tag mismatch. Line number 1.");
+    lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 
-    /* just replace closing tag */
-    xmlctx->input = "</yin:element/>";
-    xmlctx->status = LYXML_ELEM_CONTENT;
-    xmlctx->dynamic = 0;
+    /* invalid closing tag */
+    str = "<yin:element xmlns=\"urn\"></yin:element/>";
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Invalid character sequence \"/>\", expected element tag termination ('>'). Line number 1.");
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 
     /* UTF8 characters */
     str = "<𠜎€𠜎Øn:𠜎€𠜎Øn/>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_true(!strncmp("𠜎€𠜎Øn", xmlctx->name, xmlctx->name_len));
     assert_true(!strncmp("𠜎€𠜎Øn", xmlctx->prefix, xmlctx->prefix_len));
 
@@ -263,21 +291,27 @@
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_END, xmlctx->status);
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 
     /* invalid UTF-8 characters */
     str = "<¢:element>";
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
     logbuf_assert("Identifier \"¢:element>\" starts with an invalid character. Line number 1.");
+    ly_in_free(in, 0);
 
     str = "<yin:c⁐element>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Invalid character sequence \"⁐element>\", expected element tag end ('>' or '/>') or an attribute. Line number 1.");
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 
     /* mixed content */
     str = "<a>text <b>x</b></a>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("a", xmlctx->name, xmlctx->name_len));
     assert_null(xmlctx->prefix);
@@ -304,10 +338,12 @@
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_END, xmlctx->status);
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 
     /* tag mismatch */
     str = "<a>text</b>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("a", xmlctx->name, xmlctx->name_len));
     assert_null(xmlctx->prefix);
@@ -319,6 +355,7 @@
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Opening (\"a\") and closing (\"b\") elements tag mismatch. Line number 1.");
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 }
 
 static void
@@ -326,24 +363,32 @@
 {
     const char *str;
     struct lyxml_ctx *xmlctx;
+    struct ly_in *in;
     struct lyxml_ns *ns;
 
     /* not an attribute */
     str = "<e unknown/>";
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
     logbuf_assert("Invalid character sequence \"/>\", expected '='. Line number 1.");
+    ly_in_free(in, 0);
 
     str = "<e xxx=/>";
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
     logbuf_assert("Invalid character sequence \"/>\", expected either single or double quotation mark. Line number 1.");
+    ly_in_free(in, 0);
 
     str = "<e xxx\n = yyy/>";
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
     logbuf_assert("Invalid character sequence \"yyy/>\", expected either single or double quotation mark. Line number 2.");
+    ly_in_free(in, 0);
 
     /* valid attribute */
     str = "<e attr=\"val\"";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ATTRIBUTE, xmlctx->status);
@@ -356,16 +401,19 @@
     assert_int_equal(xmlctx->ws_only, 0);
     assert_int_equal(xmlctx->dynamic, 0);
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 
     /* valid namespace with prefix */
     str = "<e xmlns:nc\n = \'urn\'/>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_int_equal(1, xmlctx->ns.count);
     ns = (struct lyxml_ns *)xmlctx->ns.objs[0];
     assert_string_equal(ns->prefix, "nc");
     assert_string_equal(ns->uri, "urn");
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 }
 
 static void
@@ -373,10 +421,12 @@
 {
     const char *str;
     struct lyxml_ctx *xmlctx;
+    struct ly_in *in;
 
     /* empty attribute value */
     str = "<e a=\"\"";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ATTRIBUTE, xmlctx->status);
@@ -386,41 +436,51 @@
     assert_true(!strncmp("", xmlctx->value, xmlctx->value_len));
     assert_int_equal(xmlctx->ws_only, 1);
     assert_int_equal(xmlctx->dynamic, 0);
+    ly_in_free(in, 0);
 
     /* empty value but in single quotes */
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'\'", &in));
+    xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
-    xmlctx->input = "=\'\'";
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ATTR_CONTENT, xmlctx->status);
     assert_true(!strncmp("", xmlctx->value, xmlctx->value_len));
     assert_int_equal(xmlctx->ws_only, 1);
     assert_int_equal(xmlctx->dynamic, 0);
+    ly_in_free(in, 0);
 
     /* empty element content - only formating before defining child */
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(">\n  <y>", &in));
+    xmlctx->in = in;
     xmlctx->status = LYXML_ELEMENT;
-    xmlctx->input = ">\n  <y>";
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status);
     assert_true(!strncmp("\n  ", xmlctx->value, xmlctx->value_len));
     assert_int_equal(xmlctx->ws_only, 1);
     assert_int_equal(xmlctx->dynamic, 0);
+    ly_in_free(in, 0);
 
     /* empty element content is invalid - missing content terminating character < */
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("", &in));
+    xmlctx->in = in;
     xmlctx->status = LYXML_ELEM_CONTENT;
-    xmlctx->input = "";
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Unexpected end-of-input. Line number 2.");
+    ly_in_free(in, 0);
 
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("xxx", &in));
+    xmlctx->in = in;
     xmlctx->status = LYXML_ELEM_CONTENT;
-    xmlctx->input = "xxx";
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Invalid character sequence \"xxx\", expected element tag start ('<'). Line number 2.");
+    ly_in_free(in, 0);
 
     lyxml_ctx_free(xmlctx);
 
     /* valid strings */
     str = "<a>€𠜎Øn \n&lt;&amp;&quot;&apos;&gt; &#82;&#x4f;&#x4B;</a>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
 
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
@@ -429,52 +489,69 @@
     assert_int_equal(xmlctx->ws_only, 0);
     assert_int_equal(xmlctx->dynamic, 1);
     free((char *)xmlctx->value);
+    ly_in_free(in, 0);
 
     /* test using n-bytes UTF8 hexadecimal code points */
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'&#x0024;&#x00A2;&#x20ac;&#x10348;\'", &in));
+    xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
-    xmlctx->input = "=\'&#x0024;&#x00A2;&#x20ac;&#x10348;\'";
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ATTR_CONTENT, xmlctx->status);
     assert_true(!strncmp("$¢€𐍈", xmlctx->value, xmlctx->value_len));
     assert_int_equal(xmlctx->ws_only, 0);
     assert_int_equal(xmlctx->dynamic, 1);
     free((char *)xmlctx->value);
+    ly_in_free(in, 0);
 
     /* invalid characters in string */
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'&#x52\'", &in));
+    xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
-    xmlctx->input = "=\'&#x52\'";
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Invalid character sequence \"'\", expected ;. Line number 2.");
+    ly_in_free(in, 0);
 
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\"&#82\"", &in));
+    xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
-    xmlctx->input = "=\"&#82\"";
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Invalid character sequence \"\"\", expected ;. Line number 2.");
+    ly_in_free(in, 0);
 
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\"&nonsense;\"", &in));
+    xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
-    xmlctx->input = "=\"&nonsense;\"";
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Entity reference \"&nonsense;\" not supported, only predefined references allowed. Line number 2.");
+    ly_in_free(in, 0);
 
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(">&#o122;", &in));
+    xmlctx->in = in;
     xmlctx->status = LYXML_ELEMENT;
-    xmlctx->input = ">&#o122;";
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Invalid character reference \"&#o122;\". Line number 2.");
+    ly_in_free(in, 0);
 
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'&#x06;\'", &in));
+    xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
-    xmlctx->input = "=\'&#x06;\'";
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Invalid character reference \"&#x06;\'\" (0x00000006). Line number 2.");
+    ly_in_free(in, 0);
 
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'&#xfdd0;\'", &in));
+    xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
-    xmlctx->input = "=\'&#xfdd0;\'";
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Invalid character reference \"&#xfdd0;\'\" (0x0000fdd0). Line number 2.");
+    ly_in_free(in, 0);
 
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'&#xffff;\'", &in));
+    xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
-    xmlctx->input = "=\'&#xffff;\'";
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
     logbuf_assert("Invalid character reference \"&#xffff;\'\" (0x0000ffff). Line number 2.");
+    ly_in_free(in, 0);
 
     lyxml_ctx_free(xmlctx);
 }
@@ -484,11 +561,13 @@
 {
     const char *str;
     struct lyxml_ctx *xmlctx;
+    struct ly_in *in;
     const struct lyxml_ns *ns;
 
     /* opening element1 */
     str = "<element1/>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
 
     /* processing namespace definitions */
     assert_int_equal(LY_SUCCESS, lyxml_ns_add(xmlctx, NULL, 0, strdup("urn:default")));
@@ -529,6 +608,7 @@
     assert_null(lyxml_ns_get(xmlctx, NULL, 0));
 
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 }
 
 static void
@@ -536,10 +616,12 @@
 {
     const char *str;
     struct lyxml_ctx *xmlctx;
+    struct ly_in *in;
 
     /* opening element1 */
     str = "<element1/>";
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, str, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
 
     /* default namespace defined in parent element1 */
     assert_int_equal(LY_SUCCESS, lyxml_ns_add(xmlctx, NULL, 0, strdup("urn:default")));
@@ -558,59 +640,63 @@
     assert_int_equal(0, xmlctx->ns.count);
 
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 }
 
 static void
 test_simple_xml(void **state)
 {
     struct lyxml_ctx *xmlctx;
+    struct ly_in *in;
     const char *test_input = "<elem1 attr1=\"value\"> <elem2 attr2=\"value\" /> </elem1>";
 
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, test_input, &xmlctx));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(test_input, &in));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
-    assert_string_equal(xmlctx->input, "attr1=\"value\"> <elem2 attr2=\"value\" /> </elem1>");
+    assert_string_equal(xmlctx->in->current, "attr1=\"value\"> <elem2 attr2=\"value\" /> </elem1>");
 
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ATTRIBUTE, xmlctx->status);
-    assert_string_equal(xmlctx->input, "=\"value\"> <elem2 attr2=\"value\" /> </elem1>");
+    assert_string_equal(xmlctx->in->current, "=\"value\"> <elem2 attr2=\"value\" /> </elem1>");
 
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ATTR_CONTENT, xmlctx->status);
-    assert_string_equal(xmlctx->input, "> <elem2 attr2=\"value\" /> </elem1>");
+    assert_string_equal(xmlctx->in->current, "> <elem2 attr2=\"value\" /> </elem1>");
 
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status);
-    assert_string_equal(xmlctx->input, "<elem2 attr2=\"value\" /> </elem1>");
+    assert_string_equal(xmlctx->in->current, "<elem2 attr2=\"value\" /> </elem1>");
 
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
-    assert_string_equal(xmlctx->input, "attr2=\"value\" /> </elem1>");
+    assert_string_equal(xmlctx->in->current, "attr2=\"value\" /> </elem1>");
 
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ATTRIBUTE, xmlctx->status);
-    assert_string_equal(xmlctx->input, "=\"value\" /> </elem1>");
+    assert_string_equal(xmlctx->in->current, "=\"value\" /> </elem1>");
 
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ATTR_CONTENT, xmlctx->status);
-    assert_string_equal(xmlctx->input, " /> </elem1>");
+    assert_string_equal(xmlctx->in->current, " /> </elem1>");
 
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status);
-    assert_string_equal(xmlctx->input, "/> </elem1>");
+    assert_string_equal(xmlctx->in->current, "/> </elem1>");
 
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ELEM_CLOSE, xmlctx->status);
-    assert_string_equal(xmlctx->input, " </elem1>");
+    assert_string_equal(xmlctx->in->current, " </elem1>");
 
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ELEM_CLOSE, xmlctx->status);
-    assert_string_equal(xmlctx->input, "");
+    assert_string_equal(xmlctx->in->current, "");
 
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_END, xmlctx->status);
-    assert_string_equal(xmlctx->input, "");
+    assert_string_equal(xmlctx->in->current, "");
 
     lyxml_ctx_free(xmlctx);
+    ly_in_free(in, 0);
 }
 
 int main(void)