aboutsummaryrefslogtreecommitdiffstats
path: root/tests/check_error.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-10-24 04:12:43 -0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-10-24 04:12:43 -0200
commit3a5ea19f35e4228cd782d69f21f52656c1e9a1b8 (patch)
treed587ea7522d51d0d15c63c891a2b4f58e88060a0 /tests/check_error.c
parentb3eb6d3f1cae3449c8f988fe0985c58d1e22a7f8 (diff)
downloadblogc-3a5ea19f35e4228cd782d69f21f52656c1e9a1b8.tar.gz
blogc-3a5ea19f35e4228cd782d69f21f52656c1e9a1b8.tar.bz2
blogc-3a5ea19f35e4228cd782d69f21f52656c1e9a1b8.zip
error: improved error reporting for parsers
it will now report the line and the approximate position of the error.
Diffstat (limited to 'tests/check_error.c')
-rw-r--r--tests/check_error.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/tests/check_error.c b/tests/check_error.c
index 68f287a..17e1c40 100644
--- a/tests/check_error.c
+++ b/tests/check_error.c
@@ -48,7 +48,28 @@ test_error_parser(void **state)
blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10);
assert_non_null(error);
assert_int_equal(error->type, 1);
- assert_string_equal(error->msg, "asd 10\nError occurred near to 'hunda'");
+ assert_string_equal(error->msg,
+ "asd 10\nError occurred near line 3, position 2: chunda");
+ blogc_error_free(error);
+ a = "bola\nguda\nchunda";
+ error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10);
+ assert_non_null(error);
+ assert_int_equal(error->type, 1);
+ assert_string_equal(error->msg,
+ "asd 10\nError occurred near line 3, position 2: chunda");
+ blogc_error_free(error);
+ a = "bola\nguda\nchunda";
+ error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10);
+ assert_non_null(error);
+ assert_int_equal(error->type, 1);
+ assert_string_equal(error->msg,
+ "asd 10\nError occurred near line 1, position 1: bola");
+ blogc_error_free(error);
+ a = "";
+ error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10);
+ assert_non_null(error);
+ assert_int_equal(error->type, 1);
+ assert_string_equal(error->msg, "asd 10");
blogc_error_free(error);
}
@@ -60,7 +81,22 @@ test_error_parser_crlf(void **state)
blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10);
assert_non_null(error);
assert_int_equal(error->type, 1);
- assert_string_equal(error->msg, "asd 10\nError occurred near to 'hunda'");
+ assert_string_equal(error->msg,
+ "asd 10\nError occurred near line 3, position 2: chunda");
+ blogc_error_free(error);
+ a = "bola\r\nguda\r\nchunda";
+ error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10);
+ assert_non_null(error);
+ assert_int_equal(error->type, 1);
+ assert_string_equal(error->msg,
+ "asd 10\nError occurred near line 3, position 2: chunda");
+ blogc_error_free(error);
+ a = "bola\r\nguda\r\nchunda";
+ error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10);
+ assert_non_null(error);
+ assert_int_equal(error->type, 1);
+ assert_string_equal(error->msg,
+ "asd 10\nError occurred near line 1, position 1: bola");
blogc_error_free(error);
}