diff options
author | John Millaway <john43@users.sourceforge.net> | 2002-04-18 22:06:27 +0000 |
---|---|---|
committer | John Millaway <john43@users.sourceforge.net> | 2002-04-18 22:06:27 +0000 |
commit | 29363897c39cd8a36625a1e005a68256dfbd36d9 (patch) | |
tree | 8f85839a77c6e7775b99485763991bf5aa73fd70 /tests | |
parent | 5a6fb28c0087d0db13bcb12e33ed90feede62e41 (diff) |
Created yylineno tests.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-lineno-nr/.cvsignore | 8 | ||||
-rw-r--r-- | tests/test-lineno-nr/Makefile.am | 24 | ||||
-rw-r--r-- | tests/test-lineno-nr/scanner.l | 67 | ||||
-rw-r--r-- | tests/test-lineno-nr/test.input | 19 | ||||
-rw-r--r-- | tests/test-lineno-r/.cvsignore | 8 | ||||
-rw-r--r-- | tests/test-lineno-r/Makefile.am | 24 | ||||
-rw-r--r-- | tests/test-lineno-r/scanner.l | 70 | ||||
-rw-r--r-- | tests/test-lineno-r/test.input | 19 |
8 files changed, 239 insertions, 0 deletions
diff --git a/tests/test-lineno-nr/.cvsignore b/tests/test-lineno-nr/.cvsignore new file mode 100644 index 0000000..19d329e --- /dev/null +++ b/tests/test-lineno-nr/.cvsignore @@ -0,0 +1,8 @@ +Makefile +Makefile.in +parser.c +parser.h +scanner.c +test-lineno-nr +OUTPUT +.deps diff --git a/tests/test-lineno-nr/Makefile.am b/tests/test-lineno-nr/Makefile.am new file mode 100644 index 0000000..58b8c5f --- /dev/null +++ b/tests/test-lineno-nr/Makefile.am @@ -0,0 +1,24 @@ +BISON = @BISON@ +FLEX = $(top_builddir)/flex + +EXTRA_DIST = scanner.l test.input +CLEANFILES = scanner.c test-lineno-nr OUTPUT $(OBJS) +OBJS = scanner.o + +INCLUDES = -I $(srcdir) -I $(top_srcdir) + +testname = test-lineno-nr + +scanner.c: $(srcdir)/scanner.l + $(FLEX) $(LFLAGS) $< + + +$(testname)$(EXEEXT): $(OBJS) + $(CC) -o $@ $(OBJS) $(LDFLAGS) + +test: $(testname)$(EXEEXT) + test `./$(testname)$(EXEEXT) < $(srcdir)/test.input` -eq \ + `./$(testname)$(EXEEXT) 1 < $(srcdir)/test.input` || exit 1 + +.c.o: + $(CC) -c -o $@ $(INCLUDES) $< diff --git a/tests/test-lineno-nr/scanner.l b/tests/test-lineno-nr/scanner.l new file mode 100644 index 0000000..d0282cd --- /dev/null +++ b/tests/test-lineno-nr/scanner.l @@ -0,0 +1,67 @@ +%{ +/* A template scanner file to build "scanner.c". + Run as: + test-lineno-nr # report flex's yylineno + test-lineno-nr 1 # report count_newlines(stdin) +*/ + +#include <stdio.h> +#include <stdlib.h> +#include "config.h" + +%} + +%option 8bit outfile="scanner.c" prefix="test" +%option nounput nomain noyywrap yylineno +%option warn + +WORD [[:alpha:]]+ +DIGIT [[:digit:]] + +%% + /* The goal here is to test the yylineno processing by: + - providing some rules than CAN match newlines and + other rules that can NOT match newlines, + - matching several newlines in one rule, + - directly modifying yylineno. + */ + +"yylineno++" yylineno++; +"yylineno--" yylineno--; +[[:space:]]+ +{WORD} +{DIGIT}+(\n{DIGIT}+)* +\n +. +<<EOF>> { printf("%d\n", yylineno); + yyterminate(); + } + +%% + +/* returns number of '\n' characters in input, plus one. + This is what flex does, essentially. */ + +static int +count_newlines (FILE* in) +{ + int n=1,c; + while ((c=fgetc(in)) != EOF) + if( c == '\n') + n++; + return n; +} + +int +main ( int argc, char** argv ) +{ + if( argc > 1 ) + printf("%d\n", count_newlines(stdin)); + + else{ + yyin = stdin; + yyout = stdout; + yylex(); + } + return 0; +} diff --git a/tests/test-lineno-nr/test.input b/tests/test-lineno-nr/test.input new file mode 100644 index 0000000..c1eb961 --- /dev/null +++ b/tests/test-lineno-nr/test.input @@ -0,0 +1,19 @@ +These words +are separated +by newlines +and sometimes + spaces +too. +The next three lines are numbers with only intervening newlines +01123 +581321 +34 +And now for some blank lines.... + + +Finally, we directly modify yylineno, but then change it back afterwards +(see scanner.l): + +yylineno++ + +yylineno-- diff --git a/tests/test-lineno-r/.cvsignore b/tests/test-lineno-r/.cvsignore new file mode 100644 index 0000000..9c9f4d0 --- /dev/null +++ b/tests/test-lineno-r/.cvsignore @@ -0,0 +1,8 @@ +Makefile +Makefile.in +parser.c +parser.h +scanner.c +test-lineno-r +OUTPUT +.deps diff --git a/tests/test-lineno-r/Makefile.am b/tests/test-lineno-r/Makefile.am new file mode 100644 index 0000000..58b8c5f --- /dev/null +++ b/tests/test-lineno-r/Makefile.am @@ -0,0 +1,24 @@ +BISON = @BISON@ +FLEX = $(top_builddir)/flex + +EXTRA_DIST = scanner.l test.input +CLEANFILES = scanner.c test-lineno-nr OUTPUT $(OBJS) +OBJS = scanner.o + +INCLUDES = -I $(srcdir) -I $(top_srcdir) + +testname = test-lineno-nr + +scanner.c: $(srcdir)/scanner.l + $(FLEX) $(LFLAGS) $< + + +$(testname)$(EXEEXT): $(OBJS) + $(CC) -o $@ $(OBJS) $(LDFLAGS) + +test: $(testname)$(EXEEXT) + test `./$(testname)$(EXEEXT) < $(srcdir)/test.input` -eq \ + `./$(testname)$(EXEEXT) 1 < $(srcdir)/test.input` || exit 1 + +.c.o: + $(CC) -c -o $@ $(INCLUDES) $< diff --git a/tests/test-lineno-r/scanner.l b/tests/test-lineno-r/scanner.l new file mode 100644 index 0000000..70796be --- /dev/null +++ b/tests/test-lineno-r/scanner.l @@ -0,0 +1,70 @@ +%{ +/* A template scanner file to build "scanner.c". + Run as: + test-lineno-r # report flex's yylineno + test-lineno-r 1 # report count_newlines(stdin) +*/ + +#include <stdio.h> +#include <stdlib.h> +#include "config.h" + +%} + +%option 8bit outfile="scanner.c" prefix="test" +%option nounput nomain noyywrap yylineno reentrant +%option warn + +WORD [[:alpha:]]+ +DIGIT [[:digit:]] + +%% + /* The goal here is to test the yylineno processing by: + - providing some rules than CAN match newlines and + other rules that can NOT match newlines, + - matching several newlines in one rule, + - directly modifying yylineno. + */ + +"yylineno++" yylineno++; +"yylineno--" yylineno--; +[[:space:]]+ +{WORD} +{DIGIT}+(\n{DIGIT}+)* +\n +. +<<EOF>> { printf("%d\n", yylineno); + yyterminate(); + } + +%% + +/* returns number of '\n' characters in input, plus one. + This is what flex does, essentially. */ + +static int +count_newlines (FILE* in) +{ + int n=1,c; + while ((c=fgetc(in)) != EOF) + if( c == '\n') + n++; + return n; +} + +int +main ( int argc, char** argv ) +{ + if( argc > 1 ) + printf("%d\n", count_newlines(stdin)); + + else{ + yyscan_t s; + yylex_init(&s); + yyset_in(stdin,s); + yyset_out(stdout,s); + yylex(s); + yylex_destroy(s); + } + return 0; +} diff --git a/tests/test-lineno-r/test.input b/tests/test-lineno-r/test.input new file mode 100644 index 0000000..c1eb961 --- /dev/null +++ b/tests/test-lineno-r/test.input @@ -0,0 +1,19 @@ +These words +are separated +by newlines +and sometimes + spaces +too. +The next three lines are numbers with only intervening newlines +01123 +581321 +34 +And now for some blank lines.... + + +Finally, we directly modify yylineno, but then change it back afterwards +(see scanner.l): + +yylineno++ + +yylineno-- |