aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-06 11:58:47 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-06 13:00:06 +0300
commit52c12573a505bf29a0301a1c9553e88c3270713e (patch)
tree642047e5b3de469199b68a76064f756990a3b249 /tests
parent8465fa7066d3c922b738346335f801cf9ea2243f (diff)
downloadgrecs-52c12573a505bf29a0301a1c9553e88c3270713e.tar.gz
grecs-52c12573a505bf29a0301a1c9553e88c3270713e.tar.bz2
Rewrite list support to keep doubly-linked lists. Implement tree reduction.
* src/format.c (grecs_format_node) (grecs_format_node_path): Handle grecs_node_root. * src/grecs-gram.y (input production): Create root node. * src/grecs.h (grecs_list_entry)<prev>: New member. (grecs_node_root): New node type. (grecs_node_eq): New proto. (grecs_list_add,grecs_tree_reduce): New protos. * src/list.c: Rewrite as a doubly-linked list. * src/tree.c (grecs_node_bind): Bugfix. (grecs_node_unlink): New function. (_tree_recurse): Allow for removal of the current node. (grecs_node_eq): New function. (grecs_tree_reduce): New function. (grecs_tree_process): Descend into the first subnode at once. * src/lookup.c (node_finder): Handle grecs_node_root. * tests/reduce00.at: New testcase. * tests/reduce01.at: New testcase. * tests/reduce02.at: New testcase. * tests/testsuite.at (GRECS_TEST): New macro. Include reduce0[0-2].at. * tests/gcffmt.c: New option -reduce. * tests/gcfpeek.c: Likewise. * tests/gcfset.c: Likewise.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/gcffmt.c11
-rw-r--r--tests/gcfpeek.c9
-rw-r--r--tests/gcfset.c7
-rw-r--r--tests/reduce00.at28
-rw-r--r--tests/reduce01.at41
-rw-r--r--tests/reduce02.at52
-rw-r--r--tests/testsuite.at9
8 files changed, 155 insertions, 5 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 05a5548..b4b0dce 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -49,6 +49,9 @@ TESTSUITE_AT = \
peek01.at\
peek02.at\
peek03.at\
+ reduce00.at\
+ reduce01.at\
+ reduce02.at\
set.at\
testsuite.at\
@GRECS_VERCMP_AT@
diff --git a/tests/gcffmt.c b/tests/gcffmt.c
index aa73717..cacf7d2 100644
--- a/tests/gcffmt.c
+++ b/tests/gcffmt.c
@@ -24,7 +24,8 @@
static void
usage(const char *arg, FILE *fp, int code)
{
- fprintf(fp, "usage: %s [-h] [-locus] [-delim=char] file\n", arg);
+ fprintf(fp, "usage: %s [-h] [-locus] [-delim=char] [-reduce] file\n",
+ arg);
exit(code);
}
@@ -35,13 +36,16 @@ main(int argc, char **argv)
char *file = NULL;
struct grecs_node *tree, *node;
int flags = GRECS_NODE_FLAG_DEFAULT;
-
+ int reduce = 0;
+
while (--argc) {
char *arg = *++argv;
if (strcmp(arg, "-locus") == 0)
flags |= GRECS_NODE_FLAG_LOCUS;
else if (strncmp(arg, "-delim=", 7) == 0)
flags |= arg[7];
+ else if (strcmp(arg, "-reduce") == 0)
+ reduce = 1;
else if (strcmp(arg, "-h") == 0)
usage(progname, stdout, 0);
else if (arg[0] == '-')
@@ -58,7 +62,8 @@ main(int argc, char **argv)
tree = grecs_parse(file);
if (!tree)
exit(1);
-
+ if (reduce)
+ grecs_tree_reduce(tree, NULL);
for (node = tree; node; node = node->next) {
grecs_format_node(node, flags, stdout);
fputc('\n', stdout);
diff --git a/tests/gcfpeek.c b/tests/gcfpeek.c
index 84e56d6..905f4ca 100644
--- a/tests/gcfpeek.c
+++ b/tests/gcfpeek.c
@@ -24,7 +24,9 @@
static void
usage(const char *arg, FILE *fp, int code)
{
- fprintf(fp, "usage: %s [-h] [-locus] [-delim=char] file path\n", arg);
+ fprintf(fp,
+ "usage: %s [-h] [-locus] [-delim=char] [-reduce] file path\n",
+ arg);
exit(code);
}
@@ -37,6 +39,7 @@ main(int argc, char **argv)
struct grecs_node *tree, *node;
int flags = GRECS_NODE_FLAG_DEFAULT;
int rc = 2;
+ int reduce = 0;
while (--argc) {
char *arg = *++argv;
@@ -44,6 +47,8 @@ main(int argc, char **argv)
flags |= GRECS_NODE_FLAG_LOCUS;
else if (strncmp(arg, "-delim=", 7) == 0)
flags |= arg[7];
+ else if (strcmp(arg, "-reduce") == 0)
+ reduce = 1;
else if (strcmp(arg, "-h") == 0)
usage(progname, stdout, 0);
else if (arg[0] == '-')
@@ -63,6 +68,8 @@ main(int argc, char **argv)
tree = grecs_parse(file);
if (!tree)
exit(1);
+ if (reduce)
+ grecs_tree_reduce(tree, NULL);
for (node = tree; node; node = node->next) {
node = grecs_find_node(node, path);
diff --git a/tests/gcfset.c b/tests/gcfset.c
index d2264e3..8d5b464 100644
--- a/tests/gcfset.c
+++ b/tests/gcfset.c
@@ -171,7 +171,7 @@ print_program(struct program *prog)
static void
usage(const char *arg, FILE *fp, int code)
{
- fprintf(fp, "usage: %s [-h] [-cfhelp] file\n", arg);
+ fprintf(fp, "usage: %s [-h] [-cfhelp] [-reduce] file\n", arg);
exit(code);
}
@@ -182,6 +182,7 @@ main(int argc, char **argv)
const char *file = NULL;
struct grecs_node *tree;
int cfhelp = 0;
+ int reduce = 0;
while (--argc) {
char *arg = *++argv;
@@ -189,6 +190,8 @@ main(int argc, char **argv)
cfhelp = 1;
else if (strcmp(arg, "-h") == 0)
usage(progname, stdout, 0);
+ else if (strcmp(arg, "-reduce") == 0)
+ reduce = 1;
else if (arg[0] == '-')
usage(progname, stderr, 1);
else if (file)
@@ -211,6 +214,8 @@ main(int argc, char **argv)
tree = grecs_parse(file);
if (!tree)
exit(2);
+ if (reduce)
+ grecs_tree_reduce(tree, main_kwtab);
if (grecs_tree_process(tree, main_kwtab))
exit(2);
diff --git a/tests/reduce00.at b/tests/reduce00.at
new file mode 100644
index 0000000..a5441a6
--- /dev/null
+++ b/tests/reduce00.at
@@ -0,0 +1,28 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Grecs is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Reduction: simple statement])
+AT_KEYWORDS([reduce reduce00])
+
+GRECS_TEST([scalar a;
+scalar b;
+],
+[gcffmt -reduce],
+[0],
+[.scalar: "b"
+])
+
+AT_CLEANUP
diff --git a/tests/reduce01.at b/tests/reduce01.at
new file mode 100644
index 0000000..c0185e2
--- /dev/null
+++ b/tests/reduce01.at
@@ -0,0 +1,41 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Grecs is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Reduction: block statement])
+AT_KEYWORDS([reduce reduce01])
+
+GRECS_TEST([
+block "a" {
+ scalar a;
+ foo 1;
+}
+block "b" {
+ foo 3;
+ scalar b;
+}
+block "a" {
+ scalar b;
+}
+],
+[gcffmt -reduce],
+[0],
+[.block="b".foo: "3"
+.block="b".scalar: "b"
+.block="a".foo: "1"
+.block="a".scalar: "b"
+])
+
+AT_CLEANUP
diff --git a/tests/reduce02.at b/tests/reduce02.at
new file mode 100644
index 0000000..11d7c0b
--- /dev/null
+++ b/tests/reduce02.at
@@ -0,0 +1,52 @@
+# This file is part of grecs -*- Autotest -*-
+# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff
+#
+# Grecs is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Grecs is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Grecs. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Reduction: nested block statement])
+AT_KEYWORDS([reduce reduce02])
+
+GRECS_TEST([
+block "a" {
+ scalar a;
+ foo 1;
+ subblock {
+ foo x;
+ bar y;
+ }
+}
+block "b" {
+ foo 3;
+ scalar b;
+}
+block "a" {
+ scalar b;
+ subblock {
+ baz z;
+ foo k;
+ }
+}
+],
+[gcffmt -reduce],
+[0],
+[.block="b".foo: "3"
+.block="b".scalar: "b"
+.block="a".foo: "1"
+.block="a".scalar: "b"
+.block="a".subblock.bar: "y"
+.block="a".subblock.baz: "z"
+.block="a".subblock.foo: "k"
+])
+
+AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index e60b82d..184108c 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -37,6 +37,11 @@ m4_define([EX_CONFIG], 78) dnl configuration error
m4_define([AT_SKIP_TEST],[exit 77])
+dnl GRECS_TEST([config],[cmd],[status],[stdout],[stderr])
+m4_define([GRECS_TEST],[
+AT_DATA([test.cf],[$1])
+AT_CHECK([$2 ./test.cf],m4_shift(m4_shift($@)))])
+
dnl # Begin tests
AT_INIT
@@ -52,6 +57,10 @@ m4_include([peek03.at])
m4_include([cfhelp.at])
m4_include([set.at])
+m4_include([reduce00.at])
+m4_include([reduce01.at])
+m4_include([reduce02.at])
+
m4_if(GRECS_VERCMP_AT,,,[m4_include(GRECS_VERCMP_AT)])
# End of testsuite.at

Return to:

Send suggestions and report system problems to the System administrator.