1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-02-02 15:09:23 -05:00
This commit is contained in:
Kalle Olavi Niemitalo 2007-05-26 21:53:19 +03:00 committed by Kalle Olavi Niemitalo
commit 0d76682f70
11 changed files with 74 additions and 105 deletions

View File

@ -182,6 +182,10 @@ MAKE_COLOR = @MAKE_COLOR@
LIB_O_NAME = lib.o
# Reverse a CONFIG_* string
# Usage $(call not,$(CONFIG_FOO))
not = $(if $(findstring yes,$(1)),no,yes)
### This is here because Makefile.config is usually the first thing
### we get and sometimes the all rule can be implicit, yet we want
### it always as the default one. So this should make sure it always

View File

@ -191,6 +191,21 @@ test-default:
ifdef TEST_PROGS
TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o
TESTDEPS-$(call not,$(CONFIG_SMALL)) += \
$(top_builddir)/src/util/fastfind.o \
# Add most of the basic utility library to the test dependencies.
TESTDEPS += \
$(top_builddir)/src/intl/charsets.o \
$(top_builddir)/src/osdep/stub.o \
$(top_builddir)/src/util/conv.o \
$(top_builddir)/src/util/error.o \
$(top_builddir)/src/util/file.o \
$(top_builddir)/src/util/hash.o \
$(top_builddir)/src/util/memory.o \
$(top_builddir)/src/util/string.o \
$(top_builddir)/src/util/time.o
TESTDEPS += $(TESTDEPS-yes)
TEST_LIB=$(top_srcdir)/test/libtest.sh

View File

@ -1,7 +1,7 @@
top_builddir=../..
include $(top_builddir)/Makefile.config
SUBDIRS = css sgml
SUBDIRS = css sgml test
OBJS = configuration.o node.o select.o stack.o scanner.o
SUBDIRS-$(CONFIG_DEBUG) += test

View File

@ -8,11 +8,6 @@ TEST_PROGS = \
sgml-parser
TESTDEPS = \
$(top_builddir)/src/dom/$(LIB_O_NAME) \
$(top_builddir)/src/util/error.o \
$(top_builddir)/src/osdep/stub.o \
$(top_builddir)/src/util/hash.o \
$(top_builddir)/src/util/string.o \
$(top_builddir)/src/util/memory.o
$(top_builddir)/src/dom/$(LIB_O_NAME)
include $(top_srcdir)/Makefile.lib

View File

