aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/anarres/cpp/ErrorTest.java
diff options
context:
space:
mode:
authorShevek <[email protected]>2013-12-27 05:49:13 -0800
committerShevek <[email protected]>2013-12-27 05:49:13 -0800
commitbdc6c852f418c3e042aa41469d84544e5f60a526 (patch)
tree7866346f0fa48ad46a6a427d016dd4b83451dbbe /src/test/java/org/anarres/cpp/ErrorTest.java
parent39264fd6d2a6646e49f83b5b2b3512c1663a1c9b (diff)
Version bump to 1.4.0-SNAPSHOT.
Rewrite build system to use gradle. Clean up source for the new generation.
Diffstat (limited to 'src/test/java/org/anarres/cpp/ErrorTest.java')
-rw-r--r--src/test/java/org/anarres/cpp/ErrorTest.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/test/java/org/anarres/cpp/ErrorTest.java b/src/test/java/org/anarres/cpp/ErrorTest.java
new file mode 100644
index 0000000..8777452
--- /dev/null
+++ b/src/test/java/org/anarres/cpp/ErrorTest.java
@@ -0,0 +1,65 @@
+package org.anarres.cpp;
+
+import java.io.IOException;
+import org.junit.Test;
+import static org.anarres.cpp.Token.*;
+import static org.junit.Assert.*;
+
+public class ErrorTest {
+
+ private boolean testError(Preprocessor p)
+ throws LexerException,
+ IOException {
+ for (;;) {
+ Token tok = p.token();
+ if (tok.getType() == EOF)
+ break;
+ if (tok.getType() == INVALID)
+ return true;
+ }
+ return false;
+ }
+
+ private void testError(String input) throws Exception {
+ StringLexerSource sl;
+ PreprocessorListener pl;
+ Preprocessor p;
+
+ /* Without a PreprocessorListener, throws an exception. */
+ sl = new StringLexerSource(input, true);
+ p = new Preprocessor();
+ p.addFeature(Feature.CSYNTAX);
+ p.addInput(sl);
+ try {
+ assertTrue(testError(p));
+ fail("Lexing unexpectedly succeeded without listener.");
+ } catch (LexerException e) {
+ /* required */
+ }
+
+ /* With a PreprocessorListener, records the error. */
+ sl = new StringLexerSource(input, true);
+ p = new Preprocessor();
+ p.addFeature(Feature.CSYNTAX);
+ p.addInput(sl);
+ pl = new PreprocessorListener();
+ p.setListener(pl);
+ assertNotNull("CPP has listener", p.getListener());
+ assertTrue(testError(p));
+ assertTrue("Listener has errors", pl.getErrors() > 0);
+
+ /* Without CSYNTAX, works happily. */
+ sl = new StringLexerSource(input, true);
+ p = new Preprocessor();
+ p.addInput(sl);
+ assertTrue(testError(p));
+ }
+
+ @Test
+ public void testErrors() throws Exception {
+ testError("\"");
+ testError("'");
+ // testError("''");
+ }
+
+}