tests CHANGE enhance YANG parser tests
diff --git a/src/parser_yang.c b/src/parser_yang.c
index 4c811f4..5561c5c 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -94,7 +94,7 @@
*
* Enlarge if needed. Updates \p input as well as \p buf_used.
*
- * @param[in] ctx yang parser context for logging.
+ * @param[in] ctx libyang context for logging.
* @param[in, out] input Input string to process.
* @param[in] len Number of bytes to get from the input string and copy into the buffer.
* @param[in,out] buf Buffer to use, can be moved by realloc().
@@ -189,7 +189,7 @@
buf_store_char(struct ly_parser_ctx *ctx, const char **input, enum yang_arg arg,
char **word_p, size_t *word_len, char **word_b, size_t *buf_len, int need_buf)
{
- int prefix;
+ int prefix = 0;
unsigned int c;
size_t len;
diff --git a/tests/src/test_parser_yang.c b/tests/src/test_parser_yang.c
index 04e5b6d..ea69343 100644
--- a/tests/src/test_parser_yang.c
+++ b/tests/src/test_parser_yang.c
@@ -71,7 +71,7 @@
(void) state; /* unused */
const char *str;
- char *buf;
+ char *buf, *p;
size_t len, size;
int prefix;
struct ly_parser_ctx ctx;
@@ -88,6 +88,36 @@
assert_string_equal("cd", str);
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));
+ str = ".invalid";
+ assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
+ str = "-invalid";
+ assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
+ /* 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));
+ str = ":";
+ assert_int_equal(LY_EVALID, buf_store_char(&ctx, &str, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1));
+ /* valid colon for prefixed identifiers */
+ len = size = 0;
+ p = NULL;
+ str = "x:id";
+ assert_int_equal(LY_SUCCESS, buf_store_char(&ctx, &str, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 0));
+ assert_int_equal(1, len);
+ assert_null(buf);
+ assert_string_equal(":id", str);
+ 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));
+ assert_int_equal(2, len);
+ assert_string_equal("id", str);
+ assert_int_equal(':', p[len - 1]);
+ free(buf);
/* checking identifiers */
assert_int_equal(LY_EVALID, check_identifierchar(&ctx, ':', 0, NULL));