summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTill Varoquaux <till.varoquaux@gmail.com>2013-07-02 17:18:13 -0400
committerWill Estes <westes575@gmail.com>2013-07-02 20:26:45 -0400
commit0a3f0d7dadd2a5469ea1bdd535ef73504d749736 (patch)
treec55a676e51cc2fc7e9902b549f979c5972acda65 /tests
parent38a590701713d94e6214eb1c43394337ef18634f (diff)
Adjust yylineno properly when rewinding trailing contexts.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/test-lineno-trailing/.gitignore8
-rw-r--r--tests/test-lineno-trailing/Makefile.am45
-rw-r--r--tests/test-lineno-trailing/scanner.l87
-rw-r--r--tests/test-lineno-trailing/test.input13
5 files changed, 155 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 33c20bd..25d8b0c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -53,6 +53,7 @@ DIST_SUBDIRS = \
test-debug-r \
test-lineno-r \
test-lineno-nr \
+ test-lineno-trailing \
test-linedir-r \
TEMPLATE \
test-top \
@@ -102,6 +103,7 @@ SUBDIRS = \
test-debug-r \
test-lineno-r \
test-lineno-nr \
+ test-lineno-trailing \
test-linedir-r \
test-array-nr \
test-array-r \
diff --git a/tests/test-lineno-trailing/.gitignore b/tests/test-lineno-trailing/.gitignore
new file mode 100644
index 0000000..84b3fa9
--- /dev/null
+++ b/tests/test-lineno-trailing/.gitignore
@@ -0,0 +1,8 @@
+Makefile
+Makefile.in
+parser.c
+parser.h
+scanner.c
+test-lineno-trailing
+OUTPUT
+.deps
diff --git a/tests/test-lineno-trailing/Makefile.am b/tests/test-lineno-trailing/Makefile.am
new file mode 100644
index 0000000..bb303c3
--- /dev/null
+++ b/tests/test-lineno-trailing/Makefile.am
@@ -0,0 +1,45 @@
+# 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.input
+CLEANFILES = scanner.c $(testname)$(EXEEXT) OUTPUT $(OBJS)
+OBJS = scanner.o
+
+AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -I$(top_builddir)
+
+testname = test-lineno-trailing
+
+scanner.c: $(srcdir)/scanner.l
+ $(FLEX) $(LFLAGS) $<
+
+
+$(testname)$(EXEEXT): $(OBJS)
+ $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(OBJS) $(LOADLIBES)
+
+test: $(testname)$(EXEEXT)
+ test `./$(testname)$(EXEEXT) < $(srcdir)/test.input` -eq \
+ `./$(testname)$(EXEEXT) 1 < $(srcdir)/test.input` || exit 1
+
+.c.o:
+ $(CC) -c -o $@ $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $<
diff --git a/tests/test-lineno-trailing/scanner.l b/tests/test-lineno-trailing/scanner.l
new file mode 100644
index 0000000..20d3c8a
--- /dev/null
+++ b/tests/test-lineno-trailing/scanner.l
@@ -0,0 +1,87 @@
+/*
+ * 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 template scanner file to build "scanner.c".
+ Run as:
+ test-lineno-trailing # report flex's yylineno
+ test-lineno-trailing 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:]]+
+
+%%
+ /* The goal here is to test the yylineno in the context of trailing-contexts.
+ Using rules that have newlines in look-ahead.
+ */
+"Fixed_trailing:"/[\n]"test"[\n] {}
+"Var_trailing:"{WORD}/[\n] {}
+"Var_prefix_and_trailing:"{WORD}":"/(\n{WORD})* {}
+\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, char**);
+
+int
+main ( argc, argv )
+ 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-trailing/test.input b/tests/test-lineno-trailing/test.input
new file mode 100644
index 0000000..201164d
--- /dev/null
+++ b/tests/test-lineno-trailing/test.input
@@ -0,0 +1,13 @@
+We are testing rules with trailing contexts containing newlines (see scanner.l):
+
+Fixed_trailing:
+test
+
+Var_trailing:word
+test
+
+Var_prefix_and_trailing:word:
+more
+text
+comes
+here