diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-07-03 06:05:39 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-07-03 06:05:39 +0200 |
commit | b431f79db6deb75229748f80a3e9e448b6dacf31 (patch) | |
tree | e7ffe0864ab6e0db213afcb0e2a260d27b663d69 /tests | |
parent | 3968529cad2baec099acff5fee47b5fe24624b03 (diff) | |
download | blogc-b431f79db6deb75229748f80a3e9e448b6dacf31.tar.gz blogc-b431f79db6deb75229748f80a3e9e448b6dacf31.tar.bz2 blogc-b431f79db6deb75229748f80a3e9e448b6dacf31.zip |
Revert "error: improved parser error reporting"
this will not work properly for unicode chars
This reverts commit 3968529cad2baec099acff5fee47b5fe24624b03.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/check_error.c | 24 | ||||
-rw-r--r-- | tests/check_source_parser.c | 28 | ||||
-rw-r--r-- | tests/check_template_parser.c | 141 |
3 files changed, 61 insertions, 132 deletions
diff --git a/tests/check_error.c b/tests/check_error.c index a954095..8818b00 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -49,27 +49,21 @@ test_error_parser(void **state) assert_non_null(error); assert_int_equal(error->type, 1); assert_string_equal(error->msg, - "asd 10\nError occurred near line 3, position 2:\n" - "chunda\n" - " ^"); + "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:\n" - "chunda\n" - " ^"); + "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:\n" - "bola\n" - "^"); + "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); @@ -88,27 +82,21 @@ test_error_parser_crlf(void **state) assert_non_null(error); assert_int_equal(error->type, 1); assert_string_equal(error->msg, - "asd 10\nError occurred near line 3, position 2:\n" - "chunda\n" - " ^"); + "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:\n" - "chunda\n" - " ^"); + "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:\n" - "bola\n" - "^"); + "asd 10\nError occurred near line 1, position 1: bola"); blogc_error_free(error); } diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index 2dcaad6..d94dc70 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -220,9 +220,7 @@ test_source_parse_config_invalid_key(void **state) assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Can't find a configuration key or the content separator.\n" - "Error occurred near line 1, position 1:\n" - "bola: guda\n" - "^"); + "Error occurred near line 1, position 1: bola: guda"); blogc_error_free(err); sb_trie_free(source); } @@ -238,9 +236,7 @@ test_source_parse_config_no_key(void **state) assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Invalid configuration key.\n" - "Error occurred near line 1, position 4:\n" - "BOLa\n" - " ^"); + "Error occurred near line 1, position 4: BOLa"); blogc_error_free(err); sb_trie_free(source); } @@ -256,9 +252,7 @@ test_source_parse_config_no_key2(void **state) assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Your last configuration key is missing ':' and the value\n" - "Error occurred near line 1, position 5:\n" - "BOLA\n" - " ^"); + "Error occurred near line 1, position 5: BOLA"); blogc_error_free(err); sb_trie_free(source); } @@ -275,9 +269,7 @@ test_source_parse_config_no_value(void **state) assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Configuration value not provided for 'BOLA'.\n" - "Error occurred near line 1, position 6:\n" - "BOLA:\n" - " ^"); + "Error occurred near line 1, position 6: BOLA:"); blogc_error_free(err); sb_trie_free(source); } @@ -294,9 +286,7 @@ test_source_parse_config_no_value2(void **state) assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Configuration value not provided for 'BOLA'.\n" - "Error occurred near line 1, position 6:\n" - "BOLA:\n" - " ^"); + "Error occurred near line 1, position 6: BOLA:"); blogc_error_free(err); sb_trie_free(source); } @@ -500,9 +490,7 @@ test_source_parse_config_value_no_line_ending(void **state) assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "No line ending after the configuration value for 'BOLA'.\n" - "Error occurred near line 1, position 10:\n" - "BOLA: asd\n" - " ^"); + "Error occurred near line 1, position 10: BOLA: asd"); blogc_error_free(err); sb_trie_free(source); } @@ -519,9 +507,7 @@ test_source_parse_invalid_separator(void **state) assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Invalid content separator. Must be more than one '-' characters.\n" - "Error occurred near line 2, position 4:\n" - "---#\n" - " ^"); + "Error occurred near line 2, position 4: ---#"); blogc_error_free(err); sb_trie_free(source); } diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index 8264ffa..d2d5e8d 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -455,9 +455,7 @@ test_template_parse_invalid_block_start(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must begin with lowercase letter.\n" - "Error occurred near line 1, position 4:\n" - "{% ASD %}\n" - " ^"); + "Error occurred near line 1, position 4: {% ASD %}"); blogc_error_free(err); a = "{%-- block entry %}\n"; err = NULL; @@ -467,9 +465,7 @@ test_template_parse_invalid_block_start(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Duplicated whitespace cleaner before statement.\n" - "Error occurred near line 1, position 4:\n" - "{%-- block entry %}\n" - " ^"); + "Error occurred near line 1, position 4: {%-- block entry %}"); blogc_error_free(err); a = "{% block entry --%}\n"; err = NULL; @@ -479,9 +475,7 @@ test_template_parse_invalid_block_start(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Duplicated whitespace cleaner after statement.\n" - "Error occurred near line 1, position 17:\n" - "{% block entry --%}\n" - " ^"); + "Error occurred near line 1, position 17: {% block entry --%}"); blogc_error_free(err); } @@ -499,9 +493,7 @@ test_template_parse_invalid_block_nested(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Blocks can't be nested.\n" - "Error occurred near line 2, position 9:\n" - "{% block listing %}\n" - " ^"); + "Error occurred near line 2, position 9: {% block listing %}"); blogc_error_free(err); } @@ -519,9 +511,7 @@ test_template_parse_invalid_foreach_nested(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'foreach' statements can't be nested.\n" - "Error occurred near line 2, position 11:\n" - "{% foreach B %}\n" - " ^"); + "Error occurred near line 2, position 11: {% foreach B %}"); blogc_error_free(err); } @@ -537,9 +527,7 @@ test_template_parse_invalid_block_not_open(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endblock' statement without an open 'block' statement.\n" - "Error occurred near line 1, position 12:\n" - "{% endblock %}\n" - " ^"); + "Error occurred near line 1, position 12: {% endblock %}"); blogc_error_free(err); } @@ -555,9 +543,8 @@ test_template_parse_invalid_endif_not_open(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endif' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n" - "Error occurred near line 1, position 28:\n" - "{% block listing %}{% endif %}{% endblock %}\n" - " ^"); + "Error occurred near line 1, position 28: " + "{% block listing %}{% endif %}{% endblock %}"); blogc_error_free(err); } @@ -573,9 +560,7 @@ test_template_parse_invalid_endforeach_not_open(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endforeach' statement without an open 'foreach' statement.\n" - "Error occurred near line 1, position 14:\n" - "{% endforeach %}\n" - " ^"); + "Error occurred near line 1, position 14: {% endforeach %}"); blogc_error_free(err); } @@ -592,9 +577,7 @@ test_template_parse_invalid_block_name(void **state) assert_string_equal(err->msg, "Invalid statement type: Allowed types are: 'block', 'endblock', 'ifdef', " "'ifndef', 'else', 'endif', 'foreach' and 'endforeach'.\n" - "Error occurred near line 1, position 10:\n" - "{% chunda %}\n" - " ^"); + "Error occurred near line 1, position 10: {% chunda %}"); blogc_error_free(err); } @@ -610,9 +593,7 @@ test_template_parse_invalid_block_type_start(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid block syntax. Must begin with lowercase letter.\n" - "Error occurred near line 1, position 10:\n" - "{% block ENTRY %}\n" - " ^"); + "Error occurred near line 1, position 10: {% block ENTRY %}"); blogc_error_free(err); } @@ -628,9 +609,7 @@ test_template_parse_invalid_block_type(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid block type. Allowed types are: 'entry', 'listing' and 'listing_once'.\n" - "Error occurred near line 1, position 16:\n" - "{% block chunda %}\n" - " ^"); + "Error occurred near line 1, position 16: {% block chunda %}"); blogc_error_free(err); } @@ -646,9 +625,8 @@ test_template_parse_invalid_ifdef_start(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" - "Error occurred near line 1, position 27:\n" - "{% block entry %}{% ifdef guda %}\n" - " ^"); + "Error occurred near line 1, position 27: " + "{% block entry %}{% ifdef guda %}"); blogc_error_free(err); } @@ -664,9 +642,8 @@ test_template_parse_invalid_foreach_start(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must begin with uppercase letter.\n" - "Error occurred near line 1, position 29:\n" - "{% block entry %}{% foreach guda %}\n" - " ^"); + "Error occurred near line 1, position 29: " + "{% block entry %}{% foreach guda %}"); blogc_error_free(err); } @@ -682,9 +659,8 @@ test_template_parse_invalid_ifdef_variable(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must be uppercase letter, number or '_'.\n" - "Error occurred near line 1, position 28:\n" - "{% block entry %}{% ifdef BoLA %}\n" - " ^"); + "Error occurred near line 1, position 28: " + "{% block entry %}{% ifdef BoLA %}"); blogc_error_free(err); } @@ -700,9 +676,8 @@ test_template_parse_invalid_ifdef_variable2(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" - "Error occurred near line 1, position 27:\n" - "{% block entry %}{% ifdef 0123 %}\n" - " ^"); + "Error occurred near line 1, position 27: " + "{% block entry %}{% ifdef 0123 %}"); blogc_error_free(err); } @@ -718,9 +693,8 @@ test_template_parse_invalid_foreach_variable(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must be uppercase letter, number or '_'.\n" - "Error occurred near line 1, position 30:\n" - "{% block entry %}{% foreach BoLA %}\n" - " ^"); + "Error occurred near line 1, position 30: " + "{% block entry %}{% foreach BoLA %}"); blogc_error_free(err); } @@ -736,9 +710,8 @@ test_template_parse_invalid_foreach_variable2(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must begin with uppercase letter.\n" - "Error occurred near line 1, position 29:\n" - "{% block entry %}{% foreach 0123 %}\n" - " ^"); + "Error occurred near line 1, position 29: {% block entry %}" + "{% foreach 0123 %}"); blogc_error_free(err); } @@ -754,9 +727,8 @@ test_template_parse_invalid_if_operator(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operator. Must be '<', '>', '<=', '>=', '==' or '!='.\n" - "Error occurred near line 1, position 29:\n" - "{% block entry %}{% if BOLA = \"asd\" %}\n" - " ^"); + "Error occurred near line 1, position 29: " + "{% block entry %}{% if BOLA = \"asd\" %}"); blogc_error_free(err); } @@ -772,9 +744,8 @@ test_template_parse_invalid_if_operand(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operand. Must be double-quoted static string or variable.\n" - "Error occurred near line 1, position 32:\n" - "{% block entry %}{% if BOLA == asd %}\n" - " ^"); + "Error occurred near line 1, position 32: " + "{% block entry %}{% if BOLA == asd %}"); blogc_error_free(err); } @@ -790,9 +761,8 @@ test_template_parse_invalid_if_operand2(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Found an open double-quoted string.\n" - "Error occurred near line 1, position 32:\n" - "{% block entry %}{% if BOLA == \"asd %}\n" - " ^"); + "Error occurred near line 1, position 31: " + "{% block entry %}{% if BOLA == \"asd %}"); blogc_error_free(err); } @@ -808,9 +778,8 @@ test_template_parse_invalid_if_operand3(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operand. Must be double-quoted static string or variable.\n" - "Error occurred near line 1, position 32:\n" - "{% block entry %}{% if BOLA == 0123 %}\n" - " ^"); + "Error occurred near line 1, position 32: " + "{% block entry %}{% if BOLA == 0123 %}"); blogc_error_free(err); } @@ -826,9 +795,7 @@ test_template_parse_invalid_else1(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'else' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n" - "Error occurred near line 1, position 8:\n" - "{% else %}\n" - " ^"); + "Error occurred near line 1, position 8: {% else %}"); blogc_error_free(err); } @@ -844,9 +811,8 @@ test_template_parse_invalid_else2(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "More than one 'else' statement for an open 'if', 'ifdef' or 'ifndef' " - "statement.\nError occurred near line 1, position 60:\n" - "{% if BOLA == \"123\" %}{% if GUDA == \"1\" %}{% else %}{% else %}\n" - " ^"); + "statement.\nError occurred near line 1, position 60: {% if BOLA == \"123\" " + "%}{% if GUDA == \"1\" %}{% else %}{% else %}"); blogc_error_free(err); } @@ -869,9 +835,7 @@ test_template_parse_invalid_else3(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "More than one 'else' statement for an open 'if', 'ifdef' or 'ifndef' " - "statement.\nError occurred near line 7, position 8:\n" - "{% else %}\n" - " ^"); + "statement.\nError occurred near line 7, position 8: {% else %}"); blogc_error_free(err); } @@ -887,9 +851,7 @@ test_template_parse_invalid_block_end(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '%}'.\n" - "Error occurred near line 1, position 16:\n" - "{% block entry }}\n" - " ^"); + "Error occurred near line 1, position 16: {% block entry }}"); blogc_error_free(err); } @@ -905,9 +867,8 @@ test_template_parse_invalid_variable_name(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" - "Error occurred near line 1, position 21:\n" - "{% block entry %}{{ bola }}{% endblock %}\n" - " ^"); + "Error occurred near line 1, position 21: " + "{% block entry %}{{ bola }}{% endblock %}"); blogc_error_free(err); } @@ -923,9 +884,8 @@ test_template_parse_invalid_variable_name2(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must be uppercase letter, number or '_'.\n" - "Error occurred near line 1, position 22:\n" - "{% block entry %}{{ Bola }}{% endblock %}\n" - " ^"); + "Error occurred near line 1, position 22: " + "{% block entry %}{{ Bola }}{% endblock %}"); blogc_error_free(err); } @@ -941,9 +901,8 @@ test_template_parse_invalid_variable_name3(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" - "Error occurred near line 1, position 21:\n" - "{% block entry %}{{ 0123 }}{% endblock %}\n" - " ^"); + "Error occurred near line 1, position 21: {% block entry %}{{ 0123 }}" + "{% endblock %}"); blogc_error_free(err); } @@ -959,9 +918,8 @@ test_template_parse_invalid_variable_end(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}}'.\n" - "Error occurred near line 1, position 26:\n" - "{% block entry %}{{ BOLA %}{% endblock %}\n" - " ^"); + "Error occurred near line 1, position 26: " + "{% block entry %}{{ BOLA %}{% endblock %}"); blogc_error_free(err); } @@ -977,9 +935,7 @@ test_template_parse_invalid_close(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}'.\n" - "Error occurred near line 1, position 17:\n" - "{% block entry %%\n" - " ^"); + "Error occurred near line 1, position 17: {% block entry %%"); blogc_error_free(err); } @@ -995,9 +951,8 @@ test_template_parse_invalid_close2(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}'.\n" - "Error occurred near line 1, position 27:\n" - "{% block entry %}{{ BOLA }%{% endblock %}\n" - " ^"); + "Error occurred near line 1, position 27: " + "{% block entry %}{{ BOLA }%{% endblock %}"); blogc_error_free(err); } |