diff options
author | John Millaway <john43@users.sourceforge.net> | 2003-03-27 18:02:58 +0000 |
---|---|---|
committer | John Millaway <john43@users.sourceforge.net> | 2003-03-27 18:02:58 +0000 |
commit | 17551916f3f63d31562c1c6c15ea8749b4a9279b (patch) | |
tree | e815f489a1aa347b4f19acfaafbde5f3bb75a61b /tests | |
parent | 6fe6068dee3020caf4bd93c2c7d71c675df3201d (diff) |
Added %top block syntax.
Added test for %top block.
Documented %top block.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/descriptions | 1 | ||||
-rw-r--r-- | tests/test-top/.cvsignore | 6 | ||||
-rw-r--r-- | tests/test-top/Makefile.am | 54 | ||||
-rw-r--r-- | tests/test-top/main.c | 63 | ||||
-rw-r--r-- | tests/test-top/scanner.l | 53 | ||||
-rw-r--r-- | tests/test-top/test.input | 3 |
7 files changed, 182 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index b5c96c3..f3b78ef 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -48,6 +48,7 @@ DIST_SUBDIRS = \ test-lineno-nr \ test-linedir-r \ TEMPLATE \ + test-top \ test-array-nr \ test-array-r \ test-c-cpp-nr \ @@ -102,6 +103,7 @@ SUBDIRS = \ test-yyextra \ test-noansi-nr \ test-noansi-r \ + test-top \ test-table-opts # clean up before running the test suite so we dont test old builds of test code diff --git a/tests/descriptions b/tests/descriptions index 4b45b74..6dc76c4 100644 --- a/tests/descriptions +++ b/tests/descriptions @@ -37,4 +37,5 @@ reject - Check REJECT code. string-nr - Scan strings, non-reentrant. string-r - Scan strings, reentrant. table-opts - Try every table compression option. +top - Test %top directive. yyextra - Test yyextra. diff --git a/tests/test-top/.cvsignore b/tests/test-top/.cvsignore new file mode 100644 index 0000000..b095dd2 --- /dev/null +++ b/tests/test-top/.cvsignore @@ -0,0 +1,6 @@ +Makefile +Makefile.in +scanner.c +scanner.h +test-top +OUTPUT diff --git a/tests/test-top/Makefile.am b/tests/test-top/Makefile.am new file mode 100644 index 0000000..51e6d6b --- /dev/null +++ b/tests/test-top/Makefile.am @@ -0,0 +1,54 @@ +# This file is part of flex. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: + +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. + +# Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE. + + +FLEX = $(top_builddir)/flex + +builddir = @builddir@ + +EXTRA_DIST = scanner.l test.input main.c +CLEANFILES = scanner.c scanner.h test-top OUTPUT $(OBJS) +OBJS = scanner.o main.o + +AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -I$(top_builddir) -I$(builddir) +#LDFLAGS = $(top_srcdir)/libfl.a +LFLAGS = --header="scanner.h" +#YFLAGS = --defines --output=parser.c + +testname = test-top + +scanner.c: $(srcdir)/scanner.l + $(FLEX) $(LFLAGS) $< + +parser.c: $(srcdir)/parser.y + $(BISON) $(YFLAGS) $< + +$(testname)$(EXEEXT): $(OBJS) + $(CC) -o $@ $(LDFLAGS) $(OBJS) $(LOADLIBES) + +test: $(testname)$(EXEEXT) + ./$(testname)$(EXEEXT) < $(srcdir)/test.input + +.c.o: + $(CC) -c -o $@ $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $< + +scanner.h: scanner.c +main.o: scanner.h diff --git a/tests/test-top/main.c b/tests/test-top/main.c new file mode 100644 index 0000000..353a63e --- /dev/null +++ b/tests/test-top/main.c @@ -0,0 +1,63 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +#include "scanner.h" + +/* The scanner itself is not important here. + * We simply try to use all the functions that are exported in the + * header, to see if we get any compiler warnings. + */ +int +main ( int argc, char** argv ) +{ + yyscan_t scanner; + FILE *fp; + char * extra = "EXTRA"; + + testlex_init(&scanner); + testset_in(stdin,scanner); + testset_out(stdout,scanner); + testset_extra(extra,scanner); + + fp = testget_in(scanner); + fp = testget_out(scanner); + + while(testlex(scanner)) { + char * text; + int line; + line = testget_lineno(scanner); + text = testget_text(scanner); + + if( (char*)testget_extra(scanner) != extra) + break; + + if ( !text || line < 0) + continue; + } + testlex_destroy(scanner); + printf("TEST RETURNING OK.\n"); + return 0; +} + + +/* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ diff --git a/tests/test-top/scanner.l b/tests/test-top/scanner.l new file mode 100644 index 0000000..be329b0 --- /dev/null +++ b/tests/test-top/scanner.l @@ -0,0 +1,53 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +%{ +/* Build "scanner.c". + The scanner is not important. + This test is really about compilation. See "main.c". +*/ +#include <stdio.h> +#include <stdlib.h> +#include "config.h" + +#ifndef DEFINE_ME +#error "DEFINE_ME undefined!" +#endif +%} + +%top{ +#define DEFINE_ME 1 +} + +%option reentrant +%option 8bit outfile="scanner.c" prefix="test" +%option nounput nomain noyywrap +%option warn + + +%% + +.|\n { } + +%% + diff --git a/tests/test-top/test.input b/tests/test-top/test.input new file mode 100644 index 0000000..2ce5001 --- /dev/null +++ b/tests/test-top/test.input @@ -0,0 +1,3 @@ +Any input is ok for this scanner. +We only care if it links. + |