Skip to content

Commit

Permalink
add %eof{ test to bazel test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
lsf37 committed Mar 15, 2020
1 parent 904a933 commit 1e4a7da
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
43 changes: 43 additions & 0 deletions javatests/jflex/testcase/eof/BUILD.bazel
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",
],
)
40 changes: 40 additions & 0 deletions javatests/jflex/testcase/eof/EofGoldenTest.java
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());
}
}
}
2 changes: 2 additions & 0 deletions javatests/jflex/testcase/eof/eof-0.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bla
blub
2 changes: 2 additions & 0 deletions javatests/jflex/testcase/eof/eof-0.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EOF
<<EOF>>
29 changes: 29 additions & 0 deletions javatests/jflex/testcase/eof/eof.flex
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 ""; }

0 comments on commit 1e4a7da

Please sign in to comment.