aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShevek <[email protected]>2014-09-08 17:17:08 -0700
committerShevek <[email protected]>2014-09-08 17:17:08 -0700
commit09e951892e640874756690d3e9f7d07613b4f67b (patch)
tree8a522db3783b9e7d16264e973e4134d2b2694ce5
parenta7b9e5655b6521c6e8f3e37b83dcdfa63cb3e9b8 (diff)
Fix #15.
-rw-r--r--build.gradle5
-rw-r--r--src/main/java/org/anarres/cpp/LexerSource.java6
-rw-r--r--src/test/java/org/anarres/cpp/LexerSourceTest.java20
3 files changed, 26 insertions, 5 deletions
diff --git a/build.gradle b/build.gradle
index 9c377cb..ce1a8cd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -31,9 +31,12 @@ apply plugin: 'velocity'
dependencies {
compile 'com.google.code.findbugs:jsr305:2.0.2'
compile 'gnu.getopt:java-getopt:1.0.13'
+ // compile 'net.sf.jopt-simple:jopt-simple:4.7'
compile 'org.apache.ant:ant:1.7.0'
- testCompile 'junit:junit:4.8.1'
+ testCompile 'junit:junit:4.11'
+ // testCompile 'com.google.guava:guava:18.0'
+ testCompile 'commons-logging:commons-logging:1.2'
}
velocity {
diff --git a/src/main/java/org/anarres/cpp/LexerSource.java b/src/main/java/org/anarres/cpp/LexerSource.java
index 0b381b9..d9331fe 100644
--- a/src/main/java/org/anarres/cpp/LexerSource.java
+++ b/src/main/java/org/anarres/cpp/LexerSource.java
@@ -262,10 +262,16 @@ public class LexerSource extends Source {
do {
do {
d = read();
+ if (d == -1)
+ return new Token(INVALID, text.toString(),
+ "Unterminated comment");
text.append((char) d);
} while (d != '*');
do {
d = read();
+ if (d == -1)
+ return new Token(INVALID, text.toString(),
+ "Unterminated comment");
text.append((char) d);
} while (d == '*');
} while (d != '/');
diff --git a/src/test/java/org/anarres/cpp/LexerSourceTest.java b/src/test/java/org/anarres/cpp/LexerSourceTest.java
index 80abdd3..b83ddd6 100644
--- a/src/test/java/org/anarres/cpp/LexerSourceTest.java
+++ b/src/test/java/org/anarres/cpp/LexerSourceTest.java
@@ -1,35 +1,41 @@
package org.anarres.cpp;
import java.util.Arrays;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Ignore;
import org.junit.Test;
import static org.anarres.cpp.Token.*;
import static org.junit.Assert.*;
public class LexerSourceTest {
- private void testLexerSource(String in, boolean textmatch, int... out)
+ private static final Log LOG = LogFactory.getLog(LexerSourceTest.class);
+
+ public static void testLexerSource(String in, boolean textmatch, int... out)
throws Exception {
- System.out.println("Testing '" + in + "' => "
+ LOG.info("Testing '" + in + "' => "
+ Arrays.toString(out));
StringLexerSource s = new StringLexerSource(in);
StringBuilder buf = new StringBuilder();
for (int i = 0; i < out.length; i++) {
Token tok = s.token();
- System.out.println("Token is " + tok);
+ LOG.info("Token is " + tok);
assertEquals(out[i], tok.getType());
// assertEquals(col, tok.getColumn());
buf.append(tok.getText());
}
Token tok = s.token();
- System.out.println("Token is " + tok);
+ LOG.info("Token is " + tok);
assertEquals(EOF, tok.getType());
if (textmatch)
assertEquals(in, buf.toString());
}
+ @Ignore
@Test
public void testLexerSource()
throws Exception {
@@ -100,4 +106,10 @@ public class LexerSourceTest {
testLexerSource(".45e6", true, NUMBER);
testLexerSource("-6", true, '-', NUMBER);
}
+
+ @Test
+ public void testUnterminatedComment() throws Exception {
+ testLexerSource("5 /*", false, NUMBER, WHITESPACE, INVALID); // Bug #15
+ testLexerSource("5 //", false, NUMBER, WHITESPACE, CPPCOMMENT);
+ }
}