mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Make it possible to test how incomplete input is parsed
Also fix the expected output of proc. instruction test.
This commit is contained in:
parent
e78d43f1ac
commit
0160c0a464
@ -240,6 +240,7 @@ main(int argc, char *argv[])
|
||||
enum sgml_document_type doctype = SGML_DOCTYPE_HTML;
|
||||
enum sgml_parser_flag flags = 0;
|
||||
enum sgml_parser_code code = 0;
|
||||
int complete = 1;
|
||||
struct dom_string uri = INIT_DOM_STRING("dom://test", -1);
|
||||
struct dom_string source = INIT_DOM_STRING("(no source)", -1);
|
||||
int i;
|
||||
@ -277,7 +278,11 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
} else if (!strcmp(arg, "print-lines")) {
|
||||
flags |= SGML_PARSER_COUNT_LINES;;
|
||||
flags |= SGML_PARSER_COUNT_LINES;
|
||||
|
||||
} else if (!strcmp(arg, "incomplete")) {
|
||||
flags |= SGML_PARSER_INCREMENTAL;
|
||||
complete = 0;
|
||||
|
||||
} else if (!strcmp(arg, "help")) {
|
||||
die(NULL);
|
||||
@ -292,14 +297,18 @@ main(int argc, char *argv[])
|
||||
|
||||
add_dom_stack_context(&parser->stack, NULL, &sgml_parser_test_context_info);
|
||||
|
||||
code = parse_sgml(parser, &source, 1);
|
||||
code = parse_sgml(parser, &source, complete);
|
||||
if (parser->root) {
|
||||
assert(parser->stack.depth == 1);
|
||||
size_t root_offset = parser->stack.depth - 1;
|
||||
|
||||
assert(!complete || root_offset == 0);
|
||||
|
||||
get_dom_stack_state(&parser->stack, root_offset)->immutable = 0;
|
||||
|
||||
get_dom_stack_top(&parser->stack)->immutable = 0;
|
||||
/* For SGML_PARSER_STREAM this will free the DOM
|
||||
* root node. */
|
||||
pop_dom_node(&parser->stack);
|
||||
while (!dom_stack_is_empty(&parser->stack))
|
||||
pop_dom_node(&parser->stack);
|
||||
}
|
||||
|
||||
done_sgml_parser(parser);
|
||||
|
@ -31,6 +31,22 @@ test_output_equals () {
|
||||
test_expect_success "$desc" 'cmp -b output expected'
|
||||
}
|
||||
|
||||
test_expect_incomplete () {
|
||||
desc="$1"; shift
|
||||
src="$1"; shift
|
||||
|
||||
URI="test:$(echo "$desc" | sed '
|
||||
s/^[ \t]*\[[^]]*\][ \t]*//;
|
||||
s/[:., \t][:., \t]*/-/g;
|
||||
s/_/-/g;
|
||||
# *cough*
|
||||
y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/;
|
||||
s/[^a-zA-Z0-9-]//g;')"
|
||||
|
||||
test_expect_code 1 "$desc" \
|
||||
"sgml-parser --uri '$URI' --src '$src' --incomplete"
|
||||
}
|
||||
|
||||
|
||||
################################################################
|
||||
# Parse various SGML node types.
|
||||
@ -177,7 +193,7 @@ test_output_equals \
|
||||
'
|
||||
proc-instruction: xml -> version="1.0" />
|
||||
attribute: version -> 1.0
|
||||
proc-instruction: xml -> /'
|
||||
proc-instruction: xml -> />-'
|
||||
|
||||
test_output_equals \
|
||||
'Parse XML stylesheet processing instructions.' \
|
||||
@ -267,5 +283,68 @@ test_output_equals \
|
||||
8' \
|
||||
--print-lines
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete comment.' \
|
||||
'<!-- ... '
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete cdata section. (I)' \
|
||||
'<![CDATA[ ... '
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete cdata section. (II)' \
|
||||
'<![CDAT'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete element. (I)' \
|
||||
'<elem...'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete element. (II)' \
|
||||
'<'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete element end. (I)' \
|
||||
'<a></a'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete element end. (II)' \
|
||||
'<a></'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete attribute.' \
|
||||
'<element attr...'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete attribute value.' \
|
||||
'<element attr=...'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete attribute quoted value. (I)' \
|
||||
'<element attr="...'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete attribute quoted value. (II)' \
|
||||
'<element attr='\''...'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete processing instruction. (I)' \
|
||||
'<?xml'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete processing instruction. (II)' \
|
||||
'<?xml attr...'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete notation.' \
|
||||
'<!DOCTYPE html PUBLIC ...'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete reference. (I)' \
|
||||
'�'
|
||||
|
||||
test_expect_incomplete \
|
||||
'Check incomplete reference. (II)' \
|
||||
'&'
|
||||
|
||||
test_done
|
||||
|
Loading…
x
Reference in New Issue
Block a user