]> granicus.if.org Git - flex/commitdiff
Added test for yypush_buffer_state and yypop_buffer_state.
authorJohn Millaway <john43@users.sourceforge.net>
Wed, 26 Mar 2003 16:52:53 +0000 (16:52 +0000)
committerJohn Millaway <john43@users.sourceforge.net>
Wed, 26 Mar 2003 16:52:53 +0000 (16:52 +0000)
TODO
configure.in
tests/Makefile.am
tests/descriptions
tests/test-include-by-push/.cvsignore [new file with mode: 0644]
tests/test-include-by-push/Makefile.am [new file with mode: 0644]
tests/test-include-by-push/scanner.l [new file with mode: 0644]
tests/test-include-by-push/test-1.input [new file with mode: 0644]
tests/test-include-by-push/test-2.input [new file with mode: 0644]
tests/test-include-by-push/test-3.input [new file with mode: 0644]

diff --git a/TODO b/TODO
index c1102bc26c9de87d643f1e0cc38d68cbf137cc61..eb4ba31ebc7d35ed9aa4daeee7593117ea7d07dd 100644 (file)
--- a/TODO
+++ b/TODO
@@ -54,8 +54,6 @@
 
 ** make test suite more complete
 
-*** add a test for yypush_buffer_state/yypop_buffer_state
-
 * generic coding
 
 ** move as much skeleton code as possible out of gen.c and into
index 7742cf1db025d9c5fe8baa077638edce4cca0734..e18a0ea9e1b90a0d08599be99424a9c77c5a435d 100644 (file)
@@ -98,6 +98,7 @@ tests/test-c-cpp-r/Makefile
 tests/test-header-nr/Makefile
 tests/test-header-r/Makefile
 tests/test-include-by-buffer/Makefile
+tests/test-include-by-push/Makefile
 tests/test-include-by-reentrant/Makefile
 tests/test-multiple-scanners-nr/Makefile
 tests/test-multiple-scanners-r/Makefile
index f3d6b10bc8bd9b7624a17eecd70b43bca35563c7..b5c96c37fd6246bb68ed1a5db6728b1c9a778837 100644 (file)
@@ -53,6 +53,7 @@ DIST_SUBDIRS = \
        test-c-cpp-nr \
        test-c-cpp-r \
        test-include-by-buffer \
+       test-include-by-push \
        test-include-by-reentrant \
        test-prefix-nr \
        test-prefix-r \
@@ -91,6 +92,7 @@ SUBDIRS = \
        test-c-cpp-nr \
        test-c-cpp-r \
        test-include-by-buffer \
+       test-include-by-push \
        test-include-by-reentrant \
        test-prefix-nr \
        test-prefix-r \
index 2445520193b98af7c7704c49e66c8a133155c10d..4b45b74c7c439afd5dfc8a0cdb266249718aa522 100644 (file)
@@ -17,6 +17,7 @@ debug-r               - Use debugging functions, reentrant.
 header-nr             - Test generated header file, non-reentrant.
 header-r              - Test generated header file, reentrant.
 include-by-buffer     - YY_BUFFER_STATE, yy_push_state, etc.
+include-by-push       - yypush_buffer_state, yypop_buffer_state
 include-by-reentrant  - Nested scanners.
 linedir-r             - Check #line directives.
 lineno-nr             - Use %option yylineno, non-reentrant.
