diff options
author | Shevek <[email protected]> | 2014-09-08 17:17:08 -0700 |
---|---|---|
committer | Shevek <[email protected]> | 2014-09-08 17:17:08 -0700 |
commit | 09e951892e640874756690d3e9f7d07613b4f67b (patch) | |
tree | 8a522db3783b9e7d16264e973e4134d2b2694ce5 /src | |
parent | a7b9e5655b6521c6e8f3e37b83dcdfa63cb3e9b8 (diff) |
Fix #15.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/anarres/cpp/LexerSource.java | 6 | ||||
-rw-r--r-- | src/test/java/org/anarres/cpp/LexerSourceTest.java | 20 |
2 files changed, 22 insertions, 4 deletions
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); + } } |