-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# This build file was generated automatically, but won't be re-generated. | ||
# Feel free to improve. | ||
|
||
load("@jflex_rules//jflex:jflex.bzl", "jflex") | ||
|
||
# eof | ||
|
||
jflex( | ||
name = "gen_eof_scanner", | ||
srcs = ["eof.flex"], | ||
jflex_bin = "//jflex:jflex_bin", | ||
outputs = ["Eof.java"], | ||
) | ||
|
||
java_library( | ||
name = "eof_scanner", | ||
srcs = [ | ||
":gen_eof_scanner", | ||
], | ||
deps = [ | ||
"//java/jflex/testing/testsuite/golden", | ||
"//third_party/com/google/guava", | ||
], | ||
) | ||
|
||
java_test( | ||
name = "EofGoldenTest", | ||
srcs = [ | ||
"EofGoldenTest.java", | ||
], | ||
data = [ | ||
"eof-0.input", | ||
"eof-0.output", | ||
], | ||
deps = [ | ||
":eof_scanner", | ||
"//java/jflex/testing/diff", | ||
"//java/jflex/testing/testsuite/golden", | ||
"//java/jflex/util/scanner:scanner_factory", | ||
"//third_party/com/google/guava", | ||
"//third_party/com/google/truth", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// test: eof | ||
|
||
package jflex.testcase.eof; | ||
|
||
import java.io.File; | ||
import jflex.testing.testsuite.golden.AbstractGoldenTest; | ||
import jflex.testing.testsuite.golden.GoldenInOutFilePair; | ||
import jflex.util.scanner.ScannerFactory; | ||
import org.junit.Test; | ||
|
||
/** | ||
* test %eof and %eofthrows directives https://github.com/jflex-de/jflex/issues/743 | ||
* | ||
* <p>Note: This test was generated from {@code jflex-testsuite-maven-plugin} test cases. The test | ||
* relies on golden files for testing, expecting the scanner to output logs on the {@code | ||
* System.out}. Please migrate to proper unit tests, as describe in <a | ||
* href="https://github.com/jflex-de/jflex/tree/master/javatests/jflex/testcase"> | ||
* //javatest/jflex/testcase</a>. | ||
*/ | ||
// TODO Migrate this test to proper unit tests. | ||
public class EofGoldenTest extends AbstractGoldenTest { | ||
|
||
/** Creates a scanner conforming to the {@code eof.flex} specification. */ | ||
private final ScannerFactory<Eof> scannerFactory = ScannerFactory.of(Eof::new); | ||
|
||
private File testRuntimeDir = new File("javatests/jflex/testcase/eof"); | ||
|
||
@Test | ||
public void goldenTest0() throws Exception { | ||
GoldenInOutFilePair golden = | ||
new GoldenInOutFilePair( | ||
new File(testRuntimeDir, "eof-0.input"), new File(testRuntimeDir, "eof-0.output")); | ||
compareSystemOutWith(golden); | ||
|
||
Eof scanner = scannerFactory.createScannerForFile(golden.inputFile); | ||
while (!scanner.yyatEOF()) { | ||
System.out.println(scanner.yylex()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bla | ||
blub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
EOF | ||
<<EOF>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package jflex.testcase.eof; | ||
|
||
import java.io.*; | ||
|
||
%% | ||
|
||
%public | ||
%class Eof | ||
%type String | ||
|
||
%eof{ | ||
System.out.println("EOF"); | ||
|
||
// should never throw, but the compiler won't know | ||
if (System.out == null) { | ||
throw new java.io.IOException("testing"); | ||
} | ||
%eof} | ||
|
||
%eofthrow{ | ||
java.io.IOException | ||
%eofthrow} | ||
|
||
%% | ||
|
||
.+ { /* ignore */ } | ||
\n { /* that too */ } | ||
|
||
<<EOF>> { System.out.println("<<EOF>>"); return ""; } |