1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

DOM: Add test for dumping DOM trees to SGML

This commit is contained in:
Jonas Fonseca 2006-01-30 06:25:22 +01:00 committed by Jonas Fonseca
parent f8a86a26c4
commit 7be0093e36
2 changed files with 185 additions and 3 deletions

View File

@ -13,6 +13,7 @@
#include "dom/configuration.h"
#include "dom/node.h"
#include "dom/sgml/dump.h"
#include "dom/sgml/parser.h"
#include "dom/stack.h"
@ -265,6 +266,7 @@ main(int argc, char *argv[])
enum sgml_parser_code code = 0;
enum dom_config_flag normalize_flags = 0;
int normalize = 0;
int dump = 0;
int complete = 1;
size_t read_stdin = 0;
struct dom_string uri = STATIC_DOM_STRING("dom://test");
@ -338,6 +340,10 @@ main(int argc, char *argv[])
flags |= SGML_PARSER_INCREMENTAL;
complete = 0;
} else if (!strcmp(arg, "dump")) {
type = SGML_PARSER_TREE;
dump = 1;
} else if (!strcmp(arg, "error")) {
flags |= SGML_PARSER_DETECT_ERRORS;
@ -355,7 +361,7 @@ main(int argc, char *argv[])
parser->error_func = sgml_error_function;
if (normalize)
add_dom_config_normalizer(&parser->stack, normalize_flags);
else
else if (!dump)
add_dom_stack_context(&parser->stack, NULL, &sgml_parser_test_context_info);
if (read_stdin > 0) {
@ -402,7 +408,7 @@ main(int argc, char *argv[])
pop_dom_node(&parser->stack);
}
if (normalize) {
if (normalize || dump) {
struct dom_stack stack;
/* Note, that we cannot free nodes when walking the DOM
@ -412,7 +418,10 @@ main(int argc, char *argv[])
/* XXX: This context needs to be added first because it
* assumes the parser can be accessed via
* stack->contexts[0].data. */
add_dom_stack_context(&stack, parser, &sgml_parser_test_context_info);
if (normalize)
add_dom_stack_context(&stack, parser, &sgml_parser_test_context_info);
else if (dump)
add_sgml_file_dumper(&stack, stdout);
walk_dom_nodes(&stack, parser->root);
done_dom_stack(&stack);
done_dom_node(parser->root);

173
src/dom/test/test-sgml-dump-basic Executable file
View File

@ -0,0 +1,173 @@
#!/bin/sh
#
# Copyright (c) 2005 Jonas Fonseca
#
test_description='Test dumping of SGML documents.
Test that DOM documents are consistently dumped to SGML.
Note, this also test whether attribute nodes are sorted
correctly.
'
. "$TEST_LIB"
test_sgml_dump_exact () {
desc="$1"; shift
src="$1"; shift
sgml-parser --dump --src "$src" > output
echo -n "$src" > expected
test_expect_success "$desc" 'cmp output expected'
}
test_sgml_dump_equals () {
desc="$1"; shift
src="$1"; shift
out="$1"; shift
sgml-parser --dump --src "$src" > output
echo -n "$out" > expected
test_expect_success "$desc" 'cmp output expected'
}
################################################################
# Parse various SGML node types.
test_sgml_dump_exact \
'Parse a small document.' \
'<html><body><p>Hello World!</p></body></html>'
test_sgml_dump_exact \
'Parse an enclosed comment.' \
'<root><!-- Hello World! --></root>'
test_sgml_dump_exact \
'Parse comment combinations. (I)' \
'<root><!-- <!-- -- > --><!--foo--><!----></root>'
test_sgml_dump_exact \
'Parse comment combinations. (II).' \
'<!-- comment -->s<!-->-->t<!----->u'
test_sgml_dump_exact \
'Parse empty comment.' \
'<!---->s'
test_sgml_dump_exact \
'Parse an enclosed CDATA section.' \
'<root><![CDATA[...] ]>...]]></root>'
test_sgml_dump_exact \
'Parse non-enclosed CDATA section.' \
'<![CDATA[...]]>'
test_sgml_dump_exact \
'Parse attributes.' \
'<e a="1" b="2" c=""></e>'
test_sgml_dump_exact \
'Parse XML stylesheet processing instructions.' \
'<?xml-stylesheet type="text/xsl" href="url"?>'
test_sgml_dump_exact \
'Parse entity references.' \
'&amp;-&#42;'
#############################################################################
# Test tidy up dumping
test_sgml_dump_equals \
'Parse elements.' \
'<root><child attr="value" /><child2></><child3 >a</></root>' \
'<root><child attr="value"></child><child2></child2><child3>a</child3></root>'
test_sgml_dump_equals \
'Parse attributes with garbage.' \
"<root a=b c='d' e'f' g= h i = j k =></root>" \
"<root a=\"b\" c='d' g=\"h\" i=\"j\" k></root>"
test_sgml_dump_equals \
'Parse bad comment. (II)' \
'<!--a--!>bad comment' \
'<!--a-->bad comment'
test_sgml_dump_equals \
'Parse empty notation.' \
'<!>s' \
's'
test_sgml_dump_equals \
'Parse a bad CDATA section.' \
'<![CDATA[...' \
'<![CDATA[...]]>'
test_sgml_dump_equals \
'Parse tag soup elements. (I)' \
'<parent attr="value" <child:1></><child:2</>a</parent>' \
'<parent attr="value"><child:1></child:1><child:2></child:2>a</parent>'
test_sgml_dump_equals \
'Parse tag soup elements. (II)' \
'< a >< b < c / >< / >' \
'<a><b><c></c></b></a>'
test_sgml_dump_equals \
'Parse attribute with non-quoted values.' \
'<root color=#abc path=/to/%61-&\one";files/>...' \
'<root color="#abc" path="/to/%61-&\one";files"></root>...'
# Just how these should be gracefully handled is not clear to me.
test_sgml_dump_equals \
'Parse badly formatted entity references.' \
'& m33p;-&.:-copy;-&;-&#;-&#xx;' \
'& m33p;-&.:-copy;-&;-&#;-&#xx;'
test_sgml_dump_equals \
'Parse processing instructions.' \
'<?xml encoding="UTF8"?>
...
<?ecmascript
var val=2;
?>' \
'<?xml encoding="UTF8"?>
...
<?ecmascript var val=2;
?>'
test_sgml_dump_equals \
'Parse XML processing instructions.' \
'<?xml version="1.0" />?><?xml />-' \
'<?xml version="1.0" />?><?xml />-?>'
test_sgml_dump_equals \
'Parse exotic processing instructions.' \
'<?xml ?+>+?>-?>-<?js?>-<??>-' \
'<?xml ?+>+?>-?>-<?js ?>-<? ?>-'
test_sgml_dump_equals \
'Parse incorrect processing instructions. (II)' \
'<?js<?>-<?<??>-<?xml <=";&?>-<?' \
'<?js <?>-<? <??>-<?xml <=";&?>-' \
test_sgml_dump_equals \
'Parse incorrect processing instructions (II).' \
'<?><?' \
'<? ><??>'
test_sgml_dump_equals \
'Skip spaces not inside text.' \
'<
root
ns:attr
=
"value"
><?
target
data?>< / root >' \
'<root ns:attr="value"><?target data?></root>'
test_done