diff --git a/tests/test-include-by-push/.cvsignore b/tests/test-include-by-push/.cvsignore
new file mode 100644 (file)
index 0000000..7a7c74b
--- /dev/null
@@ -0,0 +1,7 @@
+Makefile
+Makefile.in
+parser.c
+parser.h
+scanner.c
+test-include-by-push
+OUTPUT
diff --git a/tests/test-include-by-push/Makefile.am b/tests/test-include-by-push/Makefile.am
new file mode 100644 (file)
index 0000000..46f700d
--- /dev/null
@@ -0,0 +1,49 @@
+# 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
+
+EXTRA_DIST = scanner.l test-1.input test-2.input test-3.input
+CLEANFILES = scanner.c scanner.h parser.c parser.h test-include-by-push OUTPUT $(OBJS)
+OBJS = scanner.o # parser.o
+
+AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -I$(top_builddir)
+#LDFLAGS = $(top_srcdir)/libfl.a 
+#LFLAGS = --header="scanner.h"
+#YFLAGS = --defines --output=parser.c
+
+testname = test-include-by-push
+
+scanner.c: $(srcdir)/scanner.l
+       $(FLEX) $<
+
+parser.c: $(srcdir)/parser.y
+       $(BISON) $(YFLAGS) $<
+
+$(testname)$(EXEEXT): $(OBJS)
+       $(CC) -o $@ $(LDFLAGS) $(OBJS) $(LOADLIBES)
+
+test: $(testname)$(EXEEXT)
+       ./$(testname)$(EXEEXT) $(srcdir)/test-1.input
+
+.c.o:
+       $(CC) -c -o $@ $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $<
diff --git a/tests/test-include-by-push/scanner.l b/tests/test-include-by-push/scanner.l
new file mode 100644 (file)
index 0000000..8556152
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+
+%{
+/* A scanner file to build "scanner.c".
+   Input language is any text.
+   "#include <filename>" causes a buffer switch.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include "config.h"
+%}
+
+%option 8bit outfile="scanner.c" prefix="test"
+%option nounput nomain noyywrap
+%option warn
+
+%x GET_FILENAME
+
+%%
+
+<INITIAL>{
+^"#include"[[:blank:]]+"<"  { BEGIN(GET_FILENAME); }
+.|\n      { ECHO; }
+}
+
+<GET_FILENAME>{
+[[:alnum:]_.-]+>  {
+     /* recurse */
+    yytext[yyleng-1]='\0';
+    if((yyin=fopen(yytext,"r"))==NULL) {
+        fprintf(stderr,"*** Error: Could not open include file \"%s\".\n",yytext);
+        yyterminate();
+    }
+    yypush_buffer_state( yy_create_buffer( yyin, YY_BUF_SIZE ));
+    BEGIN(0);
+    }
+.|\n  {
+    fprintf(stderr,"Invalid input \"%s\".\n", yytext);
+    yyterminate();
+   }
+}
+
+<<EOF>> {
+           fclose(yyin);
+           yypop_buffer_state();
+           if(!YY_CURRENT_BUFFER)
+               yyterminate();
+        }
+
+%%
+
+int main(int argc, char** argv);
+
+int
+main ( int argc, char** argv )
+{
+    FILE * fp;
+    if( argc != 2 ) {
+        fprintf(stderr,"*** Error: Must specifiy one filename.\n");
+        exit(-1);
+    }
+    if((fp=fopen(argv[1],"r"))==NULL) {
+        fprintf(stderr,"*** Error: fopen(%s) failed.\n",argv[1]);
+        exit(-1);
+    }
+    yyin = fp;
+    yyout = stdout;
+    yylex();
+    printf("TEST RETURNING OK.\n");
+    return 0;
+}
diff --git a/tests/test-include-by-push/test-1.input b/tests/test-include-by-push/test-1.input
new file mode 100644 (file)
index 0000000..355beaa
--- /dev/null
@@ -0,0 +1,3 @@
+Beginning of "test-1.input".
+#include <test-2.input>
+End of "test-1.input".
diff --git a/tests/test-include-by-push/test-2.input b/tests/test-include-by-push/test-2.input
new file mode 100644 (file)
index 0000000..45f11f9
--- /dev/null
@@ -0,0 +1,3 @@
+Beginning of "test-2.input".
+#include <test-3.input>
+End of "test-2.input".
diff --git a/tests/test-include-by-push/test-3.input b/tests/test-include-by-push/test-3.input
new file mode 100644 (file)
index 0000000..6a2d055
--- /dev/null
@@ -0,0 +1,2 @@
+Beginning of "test-3.input".
+End of "test-3.input".