@ -242,7 +242,8 @@ sgml_error_function(struct sgml_parser *parser, struct dom_string *string,
return DOM_CODE_OK;
}
void die(const char *msg, ...)
static void
die(const char *msg, ...)
{
va_list args;
@ -256,6 +257,29 @@ void die(const char *msg, ...)
exit(!!NULL);
}
static int
get_opt(char **argref, const char *name, int *argi, int argc, char *argv[],
const char *expect_msg)
{
char *arg = *argref;
int namelen = strlen(name);
if (strncmp(arg, name, namelen))
return 0;
arg += namelen;
if (*arg == '=') {
(*argref) = arg + 1;
} else {
(*argi)++;
if ((*argi) >= argc)
die("--%s expects %s", name, expect_msg);
(*argref) = argv[(*argi)];
}
return 1;
}
int
main(int argc, char *argv[])
{
@ -281,54 +305,17 @@ main(int argc, char *argv[])
arg += 2;
if (!strncmp(arg, "uri", 3)) {
arg += 3;
if (*arg == '=') {
arg++;
set_dom_string(&uri, arg, strlen(arg));
} else {
i++;
if (i >= argc)
die("--uri expects a URI");
set_dom_string(&uri, argv[i], strlen(argv[i]));
}
if (get_opt(&arg, "uri", &i, argc, argv, "a URI")) {
set_dom_string(&uri, arg, strlen(arg));
} else if (!strncmp(arg, "src", 3)) {
arg += 3;
if (*arg == '=') {
arg++;
set_dom_string(&source, arg, strlen(arg));
} else {
i++;
if (i >= argc)
die("--src expects a string");
set_dom_string(&source, argv[i], strlen(argv[i]));
}
} else if (get_opt(&arg, "src", &i, argc, argv, "a string")) {
set_dom_string(&source, arg, strlen(arg));
} else if (!strncmp(arg, "stdin", 5)) {
arg += 5;
if (*arg == '=') {
arg++;
read_stdin = atoi(arg);
set_dom_string(&source, arg, strlen(arg));
} else {
i++;
if (i >= argc)
die("--stdin expects a number");
read_stdin = atoi(argv[i]);
}
} else if (get_opt(&arg, "stdin", &i, argc, argv, "a number")) {
read_stdin = atoi(arg);
flags |= SGML_PARSER_INCREMENTAL;
} else if (!strncmp(arg, "normalize", 9)) {
arg += 9;
if (*arg == '=') {
arg++;
} else {
i++;
if (i >= argc)
die("--normalize expects a string");
arg = argv[i];
}
} else if (get_opt(&arg, "normalize", &i, argc, argv, "a string")) {
normalize = 1;
normalize_flags = parse_dom_config(arg, ',');
type = SGML_PARSER_TREE;

View File

@ -11,28 +11,18 @@ correctly in the DOM tree.
. "$TEST_LIB"
test_output_equals_file () {
desc="$1"; shift
src="$1"; shift
file="$1"; shift
URI="test:$(normalize "$desc")"
sgml-parser --uri "$URI" --src "$src" > output
echo "#document: $URI" > expected
sed 's/^/ /' < "$file" >> expected
test_expect_success "$desc" 'cmp output expected'
}
test_output_equals () {
desc="$1"; shift
src="$1"; shift
out="$1"; shift
echo "$out" | sed -n '2,$p' > expected+
URI="test:$(normalize "$desc")"
test_output_equals_file "$desc" "$src" "expected+"
sgml-parser --uri "$URI" --src "$src" > output
echo "#document: $URI" > expected
printf "%s\n" "$out" | sed -n '2,$p' | sed 's/^/ /' >> expected
test_expect_success "$desc" 'cmp output expected'
}
@ -194,21 +184,18 @@ entity-reference: #
#text: -
entity-reference: #xx'
cat > expected2 <<EOF
proc-instruction: xml -> encoding="UTF8"
attribute: encoding -> UTF8
#text: \\n...\\n
proc-instruction: ecmascript -> var val=2;\\n
EOF
test_output_equals_file \
test_output_equals \
'Parse processing instructions.' \
'<?xml encoding="UTF8"?>
...
<?ecmascript
var val=2;
?>' \
expected2
'
proc-instruction: xml -> encoding="UTF8"
attribute: encoding -> UTF8
#text: \n...\n
proc-instruction: ecmascript -> var val=2;\n'
test_output_equals \
'Parse XML processing instructions.' \

View File

@ -19,10 +19,10 @@ test_incremental_parsing () {
URI="test:$(normalize "$desc")"
echo "#document: $URI" > expected
echo "$out" | sed -n '2,$p' | sed -e 's/^/ /' >> expected
printf "%s\n" "$out" | sed -n '2,$p' | sed -e 's/^/ /' >> expected
for size in 1 2 3 4 5 6 7 8 9 10 15 20 25 50; do
echo -n "$src" | sgml-parser --uri "$URI" --stdin "$size" > output
printf "%s" "$src" | sgml-parser --uri "$URI" --stdin "$size" > output
test_run_ 'cmp output expected'
if [ "$?" != 0 -o "$eval_ret" != 0 ]

View File

@ -55,10 +55,10 @@ test_output_line_numbers \
7
8' \
8
test_output_line_numbers \
'Check line numbers. (IIII)' \
$'1\r\f 2\v\n 3\r\n 4\t\f 5' \
"$(printf "1\r\f 2\v\n 3\r\n 4\t\f 5")" \
5
test_done

View File

@ -16,17 +16,8 @@ mailcap-cache.o: mailcap.c
TESTDEPS = \
common.o \
$(top_builddir)/src/osdep/osdep.o \
$(top_builddir)/src/osdep/stub.o \
$(top_builddir)/src/util/conv.o \
$(top_builddir)/src/util/error.o \
$(top_builddir)/src/util/file.o \
$(top_builddir)/src/util/hash.o \
$(top_builddir)/src/util/memory.o \
$(top_builddir)/src/util/string.o \
$(top_builddir)/src/util/time.o
$(top_builddir)/src/osdep/osdep.o
TESTDEPS-$(CONFIG_NLS) += $(top_builddir)/src/intl/gettext/lib.o
TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o
include $(top_srcdir)/Makefile.lib

View File

@ -3,17 +3,11 @@ include $(top_builddir)/Makefile.config
OBJS = ftp.o parse.o
TEST_PROGS = ftp-parser
TEST_PROGS = \
ftp-parser
TESTDEPS = \
$(top_builddir)/src/osdep/stub.o \
$(top_builddir)/src/protocol/date.o \
$(top_builddir)/src/protocol/ftp/parse.o \
$(top_builddir)/src/util/conv.o \
$(top_builddir)/src/util/error.o \
$(top_builddir)/src/util/hash.o \
$(top_builddir)/src/util/memory.o \
$(top_builddir)/src/util/string.o \
$(top_builddir)/src/util/time.o
$(top_builddir)/src/protocol/ftp/parse.o
include $(top_srcdir)/Makefile.lib

View File

@ -3,10 +3,6 @@ include $(top_builddir)/Makefile.config
INCLUDES += $(GNUTLS_CFLAGS) $(OPENSSL_CFLAGS)
# Reverse a CONFIG_* string
# Usage $(call not,$(CONFIG_FOO))
not = $(if $(findstring yes,$(1)),no,yes)
OBJS-$(call not,$(CONFIG_SMALL)) += fastfind.o
OBJS-$(CONFIG_CSS) += scanner.o
OBJS-$(CONFIG_DEBUG) += memdebug.o